Table of Contents
Course Module 1: Python Fundamentals
Chapter 1: Introduction and First Steps – Take a Deep Breath 5
A proper introduction 6
Enter the Python 8
About Python 9
Portability 9
Coherence 9
Developer productivity 9
An extensive library 10
Software quality 10
Software integration 10
Satisfaction and enjoyment 10
What are the drawbacks? 11
Who is using Python today? 11
Setting up the environment 11
Python 2 versus Python 3 – the great debate 12
What you need for this course 13
Installing Python 14
Installing IPython 14
Installing additional packages 16
How you can run a Python program 17
Running Python scripts 18
Running the Python interactive shell 18
Running Python as a service 20
Running Python as a GUI application 20
How is Python code organized 21
How do we use modules and packages 22
Table of Contents
[ ii ]
Python's execution model 25
Names and namespaces 25
Scopes 27
Guidelines on how to write good code 30
The Python culture 31
A note on the IDEs 33
Chapter 2: Object-oriented Design 35
Introducing object-oriented 35
Objects and classes 37
Specifying attributes and behaviors 39
Data describes objects 40
Behaviors are actions 41
Hiding details and creating the public interface 43
Composition 45
Inheritance 48
Inheritance provides abstraction 50
Multiple inheritance 51
Case study 52
Chapter 3: Objects in Python 63
Creating Python classes 63
Adding attributes 65
Making it do something 66
Talking to yourself 66
More arguments 67
Initializing the object 69
Explaining yourself 71
Modules and packages 73
Organizing the modules 76
Absolute imports 76
Relative imports 77
Organizing module contents 79
Who can access my data? 82
Third-party libraries 84
Case study 85
Chapter 4: When Objects Are Alike 97
Basic inheritance 97
Extending built-ins 100
Overriding and super 101
Table of Contents
[ iii ]
Multiple inheritance 103
The diamond problem 105
Different sets of arguments 110
Polymorphism 113
Abstract base classes 116
Using an abstract base class 116
Creating an abstract base class 117
Demystifying the magic 119
Case study 120
Chapter 5: Expecting the Unexpected 137
Raising exceptions 138
Raising an exception 139
The effects of an exception 141
Handling exceptions 142
The exception hierarchy 148
Defining our own exceptions 149
Case study 154
Chapter 6: When to Use Object-oriented Programming 167
Treat objects as objects 167
Adding behavior to class data with properties 171
Properties in detail 174
Decorators – another way to create properties 176
Deciding when to use properties 178
Manager objects 180
Removing duplicate code 182
In practice 184
Case study 187
Chapter 7: Python Data Structures 199
Empty objects 199
Tuples and named tuples 201
Named tuples 203
Dictionaries 204
Dictionary use cases 208
Using defaultdict 208
Counter 210
Lists 211
Sorting lists 213
Sets 217
Extending built-ins 221
................
Chapter 8: Predicting Continuous Target Variables with
Regression Analysis 1181
Introducing a simple linear regression model 1182
Exploring the Housing Dataset 1183
Visualizing the important characteristics of a dataset 1184
Implementing an ordinary least squares linear regression model 1189
Solving regression for regression parameters with gradient descent 1189
Estimating the coefficient of a regression model via scikit-learn 1193
Fitting a robust regression model using RANSAC 1195
Evaluating the performance of linear regression models 1198
Using regularized methods for regression 1201
Turning a linear regression model into a curve – polynomial
regression 1203
Modeling nonlinear relationships in the Housing Dataset 1205
Dealing with nonlinear relationships using random forests 1208
Decision tree regression 1209
Random forest regression 1211
Appendix: Reflect and Test Yourself! Answers 1217
Module 2: Data Analysis 1217
Chapter 1: Introducing Data Analysis and Libraries 1217
Table of Contents
[ xviii ]
Chapter 2: Object-oriented Design 1217
Chapter 3: Data Analysis with pandas 1218
Chapter 4: Data Visualization 1218
Chapter 5: Time Series 1218
Chapter 6: Interacting with Databases 1218
Chapter 7: Data Analysis Application Examples 1219
Module 3: Data Mining 1219
Chapter 1: Getting Started with Data Mining 1219
Chapter 2: Classifying with scikit-learn Estimators 1219
Chapter 3: Predicting Sports Winners with Decision Trees 1219
Chapter 4: Recommending Movies Using Affinity Analysis 1220
Chapter 5: Extracting Features with Transformers 1220
Chapter 6: Social Media Insight Using Naive Bayes 1220
Chapter 7: Discovering Accounts to Follow Using Graph Mining 1220
Chapter 8: Beating CAPTCHAs with Neural Networks 1220
Chapter 9: Authorship Attribution 1221
Chapter 10: Clustering News Articles 1221
Chapter 11: Classifying Objects in Images Using Deep Learning 1221
Chapter 12: Working with Big Data 1221
Module 4: Machine Learning 1221
Chapter 1: Giving Computers the Ability to Learn from Data 1221
Chapter 2: Training Machine Learning 1222
Chapter 3: A Tour of Machine Learning Classifiers Using scikit-learn 1222
Chapter 4: Building Good Training Sets – Data Preprocessing 1222
Chapter 5: Compressing Data via Dimensionality Reduction 1222
Chapter 6: Learning Best Practices for Model Evaluation and
Hyperparameter Tuning 1222
Chapter 7: Combining Different Models for Ensemble Learning 1223
Chapter 8: Predicting Continuous Target Variables with
Regression Analysis 1223
Bibliography 1225