Feature Binning and Discretization
Chopping a continuous number like age or return into a handful of ranges throws away precision on purpose, and that trade can make a model simpler, more robust, or better matched to how the relationship actually behaves.
Prerequisites: Rank and Quantile Transforms, Categorical Splits in Decision Trees
A continuous feature like "days to earnings" or "trailing 20-day volatility" carries more precision than most models actually need, and sometimes more precision than the relationship it is describing actually supports. Binning deliberately throws that precision away, replacing the exact number with which bucket it falls into — "0–5 days," "6–20 days," "21+ days" — and that loss of information is sometimes exactly the right trade.
The analogy: a thermostat, not a thermometer
A thermometer reports 71.3 degrees; a thermostat only cares whether the room is "cold," "comfortable," or "hot," and it acts identically for every temperature within a band. If the relationship between temperature and comfort really does behave in bands — nobody feels meaningfully different between 70.8 and 71.6 degrees — then the thermostat's coarser view is not a loss of useful information, it is a correct simplification that also happens to be far more robust to a slightly miscalibrated thermometer. Binning is choosing to treat a continuous feature like a thermostat rather than a thermometer, when the underlying relationship justifies it.
Two ways to choose the bin edges
Equal-width binning divides the feature's range into intervals of identical width: if a feature spans 0 to 100 and , the bins are . Simple, but sensitive to outliers — one extreme value can stretch the range so much that most bins end up nearly empty.
Equal-frequency (quantile) binning instead chooses edges so that roughly the same number of observations fall in each bin — the bins are the feature's -quantiles. This is far more robust to skewed distributions and outliers, since every bin is guaranteed to have comparable sample size, which matters directly for how reliably a model can estimate what each bin means.
In plain English: rank every value by where it falls in the feature's overall distribution, then cut that ranked list into equal-sized groups — the bin boundaries adapt automatically to wherever the data is actually dense or sparse.
Worked example 1: equal-width failing on a skewed feature
Take a feature — daily dollar volume traded — ranging from $10,000 to $50,000,000 across a stock universe, heavily right-skewed (most stocks trade under $1,000,000, a few mega-caps trade in the tens of millions). Equal-width binning into 5 bins creates edges roughly every $10,000,000; bin 1 ($0–10M) would contain over 95% of all stocks, and bins 3, 4, 5 would each contain a handful of mega-caps — three of five bins carry almost no information because they are nearly empty. Equal-frequency binning into 5 bins instead puts roughly 20% of stocks in each bin regardless of the dollar scale, so every bin actually distinguishes something.
Worked example 2: binning finds a genuine non-monotonic relationship
Suppose "days since last earnings report" has a genuinely non-monotonic relationship with next-day volatility: volatility is elevated in the 3 days right after an earnings report, drops to baseline for a long middle stretch, then ticks up again just before the next report (anticipation). A linear model fed the raw day-count sees only a single slope and cannot represent that shape at all. Binning into "0–3 days" (post-earnings), "4–55 days" (quiet), "56+ days" (pre-earnings) turns this into three dummy features, and a linear model can now assign each bucket its own independent coefficient — recovering the U-shaped or dip-then-rise pattern the raw number could never express on its own.
Reshape the curve in the explorer above, then imagine slicing the x-axis into a handful of bins: a linear model on the raw x-axis cannot follow this curve, but a linear model on the binned version — one coefficient per bin — can approximate it as a step function, which is precisely what binning buys a model that cannot otherwise represent curvature.
Binning trades continuous precision for the ability to represent non-linear or non-monotonic relationships with a simple linear model, and for robustness to outliers and skew — equal-frequency binning is almost always preferable to equal-width binning on real, skewed financial data.
What this means in practice
Binning matters most for models that cannot represent non-linearity on their own — linear and logistic regression especially — and matters far less for tree-based models, which effectively discover their own data-driven bins at every split. It is also useful purely for robustness: a binned feature is immune to a single extreme outlier distorting a linear coefficient, since the outlier just falls into the top bin along with everything else that large.
The bin edges must be learned only from the training set (or, ideally, only from data available at that point in time) and then applied unchanged to validation and test data — computing quantile edges from the full dataset including future or held-out data is a leakage mistake, since the bin boundaries themselves would then encode information about data the model should not have seen yet.
Related concepts
Practice in interviews
Further reading
- Dougherty, Kohavi & Sahami, Supervised and Unsupervised Discretization of Continuous Features (1995)