Python大学教程:面向计算机科学和数据科学(英文版)

作者
[美]保罗·戴特尔(Paul Deitel) 哈维·戴特尔(Harvey Deitel)
丛书名
经典原版书库
出版社
机械工业出版社
ISBN
9787111671503
简要
简介
内容简介书籍计算机书籍 本书提供了一种独特的方法来讲解Python编程入门,内容符合最新的ACM/IEEECS和相关的计算课程倡议,以及由美国国家科学基金会赞助的数据科学本科课程。内容涵盖了最新的主题和应用的覆盖面,模块化架构使教师能够方便地调整文本,适应课程需求。
目录
第1章 计算机和Python简介 1
1.1 引言 2
1.2 硬件和软件 3
1.2.1 摩尔定律 4
1.2.2 计算机组成 4
1.3 数据层级 6
1.4 机器语言、汇编语言和高级语言 9
1.5 对象技术简介 10
1.6 操作系统 13
1.7 Python简介 16
1.8 (语言)库 18
1.8.1 Python标准库 18
1.8.2 数据科学库 18
1.9 其他常见编程语言 20
1.10 试用:使用IPython和Jupyter Notebook 21
1.10.1 将IPython交互模型用作计算器 21
1.10.2 使用IPython解释器执行Python程序 23
1.10.3 在Jupyter Notebook中编写和执行代码 24
1.11 Internet和WWW 29
1.11.1 Internet:网际网 29
1.11.2 WWW:用户友善的Internet 30
1.11.3 计算和资源云 30
1.11.4 物联网 31
1.12 软件技术 32
1.13 大数据 33
1.13.1 大数据分析 38
1.13.2 数据科学和大数据案例研究 39
1.14 数据科学入门:大数据移动应用案例研究 40
第2章 Python程序设计简介 49
2.1 引言 50
2.2 变量和赋值语句 50
2.3 算术操作 52
2.4 print函数、单引号字符串和双引号字符串 56
2.5 三引号字符串 58
2.6 从用户处获得输入 59
2.7 判断:if语句与比较操作 61
2.8 对象和动态类型 66
2.9 数据科学入门:基本统计功能 68
2.10 小结 70
第3章 控制语句和程序设计 73
3.1 引言 74
3.2 算法 74
3.3 伪代码 75
3.4 控制语句 75
3.5 if语句 78
3.6 if...else和if...elif...else语句 80
3.7 while语句 85
3.8 for语句 86
3.8.1 迭代、列表和迭代器 88
3.8.2 内置range函数 88
3.9 增量赋值 89
3.10 程序设计:通过序列控制重复 90
3.10.1 需求声明 90
3.10.2 算法的伪代码形式 90
3.10.3 在Python中为算法编码 91
3.10.4 格式化字符串简介 92
3.11 程序设计:通过哨兵控制重复 93
3.12 程序设计:嵌套控制结构 97
3.13 内置函数range:进一步讨论 101
3.14 使用Decimal类型表达货币总量 102
3.15 break和continue语句 105
3.16 布尔操作and、or和not 106
3.17 数据科学入门:趋势的度量—均值、中值、众数 109
3.18 小结 111
第4章 函数 119
4.1 引言 120
4.2 函数的定义 120
4.3 多参数函数 123
4.4 随机数生成器 125
4.5 案例研究:机会游戏 128
4.6 Python标准库 131
4.7 math模块函数 132
4.8 使用IPython的tab补全功能 133
4.9 缺省形参值 135
4.10 关键字实参 136
4.11 任意实参表 136
4.12 方法:归属于对象的函数 138
4.13 作用域规则 138
4.14 import:进一步讨论 140
4.15 给函数传递实参:进一步讨论 142
4.16 函数调用栈 145
4.17 函数式程序设计 146
4.18 数据科学入门:数据分布的度量 148
4.19 小结 150
第5章 序列:列表和元组 155
5.1 引言 156
5.2 列表 156
5.3 元组 161
5.4 序列拆包 163
5.5 序列切片 166
5.6 del语句 169
5.7 给函数传递列表 171
5.8 排序列表 172
5.9 搜索序列 174
5.10 其他列表方法 176
5.11 用列表模拟栈 178
5.12 列表解析 179
5.13 生成器表达式 181
5.14 过滤器、映射和约简 182
5.15 其他序列处理函数 185
5.16 二维列表 187
5.17 数据科学入门:模拟和静态可视化 191
5.17.1 600、60000和6000000次掷骰子的图示 191
5.17.2 掷骰子实验的序列和百分比的可视化 193
5.18 小结 199
第6章 字典和集合 209
6.1 引言 210
6.2 字典 210
6.2.1 创建字典 210
6.2.2 在字典中遍历 212
6.2.3 基本的字典操作 212
6.2.4 字典方法keys和values 214
6.2.5 字典比较 216
6.2.6 案例研究:学生成绩字典 217
6.2.7 案例研究:词计数 218
6.2.8 字典方法update 220
6.2.9 字典解析 220
6.3 集合 221
6.3.1 集合比较 223
6.3.2 集合的数学操作 225
6.3.3 集合的可变操作和方法 226
6.3.4 集合解析 228
6.4 数据科学入门:动态可视化 228
6.4.1 了解动态可视化 228
6.4.2 实现动态可视化 231
6.5 小结 234
第7章 使用NumPy进行面向数组的编程 239
7.1 引言 240
7.2 从已有数据中创建数组 241
7.3 数组属性 242
7.4 用特定值填充数组 244
7.5 使用range创建数组 244
7.6 列表与数组的性能比较:%timeit简介 246
7.7 数组操作 248
7.8 NumPy计算方法 250
7.9 全局函数 252
7.10 索引和切片 254
7.11 视图:浅拷贝 256
7.12 深拷贝 258
7.13 转换和转置 259
7.14 数据科学入门:pandas Series和DataFrame 262
7.14.1 pandas series 262
7.14.2 DataFrame 267
7.15 小结 275
第8章 字符串:进一步讨论 283
8.1 引言 284
8.2 格式化字符串 285
8.2.1 类型声明 285
8.2.2 域宽和对齐 286
8.2.3 数值格式化 287
8.2.4 字符串format方法 288
8.3 字符串拼接和重复 289
8.4 字符串空白符剥离 290
8.5 改变字符的大小写 291
8.6 字符串比较操作 292
8.7 子串搜索 292
8.8 子串替换 294
8.9 字符串切分和合并 294
8.10 字符和字符测试方法 297
8.11 原生字符串 298
8.12 正则表达式简介 299
8.12.1 re模块和fullmatch函数 300
8.12.2 子串替换和串切分 303
8.12.3 其他搜索函数和匹配处理 304
8.13 数据科学入门:pandas、正则表达式和数据治理 307
8.14 小结 312
第9章 文件和异常 319
9.1 引言 320
9.2 文件 321
9.3 文本文件处理 321
9.3.1 写文本文件:with语句简介 322
9.3.2 读文本文件 323
9.4 更新文本文件 325
9.5 JSON序列化 327
9.6 安全问题:pickle序列化和反序列化 330
9.7 关于文件的其他说明 330
9.8 异常处理 331
9.8.1 除0异常和非法输入 332
9.8.2 try语句 332
9.8.3 在except从句中捕捉多重异常 335
9.8.4 函数或过程能够抛出什么异常 336
9.8.5 try套件应该封装什么代码 336
9.9 finally子句 336
9.10 显式引发异常 339
9.11 (可选)栈展开和回溯 339
9.12 数据科学入门:CSV文件的处理 342
9.12.1 Python标准库模块CSV 342
9.12.2 将CVS文件读入pandas DataFrame 344
9.12.3 读取Titanic Disaster数据库 346
9.12.4 对Titanic Disaster数据库进行简单的数据分析 347
9.12.5 乘客年龄直方图 348
9.13 小结 349
第10章 面向对象程序设计 355
10.1 引言 356
10.2 定制类Account 358
10.2.1 试用Account类 358
10.2.2 Account类的定义 360
10.2.3 组合:对象引用作为类的成员 361
10.3 属性的受控访问 363
10.4 数据访问的特性 364
10.4.1 试用Time类 364
10.4.2 Time类的定义 366
10.4.3 Time类定义的设计要领 370
10.5 私有属性模拟 371
10.6 案例研究:洗牌和切牌 373
10.6.1 试用Card和DeckofCards类 373
10.6.2 Card类属性简介 375
10.6.3 DeckofCards类 377
10.6.4 在Matplotlib中显示扑克图片 378
10.7 继承:基类和子类 382
10.8 构建继承层次和多态简介 384
10.8.1 基类Commission-Employee 384
10.8.2 子类SalariedCommission-Employee 387
10.8.3 CommissionEmployee和SalariedCommissionEmployee的多态处理 391
10.8.4 关于基于对象和面向对象程序设计的说明 391
10.9 鸭子类型和多态 392
10.10 操作符重载 393
10.10.1 试用Complex类 394
10.10.2 Complex类的定义 395
10.11 异常类层次和定制异常处理 397
10.12 有名元组 399
10.13 Python 3.7新数据类简介 400
10.13.1 创建Card数据类 401
10.13.2 使用Card数据类 403
10.13.3 数据类相较有名元组的优势 405
10.13.4 数据类相较传统类的优势 406
10.14 使用文档字符串和doctest进行单元测试 406
10.15 命名空间和作用域 411
10.16 数据科学入门:时间序列和简单线性回归 414
10.17 小结 423
第11章 计算机科学思维:递归、搜索、排序和大O表示法 431
11.1 引言 432
11.2 阶乘 433
11.3 阶乘的递归法 433
11.4 斐波那契数列的递归法 436
11.5 递归和循环 439
11.6 搜索和排序 440
11.7 线性搜索 440
11.8 算法效率:大O表示法 442
11.9 二叉搜索 444
11.9.1 二叉搜索的实现 445
11.9.2 二叉搜索的大O表示法 447
11.10 排序算法 448
11.11 选择排序 448
11.11.1 选择排序的实现 449
11.11.2 效用函数print_pass 450
11.11.3 选择排序的大O表示法 451
11.12 插入排序 451
11.12.1 插入排序的实现 452
11.12.2 插入排序的大O表示法 453
11.13 归并排序 454
11.13.1 归并排序的实现 454
11.13.2 归并排序的大O表示法 459
11.14 总结:本章算法的大O表示法 459
11.15 可视化算法 460
11.15.1 生成函数 462
11.15.2 实现选择排序算法的动画演示 463
11.16 小结 468
第12章 自然语言处理 477
12.1 引言 478
12.2 TextBlob 479
12.2.1 创建TextBlob 481
12.2.2 语料化:文本的断句和取词 482
12.2.3 言语分部标注 482
12.2.4 提取名词短语 483
12.2.5 使用TextBlob缺省情绪分析器进行文本情绪分析 484
12.2.6 使用NaiveBayesAnalyzer进行文本情绪分析 486
12.2.7 语言检测和翻译 487
12.2.8 屈折辨析:多元化和单一化 489
12.2.9 拼写检查和更正 489
12.2.10 规范化:词根和词性还原 490
12.2.11 词频 491
12.2.12 从WordNet中获取定义、同义词、反义词 492
12.2.13 停用词删除 494
12.2.14 n-gram模型 496
12.3 使用Bar Charts和Word Clouds进行词频可视化 497
12.3.1 使用Bar Charts进行词频可视化 497
12.3.2 使用Word Clouds进行词频可视化 500
12.4 使用Textatistic进行可读性评测 503
12.5 使用spaCy进行有名实体识别 505
12.6 使用spaCyn进行相似性评估 507
12.7 其他NLP工具和库 509
12.8 机器学习和深度学习的自然语言应用 509
12.9 自然语言数据集 510
12.10 小结 510
第13章 Twitter数据挖掘 515
13.1 引言 516
13.2 Twitter API概述 518
13.3 创建Twitter账户 519
13.4 获取Twitter证书—创建App 520
13.5 推文中有什么 521
13.6 Tweepy 525
13.7 使用Tweepy在Twitter中认证 525
13.8 从Twitter账户中获取信息 527
13.9 Tweepy Cursors简介:获取账户的关注者和好友 529
13.9.1 确定账户的关注者 529
13.9.2 确定账户关注了谁 532
13.9.3 获取用户当前的推文 532
13.10 搜索当前推文 534
13.11 趋势发现:Twitter趋势API 536
13.11.1 趋势主题位置获取 536
13.11.2 趋势主题列表获取 537
13.11.3 从趋势主题中创建词云 539
13.12 推文分析前的清理/预处理 541
13.13 Twitter流处理API 542
13.13.1 创建StreamListener的子类 543
13.13.2 流处理初始化 545
13.14 推文情感分析 547
13.15 地址匹配与映射 551
13.15.1 推文的获取和映射 552
13.15.2 twetutilities.py效用函数 556
13.15.3 LocationListener类 558
13.16 存储推文的方式 559
13.17 Twitter和时间序列 560
13.18 小结 560
第14章 IBM Watson和认知计算 565
14.1 引言:IBM Watson和认知计算 566
14.2 IBM云账户和云控制台 568
14.3 Watson服务 568
14.4 附加服务和工具 572
14.5 Watson开发者云Python SDK 573
14.6 案例研究:旅行者助手—翻译App 574
14.6.1 运行App前的准备工作 575
14.6.2 试用App 576
14.6.3 SimpleLanguageTranslator.py脚本走查 577
14.7 Watson资源 587
14.8 小结 589
第15章 机器学习:分类、回归和聚类 593
15.1 机器学习入门 594
15.1.1 Scikit-learn 595
15.1.2 机器学习的类别 596
15.1.3 Scikit-learn数据集 598
15.1.4 经典的数据科学研究步骤 599
15.2 案例研究:数字数据集上的k近邻分类法(第一部分) 599
15.2.1 k近邻算法 601
15.2.2 载入数据集 602
15.2.3 可视化数据 606
15.2.4 划分训练集和测试集 608
15.2.5 创立模型 609
15.2.6 训练模型 610
15.2.7 预测数字类别 610
15.3 案例研究:数字数据集上的k近邻分类法(第二部分) 612
15.3.1 模型的准确性度量 612
15.3.2 k折交叉验证 616
15.3.3 多模型寻优 617
15.3.4 超参调优 619
15.4 案例研究:时间序列和简单线性回归 620
15.5 案例研究:加州订房数据集上的多线性回归 625
15.5.1 载入数据集 626
15.5.2 用pandas观察数据集 628
15.5.3 特征的可视化 630
15.5.4 划分训练集和测试集 634
15.5.5 训练模型 634
15.5.6 测试模型 635
15.5.7 预期及预测价格的可视化 636
15.5.8 回归模型度量 637
15.5.9 最佳模型选择 638
15.6 案例研究:无监督机器学习—降维 639
15.7 案例研究:无监督机器学习—k均值聚类 642
15.7.1 载入Iris数据集 644
15.7.2 观察Iris数据集:使用pandas进行统计描述 646
15.7.3 使用Seaborn pairplot可视化数据集 647
15.7.4 使用评估器KMeans 650
15.7.5 使用主成分分析法进行降维 652
15.7.6 选择最佳聚类评估器 655
15.8 小结 656
第16章 深度学习 665
16.1 引言 666
16.1.1 深度学习应用 668
16.1.2 深度学习演示程序 669
16.1.3 Keras资源 669
16.2 Keras内置数据集 669
16.3 Anaconda定制化环境 670
16.4 神经网络 672
16.5 张量 674
16.6 视觉处理卷积神经网络和多分类器 676
16.6.1 载入MNIST数据集 677
16.6.2 数据探索 678
16.6.3 数据准备 680
16.6.4 构造神经网络 682
16.6.5 模型训练和评价 691
16.6.6 模型存储和载入 696
16.7 使用TensorBoard进行神经网络训练的可视化 697
16.8 ConvnetJS:基于浏览器的深度学习训练和可视化 700
16.9 序列处理中的循环神经网络和IMDb数据集的情感分析 701
16.9.1 载入IMDb电影评论数据集 702
16.9.2 数据探索 703
16.9.3 数据准备 705
16.9.4 构造神经网络 706
16.9.5 模型训练和评价 709
16.10 深度学习模型调参 710
16.11 ImageNet上的卷积网络模型预学习 711
16.12 强化学习 712
16.12.1 深度强化学习 713
16.12.2 OpenAI Gym 713
16.13 小结 714
第17章 大数据:Hadoop、Spark、NoSQL和IoT 723
17.1 引言 724
17.2 关系型数据库和结构化查询语言 728
17.2.1 books数据库 730
17.2.2 SELECT查询 734
17.2.3 WHERE子句 734
17.2.4 ORDER BY子句 736
17.2.5 INNER JOIN:从多个表中合并数据 737
17.2.6 INSERT INTO语句 738
17.2.7 UPDATE语句 739
17.2.8 DELETE FROM语句 739
17.3 NoSQL和NewSQL大数据数据库概述 741
17.3.1 NoSQL键值对数据库 741
17.3.2 NoSQL文档数据库 742
17.3.3 NoSQL列数据库 742
17.3.4 NoSQL图数据库 743
17.3.5 NewSQL数据库 743
17.4 案例研究:MongoDB JSON文档数据库 744
17.4.1 创建MongoDB Atlas簇 745
17.4.2 将推文注入MongoDB 746
17.5 Hadoop 755
17.5.1 Hadoop概述 755
17.5.2 使用MapReduce汇总Romeo and Juliet的词长度 758
17.5.3 在微软Azure HDInsight上创建Apache簇 758
17.5.4 Hadoop Streaming 760
17.5.5 Mapper的实现 760
17.5.6 Reducer的实现 761
17.5.7 准备运行MapReduce案例研究 762
17.5.8 运行MapReduce作业 763
17.6 Spark 766
17.6.1 Spark概述 766
17.6.2 Docker和Jupyter Docker栈 767
17.6.3 使用Spark进行词统计 770
17.6.4 在微软Azure上进行词统计 773
17.7 Spark Streaming:使用pyspark-notebook Docker栈进行Twitter哈希标注统计 777
17.7.1 将推文注入套接字 777
17.7.2 推文哈希标注累计和Spark SQL简介 780
17.8 物联网和仪表盘 786
17.8.1 发布和订阅 788
17.8.2 使用Freeboard仪表盘可视化PubNub实时采样流 788
17.8.3 使用Python模拟互联网恒温器 790
17.8.4 使用Freeboard.io创建仪表盘 792
17.8.5 创建Python PubNub订阅 794
17.9 小结 798
Contents
1Introduction to Computers and Python 1
1.1 Introduction 2
1.2 Hardware and Software 3
1.2.1 Moore’s Law 4
1.2.2 Computer Organization 4
1.3 Data Hierarchy 6
1.4 Machine Languages, Assembly Languages and High-Level Languages 9
1.5 Introduction to Object Technology 10
1.6 Operating Systems 13
1.7 Python 161.8It’s the Libraries! 18
1.8.1 Python Standard Library 18
1.8.2 Data-Science Libraries 18
1.9 Other Popular Programming Languages 20
1.10 Test-Drive: Using IPython and Jupyter Notebooks 21
1.10.1 Using IPython Interactive Mode as a Calculator 21
1.10.2 Executing a Python Program Using the IPython Interpreter 23
1.10.3 Writing and Executing Code in a Jupyter Notebook 24
1.11 Internet and World Wide Web 29
1.11.1 Internet: A Network of Networks 29
1.11.2 World Wide Web: Making the Internet User-Friendly 30
1.11.3 The Cloud 30
1.11.4 Internet of Things 31
1.12 Software Technologies 32
1.13 How Big Is Big Data 33
1.13.1 Big Data Analytics 38
1.13.2 Data Science and Big Data Are Making a Difference: Use Cases 39
1.14 Intro to Data Science: Case Study—A Big-Data Mobile Application 40
2Introduction to Python Programming 49
2.1 Introduction 50
2.2 Variables and Assignment Statements 50
2.3 Arithmetic 52
2.4 Function print and an Intro to Single- and Double-Quoted Strings 56
2.5Triple-Quoted Strings 58
2.6Getting Input from the User 59
2.7Decision Making: The if Statement and Comparison Operators 61
2.8Objects and Dynamic Typing 66
2.9Intro to Data Science: Basic Descriptive Statistics 68
2.10Wrap-Up 70
3Control Statements and Program Development 73
3.1Introduction 74
3.2Algorithms 74
3.3Pseudocode 75
3.4Control Statements 75
3.5if Statement 78
3.6if…else and if…elif…else Statements 80
3.7while Statement 85
3.8for Statement 86
3.8.1Iterables, Lists and Iterators 88
3.8.2Built-In range Function 88
3.9Augmented Assignments 89
3.10Program Development: Sequence-Controlled Repetition 90
3.10.1Requirements Statement 90
3.10.2Pseudocode for the Algorithm 90
3.10.3Coding the Algorithm in Python 91
3.10.4Introduction to Formatted Strings 92
3.11Program Development: Sentinel-Controlled Repetition 93
3.12Program Development: Nested Control Statements 97
3.13Built-In Function range: A Deeper Look 101
3.14Using Type Decimal for Monetary Amounts 102
3.15break and continue Statements 105
3.16Boolean Operators and, or and not 106
3.17Intro to Data Science: Measures of Central Tendency—Mean, Median and Mode109
3.18Wrap-Up 111
4Functions 119
4.1Introduction 120
4.2Defining Functions 120
4.3Functions with Multiple Parameters 123
4.4Random-Number Generation 125
4.5Case Study: A Game of Chance 128
4.6Python Standard Library 131
4.7math Module Functions 132
4.8Using IPython Tab Completion for Discovery 133
4.9Default Parameter Values 135
4.10Keyword Arguments 136
4.11Arbitrary Argument Lists 136
4.12Methods: Functions That Belong to Objects 138
4.13Scope Rules 138
4.14import: A Deeper Look 140
4.15Passing Arguments to Functions: A Deeper Look 142
4.16Function-Call Stack 145
4.17Functional-Style Programming 146
4.18Intro to Data Science: Measures of Dispersion 148
4.19Wrap-Up 150
5Sequences: Lists and Tuples 155
5.1Introduction 156
5.2Lists 156
5.3Tuples 161
5.4Unpacking Sequences 163
5.5Sequence Slicing 166
5.6del Statement 169
5.7Passing Lists to Functions 171
5.8Sorting Lists 172
5.9Searching Sequences 174
5.10Other List Methods 176
5.11Simulating Stacks with Lists 178
5.12List Comprehensions 179
5.13Generator Expressions 181
5.14Filter, Map and Reduce 182
5.15Other Sequence Processing Functions 185
5.16Two-Dimensional Lists 187
5.17Intro to Data Science: Simulation and Static Visualizations 191
5.17.1Sample Graphs for 600, 60,000 and 6,000,000 Die Rolls 191
5.17.2Visualizing Die-Roll Frequencies and Percentages 193
5.18Wrap-Up 199
6Dictionaries and Sets 209
6.1Introduction 210
6.2Dictionaries 210
6.2.1Creating a Dictionary 210
6.2.2Iterating through a Dictionary 212
6.2.3Basic Dictionary Operations 212
6.2.4Dictionary Methods keys and values 214
6.2.5Dictionary Comparisons 216
6.2.6Example: Dictionary of Student Grades 217
6.2.7Example: Word Counts 218
6.2.8Dictionary Method update 220
6.2.9Dictionary Comprehensions 220
6.3Sets 221
6.3.1Comparing Sets 223
6.3.2Mathematical Set Operations 225
6.3.3Mutable Set Operators and Methods 226
6.3.4Set Comprehensions 228
6.4Intro to Data Science: Dynamic Visualizations 228
6.4.1How Dynamic Visualization Works 228
6.4.2Implementing a Dynamic Visualization 231
6.5Wrap-Up 234
7Array-Oriented Programming with NumPy 239
7.1Introduction 240
7.2Creating arrays from Existing Data 241
7.3array Attributes 242
7.4Filling arrays with Specific Values 244
7.5Creating arrays from Ranges 244
7.6List vs. array Performance: Introducing %timeit 246
7.7array Operators 248
7.8NumPy Calculation Methods 250
7.9Universal Functions 252
7.10Indexing and Slicing 254
7.11Views: Shallow Copies 256
7.12Deep Copies 258
7.13Reshaping and Transposing 259
7.14Intro to Data Science: pandas Series and DataFrames 262
7.14.1pandas Series 262
7.14.2DataFrames 267
7.15Wrap-Up 275
8Strings: A Deeper Look 283
8.1Introduction 284
8.2Formatting Strings 285
8.2.1Presentation Types 285
8.2.2Field Widths and Alignment 286
8.2.3Numeric Formatting 287
8.2.4String’s format Method 288
8.3Concatenating and Repeating Strings 289
8.4Stripping Whitespace from Strings 290
8.5Changing Character Case 291
8.6Comparison Operators for Strings 292
8.7Searching for Substrings 292
8.8Replacing Substrings 294
8.9Splitting and Joining Strings 294
8.10Characters and Character-Testing Methods 297
8.11Raw Strings 298
8.12Introduction to Regular Expressions 299
8.12.1re Module and Function fullmatch 300
8.12.2Replacing Substrings and Splitting Strings 303
8.12.3Other Search Functions; Accessing Matches 304
8.13Intro to Data Science: Pandas, Regular Expressions and Data Munging 307
8.14Wrap-Up 312
9Files and Exceptions 319
9.1Introduction 320
9.2Files 321
9.3Text-File Processing 321
9.3.1Writing to a Text File: Introducing the with Statement 322
9.3.2Reading Data from a Text File 323
9.4Updating Text Files 325
9.5Serialization with JSON 327
9.6Focus on Security: pickle Serialization and Deserialization 330
9.7Additional Notes Regarding Files 330
9.8Handling Exceptions 331
9.8.1Division by Zero and Invalid Input 332
9.8.2try Statements 332
9.8.3Catching Multiple Exceptions in One except Clause 335
9.8.4What Exceptions Does a Function or Method Raise 336
9.8.5What Code Should Be Placed in a try Suite 336
9.9finally Clause 336
9.10Explicitly Raising an Exception 339
9.11(Optional) Stack Unwinding and Tracebacks 339
9.12Intro to Data Science: Working with CSV Files 342
9.12.1Python Standard Library Module csv 342
9.12.2Reading CSV Files into Pandas DataFrames 344
9.12.3Reading the Titanic Disaster Dataset 346
9.12.4Simple Data Analysis with the Titanic Disaster Dataset 347
9.12.5Passenger Age Histogram 348
9.13Wrap-Up 349
10Object-Oriented Programming 355
10.1Introduction 356
10.2Custom Class Account 358
10.2.1Test-Driving Class Account 358
10.2.2Account Class Definition 360
10.2.3Composition: Object References as Members of Classes 361
10.3Controlling Access to Attributes 363
10.4Properties for Data Access 364
10.4.1Test-Driving Class Time 364
10.4.2Class Time Definition 366
10.4.3Class Time Definition Design Notes 370
10.5Simulating “Private” Attributes 371
10.6Case Study: Card Shuffling and Dealing Simulation 373
10.6.1Test-Driving Classes Card and DeckOfCards 373
10.6.2Class Card—Introducing Class Attributes 375
10.6.3Class DeckOfCards 377
10.6.4Displaying Card Images with Matplotlib 378
10.7Inheritance: Base Classes and Subclasses 382
10.8Building an Inheritance Hierarchy; Introducing Polymorphism 384
10.8.1Base Class CommissionEmployee 384
10.8.2Subclass SalariedCommissionEmployee 387
10.8.3Processing CommissionEmployees and SalariedCommissionEmployees Polymorphically 391
10.8.4A Note About Object-Based and Object-Oriented Programming 391
10.9Duck Typing and Polymorphism 392
10.10Operator Overloading 393
10.10.1Test-Driving Class Complex 394
10.10.2Class Complex Definition 395
10.11Exception Class Hierarchy and Custom Exceptions 397
10.12Named Tuples 399
10.13A Brief Intro to Python 3.7’s New Data Classes 400
10.13.1Creating a Card Data Class 401
10.13.2Using the Card Data Class 403
10.13.3Data Class Advantages over Named Tuples 405
10.13.4Data Class Advantages over Traditional Classes 406
10.14Unit Testing with Docstrings and doctest 406
10.15Namespaces and Scopes 411
10.16Intro to Data Science: Time Series and Simple Linear Regression 414
10.17Wrap-Up 423
11Computer Science Thinking: Recursion, Searching, Sorting and Big O 431
11.1Introduction 432
11.2Factorials 433
11.3Recursive Factorial Example 433
11.4Recursive Fibonacci Series Example 436
11.5Recursion vs. Iteration 439
11.6Searching and Sorting 440
11.7Linear Search 440
11.8Efficiency of Algorithms: Big O 442
11.9Binary Search 444
11.9.1Binary Search Implementation 445
11.9.2Big O of the Binary Search 447
11.10Sorting Algorithms 448
11.11Selection Sort 448
11.11.1Selection Sort Implementation 449
11.11.2Utility Function print_pass 450
11.11.3Big O of the Selection Sort 451
11.12Insertion Sort 451
11.12.1Insertion Sort Implementation 452
11.12.2Big O of the Insertion Sort 453
11.13Merge Sort 454
11.13.1Merge Sort Implementation 454
11.13.2Big O of the Merge Sort 459
11.14Big O Summary for This Chapter’s Searching and Sorting Algorithms 459
11.15Visualizing Algorithms 460
11.15.1Generator Functions 462
11.15.2Implementing the Selection Sort Animation 463
11.16Wrap-Up 468
12Natural Language Processing(NLP) 477
12.1Introduction 478
12.2TextBlob 479
12.2.1Create a TextBlob 481
12.2.2Tokenizing Text into Sentences and Words 482
12.2.3Parts-of-Speech Tagging 482
12.2.4Extracting Noun Phrases 483
12.2.5Sentiment Analysis with TextBlob’s Default Sentiment Analyzer 484
12.2.6Sentiment Analysis with the NaiveBayesAnalyzer 486
12.2.7Language Detection and Translation 487
12.2.8Inflection: Pluralization and Singularization 489
12.2.9Spell Checking and Correction 489
12.2.10Normalization: Stemming and Lemmatization 490
12.2.11Word Frequencies 491
12.2.12Getting Definitions, Synonyms and Antonyms from WordNet 492
12.2.13Deleting Stop Words 494
12.2.14n-grams 496
12.3Visualizing Word Frequencies with Bar Charts and Word Clouds 497
12.3.1Visualizing Word Frequencies with Pandas 497
12.3.2Visualizing Word Frequencies with Word Clouds 500
12.4Readability Assessment with Textatistic 503
12.5Named Entity Recognition with spaCy 505
12.6Similarity Detection with spaCy 507
12.7Other NLP Libraries and Tools 509
12.8Machine Learning and Deep Learning Natural Language Applications 509
12.9Natural Language Datasets 510
12.10Wrap-Up 510
13Data Mining Twitter 515
13.1Introduction 516
13.2Overview of the Twitter APIs 518
13.3Creating a Twitter Account 519
13.4Getting Twitter Credentials—Creating an App 520
13.5What’s in a Tweet 521
13.6Tweepy 525
13.7Authenticating with Twitter Via Tweepy 525
13.8Getting Information About a Twitter Account 527
13.9Introduction to Tweepy Cursors: Getting an Account’s Followers and Friends 529
13.9.1Determining an Account’s Followers 529
13.9.2Determining Whom an Account Follows 532
13.9.3Getting a User’s Recent Tweets 532
13.10Searching Recent Tweets 534
13.11Spotting Trends: Twitter Trends API 536
13.11.1Places with Trending Topics 536
13.11.2Getting a List of Trending Topics 537
13.11.3Create a Word Cloud from Trending Topics 539
13.12Cleaning/Preprocessing Tweets for Analysis 541
13.13Twitter Streaming API 542
13.13.1Creating a Subclass of StreamListener 543
13.13.2Initiating Stream Processing 545
13.14Tweet Sentiment Analysis 547
13.15Geocoding and Mapping 551
13.15.1Getting and Mapping the Tweets 552
13.15.2Utility Functions in tweetutilities.py 556
13.15.3Class LocationListener 558
13.16Ways to Store Tweets 559
13.17Twitter and Time Series 560
13.18Wrap-Up 560
14IBM Watson and Cognitive Computing 565
14.1Introduction: IBM Watson and Cognitive Computing 566
14.2IBM Cloud Account and Cloud Console 568
14.3Watson Services 568
14.4Additional Services and Tools 572
14.5Watson Developer Cloud Python SDK 573
14.6Case Study: Traveler’s Companion Translation App 57
414.6.1Before You Run the App 575
14.6.2Test-Driving the App 576
14.6.3SimpleLanguageTranslator.py Script Walkthrough 577
14.7Watson Resources 587
14.8Wrap-Up 589
15Machine Learning: Classification, Regression and Clustering 593
15.1Introduction to Machine Learning 594
15.1.1Scikit-Learn 595
15.1.2Types of Machine Learning 596
15.1.3Datasets Bundled with Scikit-Learn 598
15.1.4Steps in a Typical Data Science Study 599
15.2Case Study: Classification with k-Nearest Neighbors and the Digits Dataset, Part 1 599
15.2.1k-Nearest Neighbors Algorithm 601
15.2.2Loading the Dataset 602
15.2.3Visualizing the Data 606
15.2.4Splitting the Data for Training and Testing 608
15.2.5Creating the Model 609
15.2.6Training the Model 610
15.2.7Predicting Digit Classes 610
15.3Case Study: Classification with k-Nearest Neighbors and the Digits Dataset, Part 2 612
15.3.1Metrics for Model Accuracy 612
15.3.2K-Fold Cross-Validation 616
15.3.3Running Multiple Models to Find the Best One 617
15.3.4Hyperparameter Tuning 619
15.4Case Study: Time Series and Simple Linear Regression 620
15.5Case Study: Multiple Linear Regression with the California Housing Dataset 625
15.5.1Loading the Dataset 626
15.5.2Exploring the Data with Pandas 628
15.5.3Visualizing the Features 630
15.5.4Splitting the Data for Training and Testing 634
15.5.5Training the Model 634
15.5.6Testing the Model 635
15.5.7Visualizing the Expected vs. Predicted Prices 636
15.5.8Regression Model Metrics 637
15.5.9Choosing the Best Model 638
15.6 Case Study: Unsupervised Machine Learning, Part 1—Dimensionality Reduction639
15.7 Case Study: Unsupervised Machine Learning, Part 2—k-Means Clustering642
15.7.1Loading the Iris Dataset 644
15.7.2Exploring the Iris Dataset: Descriptive Statistics with Pandas 646
15.7.3Visualizing the Dataset with a Seaborn pairplot 647
15.7.4Using a KMeans Estimator 650
15.7.5Dimensionality Reduction with Principal Component Analysis 652
15.7.6Choosing the Best Clustering Estimator 655
15.8Wrap-Up 656
16Deep Learning 665
16.1Introduction 666
16.1.1Deep Learning Applications 668
16.1.2Deep Learning Demos 669
16.1.3Keras Resources 669
16.2Keras Built-In Datasets 669
16.3Custom Anaconda Environments 670
16.4Neural Networks 672
16.5Tensors 674
16.6 Convolutional Neural Networks for Vision; Multi-Classification with the MNIST Dataset676
16.6.1Loading the MNIST Dataset 677
16.6.2Data Exploration 678
16.6.3Data Preparation 680
16.6.4Creating the Neural Network 682
16.6.5Training and Evaluating the Model 691
16.6.6Saving and Loading a Model 696
16.7Visualizing Neural Network Training with TensorBoard 697
16.8ConvnetJS: Browser-Based Deep-Learning Training and Visualization 700
16.9Recurrent Neural Networks for Sequences; Sentiment Analysis with the IMDb Dataset701
16.9.1Loading the IMDb Movie Reviews Dataset 702
16.9.2Data Exploration 703
16.9.3Data Preparation 705
16.9.4Creating the Neural Network 706
16.9.5Training and Evaluating the Model 709
16.10Tuning Deep Learning Models 710
16.11Convnet Models Pretrained on ImageNet 711
16.12Reinforcement Learning 712
16.12.1Deep Q-Learning 713
16.12.2OpenAI Gym 713
16.13Wrap-Up 714
17Big Data: Hadoop, Spark, NoSQL and IoT 723
17.1Introduction 724
17.2Relational Databases and Structured Query Language (SQL) 728
17.2.1A books Database 730
17.2.2SELECT Queries 734
17.2.3WHERE Clause 734
17.2.4ORDER BY Clause 736
17.2.5Merging Data from Multiple Tables: INNER JOIN 737
17.2.6INSERT INTO Statement 738
17.2.7UPDATE Statement 739
17.2.8DELETE FROM Statement 739
17.3NoSQL and NewSQL Big-Data Databases: A Brief Tour 741
17.3.1NoSQL Key–Value Databases 741
17.3.2NoSQL Document Databases 742
17.3.3NoSQL Columnar Databases 742
17.3.4NoSQL Graph Databases 743
17.3.5NewSQL Databases 743
17.4Case Study: A MongoDB JSON Document Database 744
17.4.1Creating the MongoDB Atlas Cluster 745
17.4.2Streaming Tweets into MongoDB 746
17.5Hadoop 75517.5.1Hadoop Overview 755
17.5.2Summarizing Word Lengths in Romeo and Juliet via MapReduce 758
17.5.3Creating an Apache Hadoop Cluster in Microsoft Azure HDInsight 758
17.5.4Hadoop Streaming 760
17.5.5Implementing the Mapper 760
17.5.6Implementing the Reducer 761
17.5.7Preparing to Run the MapReduce Example 762
17.5.8Running the MapReduce Job 763
17.6Spark 766
17.6.1Spark Overview 766
17.6.2Docker and the Jupyter Docker Stacks 767
17.6.3Word Count with Spark 770
17.6.4Spark Word Count on Microsoft Azure 773
17.7 Spark Streaming: Counting Twitter Hashtags Using the pyspark-notebook Docker Stack777
17.7.1Streaming Tweets to a Socket 777
17.7.2Summarizing Tweet Hashtags; Introducing Spark SQL 780
17.8Internet of Things and Dashboards 786
17.8.1Publish and Subscribe 788
17.8.2Visualizing a PubNub Sample Live Stream with a Freeboard Dashboard 788
17.8.3Simulating an Internet-Connected Thermostat in Python 790
17.8.4Creating the Dashboard with Freeboard.io 792
17.8.5Creating a Python PubNub Subscriber 794
17.9Wrap-Up 798


推荐

车牌查询
桂ICP备20004708号-3