liveBook · Manning

Discretization

As explained in Grokking Machine Learning

Binning is a technique that partitions numerical values into intervals or buckets so they can be represented as categorical groups.

Binning turns a numerical feature into categories by splitting its values into intervals. For example, passenger ages can be grouped into decade-wide buckets, giving a model room to learn that survival may vary across age groups rather than follow one simple trend. section 13.3

bins = [0, 10, 20, 30, 40, 50, 60, 70, 80]
categorized_age = pandas.cut(preprocessed_data['Age'], bins)
preprocessed_data['Categorized_age'] = categorized_age
preprocessed_data = preprocessed_data.drop(["Age"], axis=1)

The Pandas example creates decade-wide age intervals, adds them as a feature, and removes the original age column. section 13.3

How Grokking Machine Learning covers it

How deep it goes
Defines binning as splitting values into buckets and demonstrates Pandas interval creation, without evaluating bin choices.
Examples
Uses Titanic passenger ages and decade-wide intervals from 0 to 80 as the concrete example.
What it assumes
Defines numerical and categorical features before applying bins to an age column.
What you can do after
Apply it via Pandas `cut` to replace passenger ages with decade-based categorical intervals.
How it connects
Connects feature engineering with numerical features, categorical features, and machine learning models.

Also explained in

Compare how 5 books explain discretization →

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.