Python Machine Learning Cookbook - Second Edition

Book Description

Discover powerful ways to effectively solve real-world machine learning problems using key libraries including scikit-learn, TensorFlow, and PyTorch

Key Features

  • Learn and implement machine learning algorithms in a variety of real-life scenarios
  • Cover a range of tasks catering to supervised, unsupervised and reinforcement learning techniques
  • Find easy-to-follow code solutions for tackling common and not-so-common challenges

Book Description

This eagerly anticipated second edition of the popular Python Machine Learning Cookbook will enable you to adopt a fresh approach to dealing with real-world machine learning and deep learning tasks.

With the help of over 100 recipes, you will learn to build powerful machine learning applications using modern libraries from the Python ecosystem. The book will also guide you on how to implement various machine learning algorithms for classification, clustering, and recommendation engines, using a recipe-based approach. With emphasis on practical solutions, dedicated sections in the book will help you to apply supervised and unsupervised learning techniques to real-world problems. Toward the concluding chapters, you will get to grips with recipes that teach you advanced techniques including reinforcement learning, deep neural networks, and automated machine learning.

By the end of this book, you will be equipped with the skills you need to apply machine learning techniques and leverage the full capabilities of the Python ecosystem through real-world examples.

What you will learn

  • Use predictive modeling and apply it to real-world problems
  • Explore data visualization techniques to interact with your data
  • Learn how to build a recommendation engine
  • Understand how to interact with text data and build models to analyze it
  • Work with speech data and recognize spoken words using Hidden Markov Models
  • Get well versed with reinforcement learning, automated ML, and transfer learning
  • Work with image data and build systems for image recognition and biometric face recognition
  • Use deep neural networks to build an optical character recognition system

Who this book is for

This book is for data scientists, machine learning developers, deep learning enthusiasts and Python programmers who want to solve real-world challenges using machine-learning techniques and algorithms. If you are facing challenges at work and want ready-to-use code solutions to cover key tasks in machine learning and the deep learning domain, then this book is what you need. Familiarity with Python programming and machine learning concepts will be useful.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Python Machine Learning Cookbook Second Edition
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  6. The Realm of Supervised Learning
    1. Technical requirements
    2. Introduction
    3. Array creation in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more...
      5. See also
    4. Data preprocessing using mean removal
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Data scaling
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Normalization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Binarization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. One-hot encoding
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Label encoding
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    10. Building a linear regressor
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    11. Computing regression accuracy
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    12. Achieving model persistence
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    13. Building a ridge regressor
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. See also
    14. Building a polynomial regressor
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    15. Estimating housing prices
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    16. Computing the relative importance of features
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    17. Estimating bicycle demand distribution
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
  7. Constructing a Classifier
    1. Technical requirements
    2. Introduction
    3. Building a simple classifier
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    4. Building a logistic regression classifier
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    5. Building a Naive Bayes classifier
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    6. Splitting a dataset for training and testing
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    7. Evaluating accuracy using cross-validation metrics
      1. Getting ready…
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    8. Visualizing a confusion matrix
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    9. Extracting a performance report
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    10. Evaluating cars based on their characteristics
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    11. Extracting validation curves
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    12. Extracting learning curves
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    13. Estimating the income bracket
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    14. Predicting the quality of wine
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
    15. Newsgroup trending topics classification
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
      5. See also
  8. Predictive Modeling
    1. Technical requirements
    2. Introduction
    3. Building a linear classifier using SVMs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Building a nonlinear classifier using SVMs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Tackling class imbalance
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Extracting confidence measurements
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Finding optimal hyperparameters
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. The grid search algorithm
        2. The randomized search algorithm
        3. The Bayesian optimization algorithm
      4. There's more…
      5. See also
    8. Building an event predictor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Estimating traffic
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Simplifying machine learning workflow using TensorFlow
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    11. Implementing a stacking method
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  9. Clustering with Unsupervised Learning
    1. Technical requirements
    2. Introduction
    3. Clustering data using the k-means algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Compressing an image using vector quantization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Grouping data using agglomerative clustering
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Evaluating the performance of clustering algorithms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Estimating the number of clusters using the DBSCAN algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    8. Finding patterns in stock market data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Building a customer segmentation model
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Using autoencoders to reconstruct handwritten digit images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  10. Visualizing Data
    1. Technical requirements
    2. An introduction to data visualization
    3. Plotting three-dimensional scatter plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Plotting bubble plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Animating bubble plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Drawing pie charts
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Plotting date-formatted time series data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Plotting histograms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Visualizing heat maps
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Animating dynamic signals
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    11. Working with the Seaborn library
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  11. Building Recommendation Engines
    1. Technical requirements
    2. Introducing the recommendation engine
    3. Building function compositions for data processing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Building machine learning pipelines
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Finding the nearest neighbors
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Constructing a k-nearest neighbors classifier
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Constructing a k-nearest neighbors regressor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Computing the Euclidean distance score
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Computing the Pearson correlation score
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Finding similar users in the dataset
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    11. Generating movie recommendations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    12. Implementing ranking algorithms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    13. Building a filtering model using TensorFlow
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  12. Analyzing Text Data
    1. Technical requirements
    2. Introduction
    3. Preprocessing data using tokenization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Stemming text data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Converting text to its base form using lemmatization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Dividing text using chunking
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Building a bag-of-words model
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Building a text classifier
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Identifying the gender of a name
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Analyzing the sentiment of a sentence
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    11. Identifying patterns in text using topic modeling
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    12. Parts of speech tagging with spaCy
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    13. Word2Vec using gensim
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    14. Shallow learning for spam detection
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  13. Speech Recognition
    1. Technical requirements
    2. Introducing speech recognition
    3. Reading and plotting audio data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Transforming audio signals into the frequency domain
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Generating audio signals with custom parameters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Synthesizing music
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Extracting frequency domain features
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Building HMMs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Building a speech recognizer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Building a TTS system
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  14. Dissecting Time Series and Sequential Data
    1. Technical requirements
    2. Introducing time series
    3. Transforming data into a time series format
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Slicing time series data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Operating on time series data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Extracting statistics from time series data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Building HMMs for sequential data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    8. Building CRFs for sequential text data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Analyzing stock market data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Using RNNs to predict time series data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  15. Analyzing Image Content
    1. Technical requirements
    2. Introducing computer vision
    3. Operating on images using OpenCV-Python
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Detecting edges
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Histogram equalization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Detecting corners
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Detecting SIFT feature points
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    8. Building a Star feature detector
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Creating features using Visual Codebook and vector quantization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Training an image classifier using Extremely Random Forests
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    11. Building an object recognizer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    12. Using Light GBM for image classification
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  16. Biometric Face Recognition
    1. Technical requirements
    2. Introduction
    3. Capturing and processing video from a webcam
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Building a face detector using Haar cascades
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Building eye and nose detectors
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Performing principal component analysis
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Performing kernel principal component analysis
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    8. Performing blind source separation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Building a face recognizer using a local binary patterns histogram
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Recognizing faces using the HOG-based model
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    11. Facial landmark recognition
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    12. User authentication by face recognition
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  17. Reinforcement Learning Techniques
    1. Technical requirements
    2. Introduction
    3. Weather forecasting with MDP
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Optimizing a financial portfolio using DP
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Finding the shortest path
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    6. Deciding the discount factor using Q-learning
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    7. Implementing the deep Q-learning algorithm
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    8. Developing an AI-based dynamic modeling system
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    9. Deep reinforcement learning with double Q-learning
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    10. Deep Q-network algorithm with dueling Q-learning
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
  18. Deep Neural Networks
    1. Technical requirements
    2. Introduction
    3. Building a perceptron
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Building a single layer neural network
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Building a deep neural network
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Creating a vector quantizer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Building a recurrent neural network for sequential data analysis
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    8. Visualizing the characters in an OCR database
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Building an optical character recognizer using neural networks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Implementing optimization algorithms in ANN
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  19. Unsupervised Representation Learning
    1. Technical requirements
    2. Introduction
    3. Using denoising autoencoders to detect fraudulent transactions
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    4. Generating word embeddings using CBOW and skipgram representations
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    5. Visualizing the MNIST dataset using PCA and t-SNE
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    6. Using word embedding for Twitter sentiment analysis
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    7. Implementing LDA with scikit-learn
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    8. Using LDA to classify text documents
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    9. Preparing data for LDA
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  20. Automated Machine Learning and Transfer Learning
    1. Technical requirements
    2. Introduction
    3. Working with Auto-WEKA
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Using AutoML to generate machine learning pipelines with TPOT
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Working with Auto-Keras
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Working with auto-sklearn
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    7. Using MLBox for selection and leak detection
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    8. Convolutional neural networks with transfer learning
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    9. Transfer learning with pretrained image classifiers using ResNet-50
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    10. Transfer learning using feature extraction with the VGG16 model
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    11. Transfer learning with pretrained GloVe embedding
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
        1. Inductive transfer learning
        2. Unsupervised transfer learning
        3. Transductive transfer learning
        4. Instance transfer learning
      5. See also
  21. Unlocking Production Issues
    1. Technical requirements
    2. Introduction
    3. Handling unstructured data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    4. Deploying machine learning models
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Keeping track of changes into production
      1. How to do it...
      2. How it works...
      3. There's more…
      4. See also
    6. Tracking accuracy to optimize model scaling
      1. How to do it...
      2. How it works...
      3. There's more…
      4. See also
  22. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Python Machine Learning Cookbook - Second Edition
  • Author(s): Giuseppe Ciaburro, Prateek Joshi
  • Release date: March 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789808452