liveBook · Manning

Preprocessing

As explained in Grokking Machine Learning

Data preprocessing is the transformation of raw data into a form suitable for computational analysis or model training.

How can raw emails, labels, or images become usable by a model? Preprocessing transforms data into a form computational methods can analyze, such as word lists, categorical labels, or feature vectors. section 8.3 section 10.3

Typical preprocessing steps include:

  • Lowercase email text, split it into words, remove repeated words with a set, and store the result in a new DataFrame column. section 8.3
  • Convert binary class labels such as 0 and 1 into categorical vectors such as [1,0] and [0,1]. section 10.3
  • Reshape rectangular images into long feature vectors and convert digit labels into vectors with one nonzero class entry. section 10.3
  • Clean data, engineer features, and prepare training, validation, and testing sets before model selection and evaluation. section 13.0

Spam detection

An email dataset contains message text and a spam label. Processing each message into unique lowercase words creates features that a naive Bayes model can count by class; a phrase such as “buy cheap lottery easy money now” then receives a high spam probability. section 8.3

def process_email(text):
text = text.lower()
return list(set(text.split()))

Inspect the compact function that lowercases email text, splits it into words, and removes repetition before modeling. section 8.3

How Grokking Machine Learning covers it

How deep it goes
Demonstrates concrete transformations and an end-to-end workflow, while stopping short of exhaustive data-cleaning rules.
Examples
Uses spam emails, circular two-class data, MNIST images, and the Titanic dataset as preprocessing examples.
What it assumes
Assumes familiarity with the dataset and problem, while demonstrating the transformations needed before training.
What you can do after
Apply preprocessing with Pandas and Keras by transforming text, labels, images, and tabular data into model-ready representations.
How it connects
Connects preprocessing with feature engineering, naive Bayes, neural networks, model training, validation, and evaluation.

Also explained in

Compare how 22 books explain preprocessing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.