Introduction to Machine Learning with Python

Book description

Machine learning has become an integral part of many commercial applications and research projects, but this field is not exclusive to large companies with extensive research teams. If you use Python, even as a beginner, this book will teach you practical ways to build your own machine learning solutions. With all the data available today, machine learning applications are limited only by your imagination.

You’ll learn the steps necessary to create a successful machine-learning application with Python and the scikit-learn library. Authors Andreas Müller and Sarah Guido focus on the practical aspects of using machine learning algorithms, rather than the math behind them. Familiarity with the NumPy and matplotlib libraries will help you get even more from this book.

With this book, you’ll learn:

  • Fundamental concepts and applications of machine learning
  • Advantages and shortcomings of widely used machine learning algorithms
  • How to represent data processed by machine learning, including which data aspects to focus on
  • Advanced methods for model evaluation and parameter tuning
  • The concept of pipelines for chaining models and encapsulating your workflow
  • Methods for working with text data, including text-specific processing techniques
  • Suggestions for improving your machine learning and data science skills

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Read This Book
    2. Why We Wrote This Book
    3. Navigating This Book
    4. Online Resources
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Safari
    8. How to Contact Us
    9. Acknowledgments
      1. From Andreas
      2. From Sarah
  2. 1. Introduction
    1. 1.1. Why Machine Learning?
      1. 1.1.1. Problems Machine Learning Can Solve
      2. 1.1.2. Knowing Your Task and Knowing Your Data
    2. 1.2. Why Python?
    3. 1.3. scikit-learn
      1. 1.3.1. Installing scikit-learn
    4. 1.4. Essential Libraries and Tools
      1. 1.4.1. Jupyter Notebook
      2. 1.4.2. NumPy
      3. 1.4.3. SciPy
      4. 1.4.4. matplotlib
      5. 1.4.5. pandas
      6. 1.4.6. mglearn
    5. 1.5. Python 2 Versus Python 3
    6. 1.6. Versions Used in this Book
    7. 1.7. A First Application: Classifying Iris Species
      1. 1.7.1. Meet the Data
      2. 1.7.2. Measuring Success: Training and Testing Data
      3. 1.7.3. First Things First: Look at Your Data
      4. 1.7.4. Building Your First Model: k-Nearest Neighbors
      5. 1.7.5. Making Predictions
      6. 1.7.6. Evaluating the Model
    8. 1.8. Summary and Outlook
  3. 2. Supervised Learning
    1. 2.1. Classification and Regression
    2. 2.2. Generalization, Overfitting, and Underfitting
      1. 2.2.1. Relation of Model Complexity to Dataset Size
    3. 2.3. Supervised Machine Learning Algorithms
      1. 2.3.1. Some Sample Datasets
      2. 2.3.2. k-Nearest Neighbors
      3. 2.3.3. Linear Models
      4. 2.3.4. Naive Bayes Classifiers
      5. 2.3.5. Decision Trees
      6. 2.3.6. Ensembles of Decision Trees
      7. 2.3.7. Kernelized Support Vector Machines
      8. 2.3.8. Neural Networks (Deep Learning)
    4. 2.4. Uncertainty Estimates from Classifiers
      1. 2.4.1. The Decision Function
      2. 2.4.2. Predicting Probabilities
      3. 2.4.3. Uncertainty in Multiclass Classification
    5. 2.5. Summary and Outlook
  4. 3. Unsupervised Learning and Preprocessing
    1. 3.1. Types of Unsupervised Learning
    2. 3.2. Challenges in Unsupervised Learning
    3. 3.3. Preprocessing and Scaling
      1. 3.3.1. Different Kinds of Preprocessing
      2. 3.3.2. Applying Data Transformations
      3. 3.3.3. Scaling Training and Test Data the Same Way
      4. 3.3.4. The Effect of Preprocessing on Supervised Learning
    4. 3.4. Dimensionality Reduction, Feature Extraction, and Manifold Learning
      1. 3.4.1. Principal Component Analysis (PCA)
      2. 3.4.2. Non-Negative Matrix Factorization (NMF)
      3. 3.4.3. Manifold Learning with t-SNE
    5. 3.5. Clustering
      1. 3.5.1. k-Means Clustering
      2. 3.5.2. Agglomerative Clustering
      3. 3.5.3. DBSCAN
      4. 3.5.4. Comparing and Evaluating Clustering Algorithms
      5. 3.5.5. Summary of Clustering Methods
    6. 3.6. Summary and Outlook
  5. 4. Representing Data and Engineering Features
    1. 4.1. Categorical Variables
      1. 4.1.1. One-Hot-Encoding (Dummy Variables)
      2. 4.1.2. Numbers Can Encode Categoricals
    2. 4.2. OneHotEncoder and ColumnTransformer: Categorical Variables with scikit-learn
    3. 4.3. Convenient ColumnTransformer creation with make_columntransformer
    4. 4.4. Binning, Discretization, Linear Models, and Trees
    5. 4.5. Interactions and Polynomials
    6. 4.6. Univariate Nonlinear Transformations
    7. 4.7. Automatic Feature Selection
      1. 4.7.1. Univariate Statistics
      2. 4.7.2. Model-Based Feature Selection
      3. 4.7.3. Iterative Feature Selection
    8. 4.8. Utilizing Expert Knowledge
    9. 4.9. Summary and Outlook
  6. 5. Model Evaluation and Improvement
    1. 5.1. Cross-Validation
      1. 5.1.1. Cross-Validation in scikit-learn
      2. 5.1.2. Benefits of Cross-Validation
      3. 5.1.3. Stratified k-Fold Cross-Validation and Other Strategies
    2. 5.2. Grid Search
      1. 5.2.1. Simple Grid Search
      2. 5.2.2. The Danger of Overfitting the Parameters and the Validation Set
      3. 5.2.3. Grid Search with Cross-Validation
    3. 5.3. Evaluation Metrics and Scoring
      1. 5.3.1. Keep the End Goal in Mind
      2. 5.3.2. Metrics for Binary Classification
      3. 5.3.3. Metrics for Multiclass Classification
      4. 5.3.4. Regression Metrics
      5. 5.3.5. Using Evaluation Metrics in Model Selection
    4. 5.4. Summary and Outlook
  7. 6. Algorithm Chains and Pipelines
    1. 6.1. Parameter Selection with Preprocessing
    2. 6.2. Building Pipelines
    3. 6.3. Using Pipelines in Grid Searches
    4. 6.4. The General Pipeline Interface
      1. 6.4.1. Convenient Pipeline Creation with make_pipeline
      2. 6.4.2. Accessing Step Attributes
      3. 6.4.3. Accessing Attributes in a Pipeline inside GridSearchCV
    5. 6.5. Grid-Searching Preprocessing Steps and Model Parameters
    6. 6.6. Grid-Searching Which Model To Use
      1. 6.6.1. Avoiding Redundant Computation
    7. 6.7. Summary and Outlook
  8. 7. Working with Text Data
    1. 7.1. Types of Data Represented as Strings
    2. 7.2. Example Application: Sentiment Analysis of Movie Reviews
    3. 7.3. Representing Text Data as a Bag of Words
      1. 7.3.1. Applying Bag-of-Words to a Toy Dataset
      2. 7.3.2. Bag-of-Words for Movie Reviews
    4. 7.4. Stopwords
    5. 7.5. Rescaling the Data with tf–idf
    6. 7.6. Investigating Model Coefficients
    7. 7.7. Bag-of-Words with More Than One Word (n-Grams)
    8. 7.8. Advanced Tokenization, Stemming, and Lemmatization
    9. 7.9. Topic Modeling and Document Clustering
      1. 7.9.1. Latent Dirichlet Allocation
    10. 7.10. Summary and Outlook
  9. 8. Wrapping Up
    1. 8.1. Approaching a Machine Learning Problem
      1. 8.1.1. Humans in the Loop
    2. 8.2. From Prototype to Production
    3. 8.3. Testing Production Systems
    4. 8.4. Building Your Own Estimator
    5. 8.5. Where to Go from Here
      1. 8.5.1. Theory
      2. 8.5.2. Other Machine Learning Frameworks and Packages
      3. 8.5.3. Ranking, Recommender Systems, and Other Kinds of Learning
      4. 8.5.4. Probabilistic Modeling, Inference, and Probabilistic Programming
      5. 8.5.5. Neural Networks
      6. 8.5.6. Scaling to Larger Datasets
      7. 8.5.7. Honing Your Skills
    6. 8.6. Conclusion
  10. Index

Product information

  • Title: Introduction to Machine Learning with Python
  • Author(s): Andreas C. Müller, Sarah Guido
  • Release date: September 2016
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449369897