ebook img

Artificial Intelligence with Python. Machine Learning: Foundations, Methodologies, and Applications PDF

334 Pages·2022·4.85 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Artificial Intelligence with Python. Machine Learning: Foundations, Methodologies, and Applications

Machine Learning: Foundations, Methodologies, and Applications Teik Toe Teoh Zheng Rong Artificial Intelligence with Python Machine Learning: Foundations, Methodologies, and Applications SeriesEditors Kay Chen Tan, Department of Computing, Hong Kong Polytechnic University, HongKong,China DachengTao,UniversityofTechnology,Sydney,Australia Bookspublishedinthisseriesfocusonthetheoryandcomputationalfoundations, advanced methodologies and practical applications of machine learning, ideally combiningmathematicallyrigoroustreatmentsofacontemporarytopicsinmachine learningwithspecificillustrationsinrelevantalgorithmdesignsanddemonstrations in real-worldapplications.Theintendedreadershipincludesresearchstudentsand researchersincomputerscience,computerengineering,electricalengineering,data science,andrelatedareasseekingaconvenientmediumtotracktheprogressesmade inthefoundations,methodologies,andapplicationsofmachinelearning. Topicsconsideredincludeallareasofmachinelearning,includingbutnotlimited to: • Decisiontree • Artificialneuralnetworks • Kernellearning • Bayesianlearning • Ensemblemethods • Dimensionreductionandmetriclearning • Reinforcementlearning • Metalearningandlearningtolearn • Imitationlearning • Computationallearningtheory • Probabilisticgraphicalmodels • Transferlearning • Multi-viewandmulti-tasklearning • Graphneuralnetworks • Generativeadversarialnetworks • Federatedlearning This series includes monographs, introductory and advanced textbooks, and state-of-the-artcollections. Furthermore,it supportsOpen Access publication mode. Moreinformationaboutthisseriesathttps://link.springer.com/bookseries/16715 Teik Toe Teoh • Zheng Rong Artificial Intelligence with Python TeikToeTeoh ZhengRong NanyangBusinessSchool NanyangTechnologicalUniversity NanyangTechnologicalUniversity Singapore,Singapore Singapore,Singapore ISSN2730-9908 ISSN2730-9916 (electronic) MachineLearning:Foundations,Methodologies,andApplications ISBN978-981-16-8614-6 ISBN978-981-16-8615-3 (eBook) https://doi.org/10.1007/978-981-16-8615-3 ©TheEditor(s)(ifapplicable)andTheAuthor(s),underexclusivelicensetoSpringerNatureSingapore PteLtd.2022 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartof thematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformation storageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodology nowknownorhereafterdeveloped. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant protectivelawsandregulationsandthereforefreeforgeneraluse. Thepublisher,theauthorsandtheeditorsaresafetoassumethattheadviceandinformationinthisbook arebelievedtobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsor theeditorsgiveawarranty,expressorimplied,withrespecttothematerialcontainedhereinorforany errorsoromissionsthatmayhavebeenmade.Thepublisherremainsneutralwithregardtojurisdictional claimsinpublishedmapsandinstitutionalaffiliations. ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSingaporePteLtd. The registered company address is: 152 Beach Road, #21-01/04 Gateway East, Singapore 189721, Singapore Preface This book is a practical guide to Python programming and artificial intelligence, written by Dr. Teoh Teik Toe. It contains many articles, notes, and lessons learnt onPythonprogramming,artificialintelligence,anddeeplearningduringDr.Teoh’s careerasadeeplearningpractitionerandatrustedadvisor. Dr. Teoh has been pursuing research in big data, deep learning, cybersecurity, artificial intelligence, machine learning, and software development for more than 25years.Hisworkshavebeenpublishedinmorethan50journals,conferencepro- ceedings,books,and bookchapters.His qualificationsincludea PhD in computer engineeringfromtheNTU,DoctorofBusinessAdministrationfromtheUniversity of Newcastle, Master of Law from the NUS, LLB and LLM from the UoL, and CFA, ACCA and CIMA. He has more than 15 years’ experience in data mining, quantitativeanalysis,datastatistics,finance,accounting,andlawandispassionate about the synergy between business and technology. He believes that artificial intelligence should be made easy for all to understand and is eager to share his knowledgeofthefield. ZhengRongisasoftwareengineerwith4yearsofexperience.Heembracesthe ambiguityofdataandenjoysthechallengespresentedbybusinessproblems.Hehas 3yearsofteachingexperienceindatamininganddatascience,andcoauthoredthree journalpublicationsonartificialintelligenceanddeeplearning.Heisinterestedin makingartificial intelligence programmingand technologyeasy to understandfor all,includingthosefromanon-technicalbackground. The field of artificial intelligence is very broad. It focuses on creating systems capableofexecutingtaskswhichwouldrequiresomeformofhumanintelligence. In-depth knowledge and understanding of the field is required to be able to developgoodartificialintelligenceprograms.Theconceptsusedinself-drivingcars and virtual assistants like Amazon’s Alexa may seem very complex and difficult to grasp. Entering the field of artificial intelligence and data science can seem daunting to beginnerswith little to no prior background,especially those with no programmingexperience. Throughouthiscareer,Dr.Teohhasdeliveredmanylecturestostudentsfromall walksoflifeaboutartificialintelligence.Thereweremanystudentswhohadlimited v vi Preface experienceinprogrammingandbeganwithnoknowledgeofartificialintelligence. However,underhisguidance,theyeventuallygainedconfidenceinwritingtheirown artificial intelligence programs. Through the materials compiled in this book, he hopestoempowermorebeginnerswhoareeagertostudyartificialintelligenceand enrichtheirlearningprocess.Hence,theaimofArtificialIntelligenceinPythonisto makeAIaccessibleandeasytounderstandforpeoplewithlittletonoprogramming experiencethroughpracticalexercises. By goingthroughthe materialscoveredin this book, newcomers will gain the knowledge they need on how to create such systems,whicharecapableofexecutingtasksthatrequiresomeformofhuman-like intelligence. This book will begin by introducingreaders to varioustopics and examplesof programming in Python, as well as key concepts in artificial intelligence. Python will be introduced, and programming skills will be imparted as we go along. Concepts and code snippets will be covered in a step-by-step manner to guide andinstillconfidenceinbeginners.Complexsubjectsindeeplearningandmachine learning will be brokendown into easy-to-digestcontent and examples. Basics of artificialintelligence,suchasclassificationandregression,willbeimpartedtobuild asolidfoundationforbeginnersbeforemovingtomoreadvancedchapters.Artificial intelligence implementations will also be shared, allowing beginners to generate theirownartificialintelligencealgorithmsforreinforcementlearning,styletransfer, chatbots,andspeechandnaturallanguageprocessing. Singapore,Singapore TeikToeTeoh ZhengRong Acknowledgments We would like to acknowledge and thank all our families and friends who have supported us throughoutthis journey, as well as all those who have helped make thisbookpossible. Ourtutorialsandcodearecompiledfromvarioussources.Withouttheworkof the authors in the references, our book would not have been possible. Credits for Pythoninstallationgoestoquanteconandpdflatex.Thefollowingcodesare compiledsothatitcanbeaquickguideandreference. vii Contents PartI Python 1 PythonforArtificialIntelligence.......................................... 3 1.1 CommonUses....................................................... 3 1.1.1 RelativePopularity........................................ 4 1.1.2 Features.................................................... 5 1.1.3 SyntaxandDesign ........................................ 5 1.2 ScientificProgramming............................................. 6 1.3 WhyPythonforArtificialIntelligence............................. 6 2 GettingStarted.............................................................. 9 2.1 SettingupYourPythonEnvironment.............................. 9 2.2 Anaconda............................................................ 9 2.2.1 InstallingAnaconda....................................... 10 2.2.2 FurtherInstallationSteps ................................. 10 2.2.3 UpdatingAnaconda....................................... 13 2.3 InstallingPackages.................................................. 14 2.4 VirtualEnvironment................................................ 14 2.5 JupyterNotebooks.................................................. 15 2.5.1 StartingtheJupyterNotebook............................ 15 2.5.2 NotebookBasics .......................................... 17 2.5.3 WorkingwiththeNotebook .............................. 21 2.5.4 SharingNotebooks........................................ 22 3 AnIntroductoryExample ................................................. 27 3.1 Overview............................................................ 27 3.2 TheTask:PlottingaWhiteNoiseProcess......................... 27 3.3 OurFirstProgram................................................... 28 3.3.1 Imports..................................................... 28 3.3.2 ImportingNamesDirectly................................ 30 3.3.3 RandomDraws............................................ 30 ix x Contents 3.4 AlternativeImplementations ....................................... 31 3.4.1 AVersionwithaforLoop................................ 31 3.4.2 Lists........................................................ 31 3.4.3 TheforLoop............................................... 32 3.4.4 ACommentonIndentation............................... 33 3.4.5 WhileLoops............................................... 34 3.5 AnotherApplication................................................ 34 3.6 Exercises ............................................................ 35 3.6.1 Exercise1.................................................. 35 3.6.2 Exercise2.................................................. 35 3.6.3 Exercise3.................................................. 36 3.6.4 Exercise4.................................................. 36 3.6.5 Exercise5.................................................. 36 3.7 Solutions ............................................................ 37 3.7.1 Exercise1.................................................. 37 3.7.2 Exercise2.................................................. 37 3.7.3 Exercise3.................................................. 38 3.7.4 Exercise4.................................................. 38 3.7.5 Exercise5.................................................. 39 4 BasicPython ................................................................ 41 4.1 Hello,World!........................................................ 42 4.2 Indentation .......................................................... 42 4.3 VariablesandTypes................................................. 43 4.3.1 Numbers................................................... 44 4.3.2 Strings ..................................................... 44 4.3.3 Lists........................................................ 46 4.3.4 Dictionaries................................................ 48 4.4 BasicOperators..................................................... 50 4.4.1 ArithmeticOperators...................................... 50 4.4.2 ListOperators ............................................. 51 4.4.3 StringOperators........................................... 52 4.5 LogicalConditions.................................................. 54 4.6 Loops................................................................ 56 4.7 ListComprehensions ............................................... 57 4.8 ExceptionHandling................................................. 58 4.8.1 Sets......................................................... 60 5 IntermediatePython ....................................................... 63 5.1 Functions............................................................ 64 5.2 ClassesandObjects................................................. 66 5.3 ModulesandPackages.............................................. 69 5.3.1 WritingModules .......................................... 70 5.4 Built-inModules.................................................... 72 5.5 WritingPackages ................................................... 75

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.