资源描述:
《Introduction to Machine Learning机器学习分享导论.pdf》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、IntroductiontoMachineLearningUsefultools:Python,NumPy,scikit-learnAntonioSuteraandJean-MichelBegonSeptember29,20162/37HowtoinstallPython?DownloadandusetheAnacondapythondistributionhttps://store.continuum.io/cshop/anaconda/.Itcomeswithallthescientificpy
2、thonstack.Alternatives:linuxpackages,pythonxy,canopy,...3/37UsingthepythoninterpreterInteractivemode1.Startapythonshell$ipython2.Writepythoncode>>>print("HelloWorld!")HelloWorld!Scriptmode1.hello.pyprint("HelloWorld!")2.Launchthescript$ipythonhello.py
3、Helloworld!4/37BasictypesInteger>>>55>>>a=5>>>a5Float>>>pi=3.14complex>>>c=1-1jboolean>>>b=5>3#5<=3>>>bTrue#Falsestring>>>s=’hello!’#Alsoworkswith"hello!">>>s’hello!’5/37PythonisadynamicprogramlanguageVariabletypesareimplicitlyinferredduringtheassignm
4、ent.Variablesarenotdeclared.>>>#Inpython>>>a=1Bycontrastinstaticallytypedlanguage,youmustdeclaredthetype.//Injava,c,c++inta=16/37Numbersandtheirarithmeticoperations(+,-,/,//,*,**,%)>>>1+23>>>50-5*620>>>2/3#withpy30.66...0>>>2./3#floatdivisioninpy2andp
5、y30.6666666666666666>>>4//3#Integerdivisionwithpy2andpy31>>>5**3.5#exponent279.5084971874737>>>4%2#modulooperation07/37Playingwithstrings>>>s=’Greatday!’>>>s’Greatday!’>>>s[0]#stringsaresequences’G’>>>"""Averyverylongstring"""’Averyverylongstring’
6、>>>’i={0}f={2}s={1}’.format(1,’test’,3.14)’i=1f=3.14s=test’8/37list,anorderedcollectionofobjectsInstantiation>>>l=[]#anemptylist>>>l=[’spam’,’egg’,[’anotherlist’],42]Indexing>>>l[1]’egg’>>>l[-1]#n_elements-142>>>l[1:2]#aslice["egg",[’anotherlist’]]Met
7、hods>>>len(l)4>>>l.pop(0)’spam’>>>l.append(3)>>>l[’egg’,[’anotherlist’],42,3]9/37dict,anunorderedandassociativedatastructureofkey-valuepairsInstantiation>>>d={1:"a","b":2,0:[4,5,6]}>>>d{0:[4,5,6],1:’a’,’b’:2}Indexing>>>d[’b’]2>>>’b’indTrueInsertion>>>
8、d[’new’]=56>>>d{0:[4,5,6],1:’a’,’b’:2,’new’:56}Deletion>>>deld[’new’]>>>d{0:[4,5,6],1:’a’,’b’:2}10/37dict,anunorderedandassociativedatastructureofkey-valuepairsMethods>>>len(d)3>>>d.keys()[0,1,’b’]>>>d.values()[[4,5,6],’a’,2]11/37Controlflow:if