O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

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. Why Machine Learning?
      1. Problems Machine Learning Can Solve
      2. Knowing Your Task and Knowing Your Data
    2. Why Python?
    3. scikit-learn
      1. Installing scikit-learn
    4. Essential Libraries and Tools
      1. Jupyter Notebook
      2. NumPy
      3. SciPy
      4. matplotlib
      5. pandas
      6. mglearn
    5. Python 2 Versus Python 3
    6. Versions Used in this Book
    7. A First Application: Classifying Iris Species
      1. Meet the Data
      2. Measuring Success: Training and Testing Data
      3. First Things First: Look at Your Data
      4. Building Your First Model: k-Nearest Neighbors
      5. Making Predictions
      6. Evaluating the Model
    8. Summary and Outlook
  3. 2. Supervised Learning
    1. Classification and Regression
    2. Generalization, Overfitting, and Underfitting
      1. Relation of Model Complexity to Dataset Size
    3. Supervised Machine Learning Algorithms
      1. Some Sample Datasets
      2. k-Nearest Neighbors
      3. Linear Models
      4. Naive Bayes Classifiers
      5. Decision Trees
      6. Ensembles of Decision Trees
      7. Kernelized Support Vector Machines
      8. Neural Networks (Deep Learning)
    4. Uncertainty Estimates from Classifiers
      1. The Decision Function
      2. Predicting Probabilities
      3. Uncertainty in Multiclass Classification
    5. Summary and Outlook
  4. 3. Unsupervised Learning and Preprocessing
    1. Types of Unsupervised Learning
    2. Challenges in Unsupervised Learning
    3. Preprocessing and Scaling
      1. Different Kinds of Preprocessing
      2. Applying Data Transformations
      3. Scaling Training and Test Data the Same Way
      4. The Effect of Preprocessing on Supervised Learning
    4. Dimensionality Reduction, Feature Extraction, and Manifold Learning
      1. Principal Component Analysis (PCA)
      2. Non-Negative Matrix Factorization (NMF)
      3. Manifold Learning with t-SNE
    5. Clustering
      1. k-Means Clustering
      2. Agglomerative Clustering
      3. DBSCAN
      4. Comparing and Evaluating Clustering Algorithms
      5. Summary of Clustering Methods
    6. Summary and Outlook
  5. 4. Representing Data and Engineering Features
    1. Categorical Variables
      1. One-Hot-Encoding (Dummy Variables)
      2. Numbers Can Encode Categoricals
    2. Binning, Discretization, Linear Models, and Trees
    3. Interactions and Polynomials
    4. Univariate Nonlinear Transformations
    5. Automatic Feature Selection
      1. Univariate Statistics
      2. Model-Based Feature Selection
      3. Iterative Feature Selection
    6. Utilizing Expert Knowledge
    7. Summary and Outlook
  6. 5. Model Evaluation and Improvement
    1. Cross-Validation
      1. Cross-Validation in scikit-learn
      2. Benefits of Cross-Validation
      3. Stratified k-Fold Cross-Validation and Other Strategies
    2. Grid Search
      1. Simple Grid Search
      2. The Danger of Overfitting the Parameters and the Validation Set
      3. Grid Search with Cross-Validation
    3. Evaluation Metrics and Scoring
      1. Keep the End Goal in Mind
      2. Metrics for Binary Classification
      3. Metrics for Multiclass Classification
      4. Regression Metrics
      5. Using Evaluation Metrics in Model Selection
    4. Summary and Outlook
  7. 6. Algorithm Chains and Pipelines
    1. Parameter Selection with Preprocessing
    2. Building Pipelines
    3. Using Pipelines in Grid Searches
    4. The General Pipeline Interface
      1. Convenient Pipeline Creation with make_pipeline
      2. Accessing Step Attributes
      3. Accessing Attributes in a Pipeline inside GridSearchCV
    5. Grid-Searching Preprocessing Steps and Model Parameters
    6. Grid-Searching Which Model To Use
    7. Summary and Outlook
  8. 7. Working with Text Data
    1. Types of Data Represented as Strings
    2. Example Application: Sentiment Analysis of Movie Reviews
    3. Representing Text Data as a Bag of Words
      1. Applying Bag-of-Words to a Toy Dataset
      2. Bag-of-Words for Movie Reviews
    4. Stopwords
    5. Rescaling the Data with tf–idf
    6. Investigating Model Coefficients
    7. Bag-of-Words with More Than One Word (n-Grams)
    8. Advanced Tokenization, Stemming, and Lemmatization
    9. Topic Modeling and Document Clustering
      1. Latent Dirichlet Allocation
    10. Summary and Outlook
  9. 8. Wrapping Up
    1. Approaching a Machine Learning Problem
      1. Humans in the Loop
    2. From Prototype to Production
    3. Testing Production Systems
    4. Building Your Own Estimator
    5. Where to Go from Here
      1. Theory
      2. Other Machine Learning Frameworks and Packages
      3. Ranking, Recommender Systems, and Other Kinds of Learning
      4. Probabilistic Modeling, Inference, and Probabilistic Programming
      5. Neural Networks
      6. Scaling to Larger Datasets
      7. Honing Your Skills
    6. Conclusion
  10. Index