Home Knowledge Base Binning (Discretization)

Binning (Discretization) is a feature engineering technique that converts continuous variables into categorical "buckets" — transforming exact values like Age=27 into ranges like "18-35", which helps linear models capture non-linear relationships (a linear model can't natively learn "young and old are high risk, middle-aged is low risk" but can learn different weights per age bin), reduces the impact of outliers (age 150 just goes into the "60+" bucket), and can improve model interpretability by expressing features in terms that domain experts understand.

What Is Binning?

Binning Strategies

StrategyMethodBin Example (Age)Use Case
Equal WidthSame range per bin0-25, 25-50, 50-75, 75-100Simple, uniform distribution assumed
Equal Frequency (Quantile)Same count per binEach bin has ~1000 peopleSkewed distributions
Domain KnowledgeExpert-defined thresholds0-17 (minor), 18-64 (adult), 65+ (senior)When business rules matter
Decision Tree SplitsUse tree to find optimal thresholdsSplit at 35 and 58 (maximizes prediction)Data-driven optimal bins
K-MeansCluster values into K groupsCenters at 22, 38, 55, 72Natural groupings in the data

Binning Example: Credit Risk

AgeBinDefault RateInterpretation
18-25Young15%Higher risk — less financial history
26-35Early Career8%Moderate risk
36-50Established4%Low risk — stable income
51-65Pre-Retirement5%Low risk
65+Retirement12%Higher risk — fixed income

A linear model with the raw Age feature can only learn "older = more/less risk" (monotonic). With bins, it learns the U-shaped relationship: young and old are higher risk.

Python Implementation

import pandas as pd

# Equal-width bins
df['age_bin'] = pd.cut(df['age'], bins=[0, 25, 35, 50, 65, 100],
                        labels=['Young', 'Early', 'Mid', 'Senior', 'Elder'])

# Quantile bins (equal frequency)
df['income_bin'] = pd.qcut(df['income'], q=5, labels=['Q1','Q2','Q3','Q4','Q5'])

When to Bin vs Not

BinDon't Bin
Linear models with non-linear relationshipsTree-based models (they find optimal splits already)
Noisy measurements where bins are more reliableWhen exact values matter (temperature in physics)
Domain requires categories (age groups, income brackets)When you have enough data for the model to learn non-linearities
Outlier mitigationWhen precision loss is unacceptable

Binning is the feature engineering technique that bridges continuous and categorical thinking — enabling linear models to capture non-linear patterns, reducing outlier impact, and expressing features in domain-meaningful categories, with the trade-off that information is lost whenever exact values are collapsed into ranges.

binningdiscretizebucket

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.