资源描述:
《statistics and linear algebra》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、StatisticsandLinearAlgebraStatisticsandlinearalgebraarebranchesofmathematicsthatareespeciallyusefulfordataanalysis.That'swhywewillfocusontheminthischapter.Statisticsisneededtomakeinferencesfromrawdata.Forinstance,wecancomputethatthedataforavariablehasacertainarithmeticmeanandstan
2、darddeviation.Fromthesenumbers,wecantheninferarangeandtheexpectedvalueforthisvariable.Then,wecanrunstatisticalteststocheckhowlikelyitisthatwemadetherightconclusion.Linearalgebraconcernsitselfwithsystemsoflinearequations.TheseareeasytosolvewithNumPyandSciPyusingthelinalgpackage.Li
3、nearalgebraisuseful,forinstance,tofitdatatoamodel.WeshallintroduceotherNumPyandSciPypackagesinthischapterforrandomnumbergenerationandmaskedarrays.Inthischapter,wewillcoverthefollowingtopics:•Descriptivestatistics•Thelinalgpackage•Polynomials•Matricesasspecializedndarraysubclasses
4、•Randomnumbers•Continuousanddiscretedistributions•MaskedarraysNumPyandSciPymodulesFirst,let'stakealookattheNumPyandSciPymoduledocumentation.Whatwillbedescribedhereisnotatopicspecifictodataanalysis,butmoreofageneralPythonitem.StatisticsandLinearAlgebraThefollowingcodeprintsthedesc
5、riptionsofsubpackagesforNumPyandSciPy:importpkgutilaspuimportnumpyasnpimportmatplotlibasmplimportscipyasspimportpydocprint"NumPyversion",np.__version__print"SciPyversion",sp.__version__print"Matplotlibversion",mpl.__version__defclean(astr):s=astr#removemultiplespacess=''.join(s.s
6、plit())s=s.replace('=','')returnsdefprint_desc(prefix,pkg_path):forpkginpu.iter_modules(path=pkg_path):name=prefix+"."+pkg[1]ifpkg[2]==True:try:docstr=pydoc.plain(pydoc.render_doc(name))docstr=clean(docstr)start=docstr.find("DESCRIPTION")docstr=docstr[start:start+140]printname,do
7、cstrexcept:continueprint_desc("numpy",np.__path__)printprintprintprint_desc("scipy",sp.__path__)UsingthestandardPythonmodulespkgutilandpydoc,wecaniteratethroughsubpackagesinNumPyandSciPyandextractshortdescriptionsofthesesubpackages.WewillalsoprinttheSciPy,matplotlib,andNumPyversi
8、ons.[60]Chapter3Theversionsforthevarious