Feature Engineering for Machine Learning

Book description

Feature engineering is a crucial step in the machine-learning pipeline, yet this topic is rarely examined on its own. With this practical book, you’ll learn techniques for extracting and transforming features—the numeric representations of raw data—into formats for machine-learning models. Each chapter guides you through a single data problem, such as how to represent text or image data. Together, these examples illustrate the main principles of feature engineering.

Rather than simply teach these principles, authors Alice Zheng and Amanda Casari focus on practical application with exercises throughout the book. The closing chapter brings everything together by tackling a real-world, structured dataset with several feature-engineering techniques. Python packages including numpy, Pandas, Scikit-learn, and Matplotlib are used in code examples.

You’ll examine:

  • Feature engineering for numeric data: filtering, binning, scaling, log transforms, and power transforms
  • Natural text techniques: bag-of-words, n-grams, and phrase detection
  • Frequency-based filtering and feature scaling for eliminating uninformative features
  • Encoding techniques of categorical variables, including feature hashing and bin-counting
  • Model-based feature engineering with principal component analysis
  • The concept of model stacking, using k-means as a featurization technique
  • Image feature extraction with manual and deep-learning techniques

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Introduction
    2. Conventions Used in This Book
    3. Using Code Examples
    4. O’Reilly Safari
    5. How to Contact Us
    6. Acknowledgments
      1. Special Thanks from Alice
      2. Special Thanks from Amanda
  2. 1. The Machine Learning Pipeline
    1. Data
    2. Tasks
    3. Models
    4. Features
    5. Model Evaluation
  3. 2. Fancy Tricks with Simple Numbers
    1. Scalars, Vectors, and Spaces
    2. Dealing with Counts
      1. Binarization
      2. Quantization or Binning
    3. Log Transformation
      1. Log Transform in Action
      2. Power Transforms: Generalization of the Log Transform
    4. Feature Scaling or Normalization
      1. Min-Max Scaling
      2. Standardization (Variance Scaling)
      3. ℓ2 Normalization
    5. Interaction Features
    6. Feature Selection
    7. Summary
    8. Bibliography
  4. 3. Text Data: Flattening, Filtering, and Chunking
    1. Bag-of-X: Turning Natural Text into Flat Vectors
      1. Bag-of-Words
      2. Bag-of-n-Grams
    2. Filtering for Cleaner Features
      1. Stopwords
      2. Frequency-Based Filtering
      3. Stemming
    3. Atoms of Meaning: From Words to n-Grams to Phrases
      1. Parsing and Tokenization
      2. Collocation Extraction for Phrase Detection
    4. Summary
    5. Bibliography
  5. 4. The Effects of Feature Scaling: From Bag-of-Words to Tf-Idf
    1. Tf-Idf : A Simple Twist on Bag-of-Words
    2. Putting It to the Test
      1. Creating a Classification Dataset
      2. Scaling Bag-of-Words with Tf-Idf Transformation
      3. Classification with Logistic Regression
      4. Tuning Logistic Regression with Regularization
    3. Deep Dive: What Is Happening?
    4. Summary
    5. Bibliography
  6. 5. Categorical Variables: Counting Eggs in the Age of Robotic Chickens
    1. Encoding Categorical Variables
      1. One-Hot Encoding
      2. Dummy Coding
      3. Effect Coding
      4. Pros and Cons of Categorical Variable Encodings
    2. Dealing with Large Categorical Variables
      1. Feature Hashing
      2. Bin Counting
    3. Summary
    4. Bibliography
  7. 6. Dimensionality Reduction: Squashing the Data Pancake with PCA
    1. Intuition
    2. Derivation
      1. Linear Projection
      2. Variance and Empirical Variance
      3. Principal Components: First Formulation
      4. Principal Components: Matrix-Vector Formulation
      5. General Solution of the Principal Components
      6. Transforming Features
      7. Implementing PCA
    3. PCA in Action
    4. Whitening and ZCA
    5. Considerations and Limitations of PCA
    6. Use Cases
    7. Summary
    8. Bibliography
  8. 7. Nonlinear Featurization via K-Means Model Stacking
    1. k-Means Clustering
    2. Clustering as Surface Tiling
    3. k-Means Featurization for Classification
      1. Alternative Dense Featurization
    4. Pros, Cons, and Gotchas
    5. Summary
    6. Bibliography
  9. 8. Automating the Featurizer: Image Feature Extraction and Deep Learning
    1. The Simplest Image Features (and Why They Don’t Work)
    2. Manual Feature Extraction: SIFT and HOG
      1. Image Gradients
      2. Gradient Orientation Histograms
      3. SIFT Architecture
    3. Learning Image Features with Deep Neural Networks
      1. Fully Connected Layers
      2. Convolutional Layers
      3. Rectified Linear Unit (ReLU) Transformation
      4. Response Normalization Layers
      5. Pooling Layers
      6. Structure of AlexNet
    4. Summary
    5. Bibliography
  10. 9. Back to the Feature: Building an Academic Paper Recommender
    1. Item-Based Collaborative Filtering
    2. First Pass: Data Import, Cleaning, and Feature Parsing
      1. Academic Paper Recommender: Naive Approach
    3. Second Pass: More Engineering and a Smarter Model
      1. Academic Paper Recommender: Take 2
    4. Third Pass: More Features = More Information
      1. Academic Paper Recommender: Take 3
    5. Summary
    6. Bibliography
  11. A. Linear Modeling and Linear Algebra Basics
    1. Overview of Linear Classification
    2. The Anatomy of a Matrix
      1. From Vectors to Subspaces
      2. Singular Value Decomposition (SVD)
      3. The Four Fundamental Subspaces of the Data Matrix
    3. Solving a Linear System
    4. Bibliography
  12. Index

Product information

  • Title: Feature Engineering for Machine Learning
  • Author(s): Alice Zheng, Amanda Casari
  • Release date: April 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491953242