python3人工智能_PYTHON 3破冰人工智能从入门到实战

数学基础:从历年数学建模竞赛入手,解读人工智能中的数学方法。

编程实践:100余个代码实例,全面讲解网络爬虫、数据存储与数据分析等内容。

算法应用:实战案例辅以丰富图解,详尽分析人工智能算法特性及其应用场景。

本书创新性地从数学建模竞赛入手,深入浅出地讲解了人工智能领域的相关知识。本书内容基于Python 3.6,从人工智能领域的数学出发,到Python在人工智能场景下的关键模块;从网络爬虫到数据存储,再到数据分析;从机器学习到深度学习,涉及自然语言处理、机器学习、深度学习、推荐系统和知识图谱等。

此外,本书还提供了近140个代码案例和大量图表,全面系统地阐述了算法特性,个别案例算法来自于工作经验总结,力求帮助读者学以致用。

黄海涛(笔名零壹),算法工程师,网易云课堂“零壹课堂”主创人,CSDN博客专家,2018年度博客之星。曾先后参与开发多款人工智能产品,具有丰富项目经验;精通数学建模,曾多次获得竞赛奖项。

第 1章 从数学建模到人工智能1

1.1 数学建模 1

1.1.1 数学建模与人工智能 1

1.1.2 数学建模中的常见问题 4

1.2 人工智能下的数学 12

1.2.1 统计量 12

1.2.2 矩阵概念及运算 13

1.2.3 概率论与数理统计 16

1.2.4 高等数学——导数、微分、不定积分、定积分 19

第 2章 Python快速入门 24

2.1 安装Python 24

2.1.1 Python安装步骤 24

2.1.2 IDE的选择 27

2.2 Python基本操作 28

2.2.1 第 一个小程序 28

2.2.2 注释与格式化输出 28

2.2.3 列表、元组、字典 34

2.2.4 条件语句与循环语句 37

2.2.5 break、continue、pass 40

2.3 Python不错操作 41

2.3.1 lambda 41

2.3.2 map 42

2.3.3 filter 43

第3章 Python科学计算库NumPy 45

3.1 NumPy简介与安装 45

3.1.1 NumPy简介 45

3.1.2 NumPy安装 45

3.2 基本操作 46

3.2.1 初识NumPy 46

3.2.2 NumPy数组类型 47

3.2.3 NumPy创建数组 49

3.2.4 索引与切片 56

3.2.5 矩阵合并与分割 60

3.2.6 矩阵运算与线性代数 62

3.2.7 NumPy的广播机制 69

3.2.8 NumPy统计函数 71

3.2.9 NumPy排序、搜索 75

3.2.10 NumPy数据的保存 79

第4章 常用科学计算模块快速入门 80

4.1 Pandas科学计算库 80

4.1.1 初识Pandas 80

4.1.2 Pandas基本操作 82

4.2 Matplotlib可视化图库 94

4.2.1 初识Matplotlib 94

4.2.2 Matplotlib基本操作 96

4.2.3 Matplotlib绘图案例 98

4.3 SciPy科学计算库 100

4.3.1 初识SciPy 100

4.3.2 SciPy基本操作 101

4.3.3 SciPy图像处理案例 103

第5章 Python网络爬虫 106

5.1 爬虫基础 106

5.1.1 初识爬虫 106

5.1.2 网络爬虫的算法 107

5.2 爬虫入门实战 107

5.2.1 调用API 107

5.2.2 爬虫实战 112

5.3 爬虫进阶—高效率爬虫 113

5.3.1 多进程 113

5.3.2 多线程 114

5.3.3 协程 115

5.3.4 小结 116

第6章 Python数据存储 117

6.1 关系型数据库MySQL 117

6.1.1 初识MySQL 117

6.1.2 Python操作MySQL 118

6.2 NoSQL之MongoDB 120

6.2.1 初识NoSQL 120

6.2.2 Python操作MongoDB 121

6.3 本章小结 123

6.3.1 数据库基本理论 123

6.3.2 数据库结合 124

6.3.3 结束语 125

第7章 Python数据分析 126

7.1 数据获取 126

7.1.1 从键盘获取数据 126

7.1.2 文件的读取与写入 127

7.1.3 Pandas读写操作 129

7.2 数据分析案例 130

7.2.1 普查数据统计分析案例 130

7.2.2 小结 139

第8章 自然语言处理 140

8.1 Jieba分词基础 140

8.1.1 Jieba中文分词 140

8.1.2 Jieba分词的3种模式 141

8.1.3 标注词性与添加定义词 142

8.2 关键词提取 144

8.2.1 TF-IDF关键词提取 145

8.2.2 TextRank关键词提取 147

8.3 word2vec介绍 150

8.3.1 word2vec基础原理简介 150

8.3.2 word2vec训练模型 153

8.3.3 基于gensim的word2vec实战 154

第9章 从回归分析到算法基础 160

9.1 回归分析简介 160

9.1.1 “回归”一词的来源 160

9.1.2 回归与相关 161

9.1.3 回归模型的划分与应用 161

9.2 线性回归分析实战 162

9.2.1 线性回归的建立与求解 162

9.2.2 Python求解回归模型案例 164

9.2.3 检验、预测与控制 166

第 10章 从K-Means聚类看算法调参 171

10.1 K-Means基本概述 171

10.1.1 K-Means简介 171

10.1.2 目标函数 171

10.1.3 算法流程 172

10.1.4 算法优缺点分析 174

10.2 K-Means实战 174

第 11章 从决策树看算法升级 180

11.1 决策树基本简介 180

11.2 经典算法介绍 181

11.2.1 信息熵 181

11.2.2 信息增益 182

11.2.3 信息增益率184

11.2.4 基尼系数 185

11.2.5 小结 185

11.3 决策树实战 186

11.3.1 决策树回归 186

11.3.2 决策树的分类 188

第 12章 从朴素贝叶斯看算法多变 193

12.1 朴素贝叶斯简介 193

12.1.1 认识朴素贝叶斯 193

12.1.2 朴素贝叶斯分类的工作过程 194

12.1.3 朴素贝叶斯算法的优缺点 195

12.2 3种朴素贝叶斯实战 195

第 13章 从推荐系统看算法场景 200

13.1 推荐系统简介 200

13.1.1 推荐系统的发展 200

13.1.2 协同过滤 201

13.2 基于文本的推荐 208

13.2.1 标签与知识图谱推荐案例 209

13.2.2 小结 217

第 14章 从TensorFlow开启深度学习之旅 218

14.1 初识TensorFlow 218

14.1.1 什么是TensorFlow 218

14.1.2 安装TensorFlow 219

14.1.3 TensorFlow基本概念与原理 219

14.2 TensorFlow数据结构 221

14.2.1 阶 221

14.2.2 形状 221

14.2.3 数据类型 221

14.3 生成数据十二法 222

14.3.1 生成Tensor 222

14.3.2 生成序列 224

14.3.3 生成随机数 225

14.4 TensorFlow实战 225

参考文献 230

这是一本不错的Python教程,我一直想推荐给学生一本浅显易懂并且有关数学建模的图书,本书十分适合。它以Python为基础,从数学建模到人工智能,同时介绍了常用算法,可以说从建模比赛到工作实践全面渗透。建议所有对Python、数学建模、人工智能感兴趣的朋友都好好读一下。

——延边大学教授(学科带头人) 侯成敏

数学是人工智能的灵魂所在,也是很多学习者的薄弱环节。本书从数学建模的角度出发,深入浅出地讲解了人工智能的相关技术,并利用当前的Python 3进行应用实战,从网络爬虫到数据分析,从自然语言处理到回归分析,从推荐系统到深度学习,实例与图解丰富,通俗易懂。通过阅读本书,读者可以在数学基础、编程语言和算法应用三个方面获得极大提升。

——《趣学算法》作者 陈小玉

本书应该是你踏入人工智能领域推荐阅读的入门书。这本书中既有来自领域广泛的实战案例,也有来自建模竞赛的经典数学方法。读者在开始了解人工智能时应知道该做些什么、怎么做,本书可给予读者可靠的实践经验与观点支撑。在学习更深奥的人工智能课程之前,这是一本值得一读的书!

——“机器人库”网站主编 刘 飞

人工智能是新一轮产业变革的核心驱动力,正在掀起新一波的科技浪潮,尤其在自动化和数据驱动的众多领域(如图像识别、机器人、搜索引擎、自动驾驶等技术)中都有广泛的应用。由于具有免费开源、简单高效、强大的社区和第三方库支持等特点,Python在人工智能和数据科学领域独占鳌头。本书从数学建模开始讲起,将Python开发基础、数据分析、网络爬虫、自然语言处理、算法知识、人工智能项目实践等内容串联起来,层层递进,是一本Python人工智能入门书。

——Python中文社区公众号运营负责人 阿 橙

本书详细讲解了Python人工智能的相关知识,内容深入浅出,案例通俗易懂,图文并茂,代码和注解详细全面,便于读者快速上手,很好适合人工智能初学者、Python爱好者和高校师生学习。作为一线开发人员,作者长期从事人工智能及数据分析相关工作,实践经验丰富。赶快跟着本书开启您的Python人工智能破冰之旅吧!

——大学教师,CSDN博客专家,《Python网络数据抓取及分析从入门到精通》系列书作者 杨秀璋

CHAPTER 1 About Python ............................................................................................1 What Is Python? ................................................................................................................1 A Brief History of Python ................................................................................................2 Interpreters Versus Compilers .......................................................................................5 When to Use (or Not Use) an Interpreted Language .........................................8 Understanding Bytecodes ......................................................................................10 Why Use Python? ...........................................................................................................11 Object-Oriented ........................................................................................................11 Cross Platform ..........................................................................................................11 Broad User Base .......................................................................................................11 Well Supported in Third-Party Tools ...................................................................12 Good Selection of Tools Available ........................................................................12 Good Selection of Pre-built Libraries ..................................................................12 Where Is Python Used? .................................................................................................13 How Is Python Licensed? ..............................................................................................13 Where Do I Get Python? ...............................................................................................14 Installing Python ............................................................................................................14 Getting Information on Python ..................................................................................16 Python Communities .....................................................................................................17 Other Software ................................................................................................................18 And Now for Something Completely Different… ....................................................18 CHAPTER 2 Python Language Overview .................................................................19 Python Syntax .................................................................................................................20 Comments .................................................................................................................20 Indentation ...............................................................................................................20 Contents TABLE OF} vii Q Q Q Python Reserved Words ................................................................................................24 Decision Making and Iteration Keywords ..........................................................25 Debugging Keywords ..............................................................................................27 Package and Module Handling Keywords .........................................................27 Exception Handling Keywords ..............................................................................29 General Language Keywords .................................................................................31 Other Keywords ........................................................................................................32 Variable Usage ................................................................................................................34 The Continuation Variable ....................................................................................36 Watching Out for Spelling Mistakes! ..................................................................37 Predicates .........................................................................................................................38 Identifier Scope ...............................................................................................................39 Operators .........................................................................................................................42 Modulo Operator .....................................................................................................44 Exponential Operator .............................................................................................46 Logical Operators ....................................................................................................46 Comparative Operators ..........................................................................................49 Bitwise Operators ....................................................................................................51 Membership Operators and String Operators ..................................................53 Identity Operators ...................................................................................................53 In Conclusion ..................................................................................................................53 CHAPTER 3 Tools ..........................................................................................................55 IDLE ...................................................................................................................................55 File Menu ...................................................................................................................57 The Path Browser Dialog ........................................................................................62 Edit Menu ..................................................................................................................64 Shell Menu .................................................................................................................70 Debug Menu ..............................................................................................................71 The Edit Window ......................................................................................................79 Format Menu ............................................................................................................80 CONTENTS viii Q Q Q Command Line Compiler ..............................................................................................90 Creating Python Files ....................................................................................................93 Documentation ...............................................................................................................95 In Conclusion ..................................................................................................................96 CHAPTER 4 Data Types ...............................................................................................97 Numeric Types ................................................................................................................98 Integers ......................................................................................................................98 Demonstrating Long Integers ...............................................................................99 Octal and Hexadecimal ........................................................................................100 Floating Point Numbers .............................................................................................101 Strings ............................................................................................................................103 String Variables .....................................................................................................103 Concatenating Strings .........................................................................................106 Repeating Strings ..................................................................................................107 Substrings ...............................................................................................................108 Slicing ......................................................................................................................110 String Functions ....................................................................................................111 String Constants ....................................................................................................112 Conversion Functions ...........................................................................................114 Search Functions ...................................................................................................118 Formatting Functions ..........................................................................................120 Escape Sequences ..................................................................................................121 Sequences ......................................................................................................................122 Lists ..........................................................................................................................123 Shared References .................................................................................................128 Tuples .......................................................................................................................128 Dictionaries ............................................................................................................132 Advanced Type .............................................................................................................136 Classes and Objects ..............................................................................................136 Complex Type .........................................................................................................137 Generator Type ......................................................................................................138 CONTENTS ix Q Q Q None Type ...............................................................................................................139 Unicode Type ..........................................................................................................140 In Conclusion ................................................................................................................141 CHAPTER 5 Control Flow .........................................................................................143 Conditionals ..................................................................................................................144 The if Statement ..................................................................................................144 The elif Statement .............................................................................................147 The else Statement .............................................................................................149 Wrapping Up the Conditionals: A Cool Example ...........................................150 Loops ..............................................................................................................................153 The for Loop ..........................................................................................................153 The while Loop .....................................................................................................161 In Conclusion ................................................................................................................164 CHAPTER 6 Input and Output ................................................................................165 User Input ......................................................................................................................165 The input Function ..............................................................................................166 The raw_input Function ....................................................................................168 User Output ...................................................................................................................170 Formatting ..............................................................................................................172 File Input .......................................................................................................................175 File Output ....................................................................................................................177 Closing Files ..................................................................................................................179 Positioning in Files ......................................................................................................180 Directories and Files ...................................................................................................183 The stat Module: File Statistics ..............................................................................186 Command Line Arguments ........................................................................................190 Pickle ..............................................................................................................................192 In Conclusion ................................................................................................................195 CONTENTS x Q Q Q CHAPTER 7 Functions and Modules .....................................................................197 What Is a Function? ....................................................................................................197 Defining Functions in Python ...................................................................................197 What Are Arguments? ................................................................................................200 How Do You Pass an Argument to a Function? ....................................................201 Default Arguments ......................................................................................................203 Variable Default Arguments .....................................................................................205 Keyword Arguments ....................................................................................................206 Returning Values from Functions ............................................................................207 Returning Multiple Values from Functions ...........................................................209 Recursive Functions ....................................................................................................210 Passing Functions as Arguments .............................................................................212 Lambda Functions .......................................................................................................213 Variable Numbers of Arguments to a Function ....................................................215 Variable Scope in Functions ......................................................................................216 Using Modules ..............................................................................................................218 In Conclusion ................................................................................................................219 CHAPTER 8 Exception Handling ............................................................................221 Looking at Exceptions in Python ..............................................................................222 Traceback Example ......................................................................................................223 Understanding Tracebacks ........................................................................................224 Exceptions .....................................................................................................................225 Catching Exceptions with try..except .........................................................226 Multiple except Clauses .....................................................................................229 Blank except Clauses ..........................................................................................231 The else Clauses .........................................................................................................232 The finally Clause ....................................................................................................234 Raising Your Own Exceptions ...................................................................................235 Exception Arguments .................................................................................................237 User-Defined Exceptions ............................................................................................238 Working with the Exception Information ..............................................................239 CONTENTS xi Q Q Q exc_type ................................................................................................................239 exc_value ..............................................................................................................240 Using the with Clause for Files ................................................................................243 Re-throwing Exceptions .............................................................................................244 In Conclusion ................................................................................................................246 CHAPTER 9 Object-Oriented Programming .........................................................247 A Brief History of OOP ................................................................................................247 What Is an Object? ......................................................................................................248 Why Do We Use Objects? ...........................................................................................249 Reuse ........................................................................................................................249 Ease in Debugging .................................................................................................250 Maintainability ......................................................................................................250 The Attributes of Object-Oriented Development .................................................251 Abstraction .............................................................................................................251 Data Hiding ............................................................................................................252 Inheritance .............................................................................................................253 Polymorphism ........................................................................................................255 Terminology ..................................................................................................................256 Class .........................................................................................................................256 Object .......................................................................................................................256 Attribute ..................................................................................................................257 Method ....................................................................................................................258 Message Passing ....................................................................................................259 Event Handling ......................................................................................................260 Derivation ...............................................................................................................260 Coupling ..................................................................................................................261 Cohesion ..................................................................................................................261 Constants ................................................................................................................261 Other Concepts .............................................................................................................262 In Conclusion ................................................................................................................262 CONTENTS xii Q Q Q CHAPTER 10 Classes and Objects in Python ..........................................................265 Python Classes ..............................................................................................................265 Properties ......................................................................................................................267 Attribute Modifying Functions .................................................................................272 Private Attributes ........................................................................................................274 Doc Strings ....................................................................................................................275 Properties ......................................................................................................................277 The self Object ...........................................................................................................279 Methods .........................................................................................................................281 Special Methods ...........................................................................................................283 Initialization ...........................................................................................................283 Termination ............................................................................................................284 String Conversion ..................................................................................................285 Inheritance ....................................................................................................................287 Multiple Inheritance ...................................................................................................291 Using super ..................................................................................................................293 Polymorphism ..............................................................................................................295 Exception Classes .........................................................................................................297 Iterators .........................................................................................................................299 Operator Overloading .................................................................................................301 In Conclusion ................................................................................................................304 CHAPTER 11 The Python Library ..............................................................................305 Containers .....................................................................................................................305 Working with the deque Class ...........................................................................306 Math ................................................................................................................................312 Complex Math ..............................................................................................................313 Types ...............................................................................................................................315 Strings ............................................................................................................................318 Regular Expressions ....................................................................................................319 Patterns ...................................................................................................................320 Special Sequence Characters ..............................................................................323 CONTENTS xiii Q Q Q Compiling Regular Expressions .........................................................................323 Matching Strings ...................................................................................................324 Meta Characters ....................................................................................................326 Grouping .................................................................................................................327 System ............................................................................................................................328 Random Number Generation ....................................................................................330 Dates and Times ...........................................................................................................331 Creating a New Time ............................................................................................332 Time Operations ....................................................................................................332 Creating a New Date .............................................................................................333 Date Operations ....................................................................................................333 Time Zone Information ........................................................................................335 Operating System Interface .......................................................................................336 System Information ..............................................................................................336 Process Management ...........................................................................................337 In Conclusion ................................................................................................................341 CHAPTER 12 The GUI — TkInter ...............................................................................343 What Is TkInter? ...........................................................................................................343 Terms and Conditions .................................................................................................343 Event Handling ......................................................................................................344 Callbacks .................................................................................................................344 Widgets ....................................................................................................................345 Layout Managers ...................................................................................................345 Working with TkInter .................................................................................................346 Creating a Label ...........................................................................................................347 Frame Widgets and Centering ..................................................................................349 An Application with a Button ...................................................................................351 Working with Entry Fields and Grid Layouts ........................................................353 Creating a Class to Handle User Interfaces ...........................................................356 Working with List Boxes ............................................................................................358 Scrolling a List Box ................................................................................................361 CONTENTS xiv Q Q Q Menus .............................................................................................................................363 Context Menus .............................................................................................................366 Scale Widgets ................................................................................................................367 RadioButtons and CheckButton ...............................................................................370 Text Widgets .................................................................................................................373 In Conclusion ................................................................................................................375 CHAPTER 13 The Web Server—Apache ...................................................................377 Setting Up Apache .......................................................................................................377 Testing Apache .............................................................................................................378 Your First Python CGI Script: Hello Apache ...........................................................379 Examining the Hello Python Script ...................................................................380 The cgi-bin Directory ............................................................................................381 A Script for Displaying the Environment ...............................................................382 Receiving Data from an HTML File ..........................................................................384 Sending Data to an HTML File ..................................................................................387 How It All Works ...................................................................................................390 Dynamic HTML Displays Based on User Input ......................................................391 HTML Elements ............................................................................................................396 Cookies ...........................................................................................................................399 Uploading Files ............................................................................................................402 Redirection ....................................................................................................................403 Error Handling ..............................................................................................................405 In Conclusion ................................................................................................................406 CHAPTER 14 Working with Databases ...................................................................407 What Is a Database? ...................................................................................................407 Simple Database Terminology ...........................................................................408 What Is MySQL? ...........................................................................................................409 Downloading and Installing ......................................................................................409 Creating a New Database ..........................................................................................410 Creating a New User ....................................................................................................414 CONTENTS xv Q Q Q Opening an Existing Database .................................................................................415 Writing to a Database ................................................................................................417 Reading from a Database ..........................................................................................421 Updating a Database ..................................................................................................424 Deleting from a Database ..........................................................................................427 Searching a Database .................................................................................................430 In Conclusion ................................................................................................................436 CHAPTER 15 Putting It All Together .......................................................................437 Designing the Application .........................................................................................437 Program Flow .........................................................................................................437 User Interface Design ...........................................................................................438 Database Design ...................................................................................................439 Implementing the Database Tables ........................................................................440 Implementing the Forms ...........................................................................................442 Adding Reviews ............................................................................................................449 Adding the Review to the Database ........................................................................452 Listing the Reviews ......................................................................................................456 Deleting Books .............................................................................................................459 In Conclusion ................................................................................................................462 CHAPTER 16 Python and Graphics ..........................................................................463 The PIL Library ..............................................................................................................463 Downloading ..........................................................................................................464 Installing .................................................................................................................464 Verifying Your Installation ..................................................................................465 Creating a New Image ................................................................................................465 Function Parameters ............................................................................................466 Drawing on the Image ................................................................................................467 Drawing the Image ...............................................................................................468 Displaying the Image ...........................................................................................470 CONTENTS xvi Q Q Q
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值