《Python数据挖掘环境搭建.docx》由会员分享,可在线阅读,更多相关《Python数据挖掘环境搭建.docx(27页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、4 X,实验报告学号20191106078姓名龚永好上机地点信-506专业电子信息工程班级电信1902班时间2022年5月5日上机内容实验一:Python数据挖掘环境搭建一、实验目的及要求目的:学会安装Python软件,学会安装第三方扩展库,建立开发环境,学会使用Python数据分析 工具。要求:1 .完成Python及numpy、pandas scipy matplotlib等第三方库的安装,画出安装流程图并备 注考前须知。2 .完成数据集中趋势统计,计算均值、中位数和众数。3 .完成数据离散趋势统计,计算极差、四分位数、四分位距、五数概括、方差和标准差、DataFrame描述性统计,画出画
2、箱线图。4 .完成数据基本统计图,画出条形图、饼状图、折线图、直方图、散点图、分位数-分位数图。二、实验设备(环境)及要求1 .硬件要求:CPU在2.0 GHz以上,内存在4G以上,建议8G。2 .软件要求:Widows7系统及以上系统,Anaconda编译环境。三、实验内容(-)Python安装及第三方库的安装与检查数据挖掘理论与实践指导教师:向前 SNr (Python 36 .D & E is A 国目-TG MU 餐津 B X Z 1-10 9Ti-isG”日1#coding: utf-831-1656 QI7print(Ql)|np.percentile(feature_l,0.25
3、)Vari able splrr | File vfl0rwr MlpIKythe catleB CosI l/*O Ia H: runfle( *C: /Users/AdiUnlstrAtor/Oesktap/shujiMjue-shlyanl/1-14(C:/lHer$ AdBiniitratcr/DesktcoZ2.3四分位数极差(四分位距)Re dit Search Source gun Qebug Consoles grpjecH loots yiew Help口g sktotshQjwtjMvskiyuil 个Eixtdr - C WsrsVA4Miii str*trB4sktoV
4、shnjustjua-shiytQl U*17. pyX Klp& XCl I 1-10.”; I l-U y I 172” I 1-13.0 | J-14.py1 -1$ yy 1;6 - l-T py O | L Swec-1; Obj“, G Ct1# - *- coding: utf-8 - 4- 2 31-17 4 5 6IQR = Q3 - QI 7print(IQR) 8|UsageHere you can get help of f object by Ctrl*! n frort of . eeber cn the (deo or theQxw*rlelpcan dso be
5、 shewn autcnidtica*V after rrittnr or c Q/e允,ences Ne toSpder,*ad oistrtor/Oesktop/shujut- shjyani/1 14.py* wtlr*C :/UMrs/Adainistrtor/Oefktop/ shujvwAjue-shiyenl)j.eeeoeeeeoeeeeeesIn 32: runf ile( C:,: c .,-!. t.p/tnuju ajue-ihXyonl . . t. p . wdlr* C:AdedX atL/Dedushu juwa jue- Piy*l *)Xn 33: runf
6、lle( C: J-e , Ao*ldstr tor/Cc.- top/sjju.jjue- thiyanl/1 1- .py wdlr C: Zl ie* . *uin. il,t it_ Oct,xtop, $hujuojuc $HyMl ,)4.33725in ij: runriie( i: shujuwajue*shiynl),皿l”.pb , wdir-a. -dn . 115trtor/Desktop/Xn SS:2.4五数概括3e dit Search Source gun Qebug Cfifnolei grojecH look Jfiew Help口注由海 A昌日师6 MC餐
7、同X/一 C: VsrsJL4BimstrUorBskto*duijwtjMvxkiyud 个Editor - C strsVAdioistrftiorDsktodmjuBtju*xhiyatU-18. py二;1-u” 卜 12.”1-13 ” I 1-14 rr 1-15.py ,1-16.” 1-H py E P,1# - - coding: utf-8 - -2 ” ” “31-18456 max_value = np.max(feature_l)7 Q3 = np.percentile(feature_l,75)8median-value np.median(feature_l)9
8、QI = np.percentile(feature_l,e.25)10 min_value = np.min(feature_l)11 min_value, QI, median_value, Q3, max_value12 print(min-value, QI, median_value, Q3, max_value)S x 1falpS x,卜 ,Ssurct Cvl* * 0bjc,G QVrible explorer File explorer MUpIFytUft CMisol*& XH EZ lO |14 QXn 32: runfileCC:/User$/A4Binistrto
9、*/Dcsktop/shuJimjue-shiyani/1 -15.pya, wdlr*C: /IMrs/AMnistrator/oeslctop/.$hujuMjue*shlyRl*) 4.4Xn 33: runfileOesktop/shujuwa. .py, wdir- -ator/Desktop/shujuwajue-shlyanl() 4.55725In M: runfile(C: Users/Adwinistotor/Desktop/shujuwajue-shiyanl 1-17.py,t wdir C:/tiers Administrato*/Desktop/ shujuwaju
10、e- sMyl) e.0627seeeeeee0ee)In 35: runfile( c : /Users/AdBinistrator/Desktop/shujuNijut-shiyanl/l-lS.py*, wrfirC: /Vsrs/Ars Ad 6.4, 7.9)Xn (37:2.5箱线图单一箱线图 Spyd*r (Pythoc 3.6, 上pe ditSource gun Qebug Cgmoles projects Jook yiew fjdp口餐店 酷 G HI c: CH C= H B X Z今,餐小E4tlr C UriA4iiiilrlorDi)rtpUraj口 1 1-12
11、 ty | 1-13 ni 上M ”J-15 y j 1-16 n J-17 w 1-10 py _ 179 ” ft Sowe. Cxal. 0b”“1# - - coding: utf-8 - -23 1-19456 import matplotlib.pyplot as pit7 pit.boxplot(xsfeature_l)8plt.ylabel(values of + iris_data.feature_names0)UyMe tt you can fet hep of ny object bv prea&nc CtrM c frort of t. either on the td
12、(tor or the ConsolHelpcar, aso be shown azoma-h after wfn a pe*enthesisnewt to an object. *ou can acnvMe thabehwU 7plxXFyUben9 :Cj i/*Q ,In 41 J: rwflle(c: users/Adainistrtor/Desktop/shuMie-shiyxu/1-19.py*3 血2-Min”/Desktop/ thvjwwajve sMyE *)aoItomPi tmgm (cm)In (42):多个箱线图f3e dit $,arch Source gun Q
13、ebug Cfimoles grojecH lookydp0 fe a i= Aglgl 布 C HI C: CH CH B wx/一 )C: UsrsA4*ixustrttorSrsktc&hu)xDf tjM&hAyoxilEixtor - C VxrsA4KU strtlorDsktoshmju*ju*xhiyaat py(9 X )klpQ | 1-12. xr 1-13.”1-14. py 1-15 py 1-14 py 1-17. py J-18 py 1-19 py 1-20 py L_ * Q, Src C*nU , jtHr 1 9 - -t/f-82 , 31-20 4 5
14、 6 import matplotlib.pyplot as pit 7 pit.boxplot(xfeature_l)-8 plt.ylabel( values of iris_data.feature_nanes0)-9 pit.xlabel(iris_data.feature_names9) 10 plt.show() 11 from pandas import DataFrane12 iris df = DataFrane(iris_data.data, columns=iris_data.feature names) 13fig, axes plt.subplots(l,4)14 i
15、ri$_df.plot(kind-box, ax-axes, subplots-True, title-All feature boxplots) 15 axes0.set_ylabel(iris_df.columns0)16 axes1.set_ylabel(iris_df.columnslj) 17 axes2.set_ylabel(iris_df.columns2) 18axes3.set_ylabel(iris_df.columns3) 19 fig.subplots_adjust(wspace=l, hspace=l) 20fig.show() 21Here you can get
16、he Ip of an object by press” Ctrkl ri front of ft. e ther on tht W0f ortht 8n3Help an Mo beWter wrMr *SNewtoSpvder9 Aead our”1“ 八】 心r”)klpIfythoa CMd4ltC:Prcgra)atAfond3Hbsit-packaftMtplotHbfigurc.py:459: UsenUrtting: Mtplotlib is currently using a non-GUI *kend, so cannot show the figuretplotlib is
17、 cyrretly using a non-QUX Mcktnd, *All feature boxpiots2.6方差和标准差50lepal length (an)In 47:05B*A A_00 4 , itepal mdth (an) petal length (cm) peUi wWi (cm Spyder (Python 3 6,pe Edit Search Source gun Qebug Cgmoles rject$ look yiew fjdp区I: A国目蜂C用仁仁生 E x Z 今C VtrsXii!us?Ml C餐之E X Z pe d* $e*fch Source gu
18、n Qebug Cfiwoles Projects Jools Jfiew Help fe a -j= Editor - C 2r:kAu cm grheipof n otjecx bypressog CirM n on: o? c. e Thef on the Cdor or the Conwle*8 can be ownautomxKVer Mting 6 psMhex newt r。 an object Bu can actare 6s bcnv HetpIFytK& co&soleCl| IAQ6.7 6.7 6.3 6.5 6.2 5.9New to Spider & ad our
19、uaoLitfIn 5?i runak( C :/l - Ade:rt(y/m:btopihUM,jue hjyonl/J 21 7y,wdir-C Ur:ci,toDe&ktcp/shujuMdjue-shiyanl*)C Ustrs14ixastrtorMsktci*shQjwjM-*duyud(9 X Help口 一l-M.”:1-6” 卜 16.”1-1。178 py E.py 维 P,_ 二21 ” l-t2 n 巳七 Q S*| 1# -2 ”31-224 coding: utf-856 import numpy as np7from sklearn.datasets import
20、 load_iri$8 iris_data = load_iris()9 feature=iris_data.data:,0ie1112 var = np.var(feature_l)13 var1415#斫有密堂专16var_all = np.var(iris_data.data, axis=0)17 var_all18 一19 print(var_all)|3e Edit Search Source gun Qebug Cflmolei projects Jools Jfiew *lp注个WPTEgLEh an”到,X?ytho占 Cmiio1 1/aQC.7 6.7 6.3 C.5 6i
21、wpXn 52: runfilr( C :/W sM“cl,)0.68112222 e.l67$067 3.0924239 57S531sq各 鬓A团目咻6附C仁剧X,-4- 4C VsrsAdiiuslrfttorIsktcthajw4jM-dayuU“注个Editor - C MI“nA4aUtr2QrMksktopZj3urhiyifti10.p7(9 X MUp口口 | 卜好“IB E E ”18 codtrig: utf-8179 ” impy L21.” I 1-22” sausk31-234 6 import numpy as np7from sklearn.datasets i
22、mport load iris8 iris_data = load_iris()“feature-iris_data.data: ,01012 van = np.var(feature_l)13 var1415,516 var_all = np.var(iris_data.data, axis=0)17 var all18-19#标准差20 std = np.std(feature_l)21std2223 print(stc()Hen? you can get he ip of any otject by pres&og Ctrl* I g front of t. e th= on Ed *9
23、VtriUle explr1 txlorer KlpCj CsM a3T.7 6.7 6.3 6.5 67T37打 6Bn”?22222”2,NeweSpvder,Aead ournprSIn (52 : runfile( r/Ad*iM-r/X-hujuw加sMyWL21 .py,Desktop/shujuwajue-hianl,).681X222222222223Xn (S) : runfi|f( t , / . - pr- Ade/0 MrM i y n I ,ytDesktop/shujuMjueshiyanl*)(0.68112222 9.15675067 3.W242489。57t
24、s31“Xn (MJ: rwnfil(C: A Fri/Admini%trator/Oeiktap/hujuwjue thiysnl/:八 py .Desktop/i*ujimdju-lhyanl,).825mm7B514e9In (55:wdir*C:/Users/Admlni$trtor/wdiraC :/U%ert/Adiinittrtor/“注个5 X M.lp1-21.py 1-22 ft 1-231/4 py 匚 |l/l-21.py wdir * C: /Osers/Admin is t r4torDesktop/we - thiyanl *)Xn 53: runfile.八二,
25、l Ad:nistrarc*-/Desetc? y . :m7r : qM :wdir* -5:Dektop/bujuMjur.Bhiysnl *)0.68112222 0.18675667 3.09242489 0.57853156)Xn S4: runfile( C : ; Lrrj/Adfrxn i st rator/Oxktoz sb.;ino-ue th:, ?I 1-; py, wdira* e-s, Desktop/ihujutojucashlyanl)6.82530129178514e9In (55:. .vdi- Osers/Adiri Desktop/sbujiMjuc-s
26、hiyanl).82550129 e.432M6 1.7M529ie 0.76061262)2.7 DataFrame描述性统计pe d* Search Source gun Qebug Consoles Projects Jools Jfiew tfelp。金电)三现Q 4目目咻 川0tGA. 同X-/,C1. WsrsA4*iikistr 1 -17 71-18. py ,b19.”1-20 py 1-21 py IN py 1-23 py l-2 py1# - coding: utf-8 -*-2 3 1-254 , 56 print(iris_df,describe()erplortr
27、 File exIrer lUlp IFythMk cgsal。(9 X口EM l/A(3 4 1%e.82sm29i7ni4e9Xa (55: runf 1(Adninittreto*-/Dvtkctop/thuJUMa juv-ihiyenl/l -24.py # wdira *C:/Urt/AdilnitDesktop/siiujtMjue-shlyaftl ).412146M I.7MS2918 7H262In (5: runfllt(/UMrB/Ad*lAlBtrtor/()sktop/ihujuNju* hlynl/X-25.py, (/Adiinistrtor/DeskTop/s
28、ujcmjue-shiyanl*)length (cs)petal width (co)countISvise.oeeoeecans.Mn.1.19S667std6.82M66.0.763161*in4.weeeee.ieeoee5168.e.jeeeoeS.teeeMi.5eeeee75%6.40=i.seeeeeMX7.99M02.seeoee8 roan x 4 coluflnsXn g;(四)数据基本统计图3.1条形图Spyder (PythonJjft3e dit Search Source gun Qebug Cfimolet grojecH JoolsHelp=g :e A 回回
29、 C 川 C 三 G EX/-46 C.UhtrxUixtrZamkpMB.jj-dM注个Editor - C VxtrsAdicdxtrUorIsktozKjuitju-xhiyealU*26. py(9 X )Ulpj | l-a n Id” _ Spy IN” Spy 1-24” F ”i*2S py O 卜 d Swrce Cnitlt Object1# -*- coding: utf-8 -31-264 56 import numpy as np7from sklearn.datasets import load_iris 8iris_data = load_iris()9 samp
30、le=iris.data.dataB: 1811 pl = pit.bar(range(1, len(sample_l)+l), 12 height = sample,13 tick_label = iris_data.feature_names, 14 width=0.3),15 plt.ylabel(em) 16plt.title(bar of first data)17 plt.show()1813.2饼状图 Spyder (Python 3.6) a a ?Hl c:金停E X Z labels, autopct*l.if%,12 shadow=True, startangle=90)
31、i axl.axis( equal) .14plt.show()|3.3折线图IFythMb口 1/aQIU“(9 X XUp卜外” 卜 15 1/A(JIn St: runfileDektop/shujiMjix-shlyAnl*)Xn 59:Ulpsepal length (an) itpal wtth (cm) petal length :cm| petdiSpy” (Python 3.6) .ile dt Search Source am Rebug Cgnvolw grojecH Tools few HelpDAO、国 Q 0 (? HI c: c= c= E X Z * C* Vx
32、frtA4jnirtwSektpVlmjrjxir*shiyml“勺个litr C:VswsMf iitr*tor5ktopSiHjwwjue-xhiyAJM-28 py.T _T .7/* m* Y-TrTY *f- j r 一: 一_9 X Help一 .一rn. 4 . . j _ I4,.9 x| wi.grQ iNp,C3 | la” t-.prC3 | Em口 i*py口 田,& g“ 心】. objc S。1# -coding: utf-8 - *-2 w M 13 1-284 3 ” “56 import numpy as np7 import matplotlib.pyplo
33、t as pit8x = np.arange(0, 5, 0.1)9 y = np.sin(x)pit.plot(x, y)10 pit.show()Vtriable txpidrerPil txlortr HelpIPytWn C3l.- x :Desktop/shu jvwa jut - shiyi)3.4直方图pe d* Search Source gun Qebug Cfimcles rojectx Jools yiew HelpIn ;60:占个Editor - C JJMnA4oUtr2orUxktopZj3urhiv3l*29 ”(9 X Kelp口 S | 1幺 y s J 9
34、 _ 必旦L ”py_ 二 pt17-coditrg: utf-8 -2 W M M 31-2945 , 6 import numpy as np7from sklearn.datasets import load_iris8 import matplotlib.pyplot as pit9 iris_data load_iris()10 feature_2 - iris_data.data:411 pit.hist(feature ?, bins=10)12 plt.show()|1-2S ”: |& Snrs Cnsl gj“tHere you can get he Ip of any object by pres&ng Clrll i front of t. eehe*, on 6 Ed *gNewtoSpyder ftead our w 3Tu-ieble explorer File exjl4rtrK41PXfyUMa cM“.& X0 L 1/A 口 4 ClDesktop 八 hujiW 皿I。*ZO 2510354045Xn 61:3.5散点图File Edit Search Source R