Wednesday, March 18, 2026

Two-Stage Hurdle Fashions: Predicting Zero-Inflated Outcomes


Introduction

, we repeatedly encounter prediction issues the place the result has an uncommon distribution: a big mass of zeros mixed with a steady or depend distribution for constructive values. When you’ve labored in any customer-facing area, you’ve virtually actually run into this. Take into consideration predicting buyer spending. In any given week, the overwhelming majority of customers in your platform don’t buy something in any respect, however the ones who do may spend anyplace from $5 to $5,000. Insurance coverage claims observe an analogous sample: most policyholders don’t file something in a given quarter, however the claims that do are available range enormously in dimension. You see the identical construction in mortgage prepayments, worker turnover timing, advert click on income, and numerous different enterprise outcomes.

The intuition for many groups is to succeed in for the standard regression mannequin and attempt to make it work. I’ve seen this play out a number of instances. Somebody matches an OLS mannequin, will get damaging predictions for half the shopper base, provides a flooring at zero, and calls it a day. Or they fight a log-transform, run into the $log(0)$ downside, tack on a $+1$ offset, and hope for the very best. These workarounds may work, however they gloss over a basic situation: the zeros and the constructive values in your knowledge are sometimes generated by fully completely different processes. A buyer who won’t ever purchase your product is basically completely different from a buyer who buys sometimes however occurred to not this week. Treating them the identical means in a single mannequin forces the algorithm to compromise on each teams, and it often does a poor job on every.

The two-stage hurdle mannequin gives a extra principled resolution by decomposing the issue into two distinct questions.
First, will the result be zero or constructive?
And second, on condition that it’s constructive, what is going to the worth be?
By separating the “if” from the “how a lot,” we will use the proper instruments on every sub-problem independently with completely different algorithms, completely different options, and completely different assumptions, then mix the outcomes right into a single prediction.

On this article, I’ll stroll by way of the speculation behind hurdle fashions, present a working Python implementation, and talk about the sensible concerns that matter when deploying these fashions in manufacturing.
readers who’re already aware of the motivation can skip straight to the implementation part.

The Drawback with Normal Approaches

Why Not Simply Use Linear Regression? To make this concrete, think about predicting buyer spend.
If 80% of consumers spend zero and the remaining 20% spend between 10 and 1000 {dollars}, a linear regression mannequin instantly runs into bother.
The mannequin can (and can) predict damaging spend for some clients, which is nonsensical since you possibly can’t spend damaging {dollars}.
It is going to additionally battle on the boundary: the large spike at zero pulls the regression line down, inflicting the mannequin to underpredict zeros and overpredict small constructive values concurrently.
The variance construction can be fallacious.
Clients who spend nothing have zero variance by definition, whereas clients who do spend have excessive variance.
Whereas you should utilize heteroskedasticity-robust commonplace errors to get legitimate inference regardless of non-constant variance, that solely fixes the usual errors and doesn’t repair the predictions themselves.
The fitted values are nonetheless coming from a linear mannequin that’s attempting to common over a spike at zero and a right-skewed constructive distribution, which is a poor match no matter the way you compute the boldness intervals.

Why Not Log-Remodel? The subsequent factor most individuals attempt is a log-transform: $log(y + 1)$ or $log(y + epsilon)$.
This compresses the proper tail and makes the constructive values look extra regular, nevertheless it introduces its personal set of issues.
The selection of offset ($1$ or $epsilon$) is bigoted, and your predictions will change relying on what you decide.
If you back-transform through $exp(hat{y}) – 1$, you introduce a scientific bias resulting from Jensen’s inequality, for the reason that anticipated worth of the exponentiated prediction is just not the identical because the exponentiation of the anticipated prediction.
Extra basically, the mannequin nonetheless doesn’t distinguish between a buyer who by no means spends and one who generally spends however occurred to be zero this era.
Each get mapped to $log(0 + 1) = 0$, and the mannequin treats them identically although they characterize very completely different buyer behaviors.

What This Means for Forecasting. The deeper situation with forcing a single mannequin onto zero-inflated knowledge goes past poor level estimates.
If you ask one mannequin to explain two basically completely different behaviors (not partaking in any respect vs. partaking at various intensities), you find yourself with a mannequin that conflates the drivers of every.
The options that predict whether or not a buyer will buy in any respect are sometimes fairly completely different from the options that predict how a lot they’ll spend given a purchase order.
Recency and engagement frequency may dominate the “will they purchase” query, whereas revenue and product class preferences matter extra for the “how a lot” query.
A single regression mixes these alerts collectively, making it troublesome to disentangle what’s truly driving the forecast.

This additionally has sensible implications for a way you act on the mannequin.
In case your forecast is low for a specific buyer, is it as a result of they’re unlikely to buy, or as a result of they’re prone to buy however at a small quantity?
The optimum enterprise response to every state of affairs is completely different.
You may ship a re-engagement marketing campaign for the primary case and an upsell supply for the second.
A single mannequin offers you one quantity, however there isn’t a technique to inform which lever to drag.

The Two-Stage Hurdle Mannequin

Conceptual Framework. The core concept behind hurdle fashions is surprisingly intuitive.
Zeros and positives typically come up from completely different data-generating processes, so we should always mannequin them individually.
Consider it as two sequential questions your mannequin must reply.
First, does this buyer cross the “hurdle” and have interaction in any respect?
And second, on condition that they’ve engaged, how a lot do they spend?
Formally, we will write the distribution of the result $Y$ conditional on options $X$ as:

$$ P(Y = y | X) = start{instances} 1 – pi(X) & textual content{if } y = 0 pi(X) cdot f(y | X, y > 0) & textual content{if } y > 0 finish{instances} $$

Right here, $pi(X)$ is the chance of crossing the hurdle (having a constructive end result), and $f(y | X, y > 0)$ is the conditional distribution of $y$ on condition that it’s constructive.
The great thing about this formulation is that these two parts might be modeled independently.
You should utilize a gradient boosting classifier for the primary stage and a gamma regression for the second, or logistic regression paired with a neural community, or some other mixture that fits your knowledge.
Every stage will get its personal function set, its personal hyperparameters, and its personal analysis metrics.
This modularity is what makes hurdle fashions so sensible in manufacturing settings.

Stage 1: The Classification Mannequin. The primary stage is a simple binary classification downside: predict whether or not $y > 0$.
You’re coaching on the complete dataset, with each remark labeled as both zero or constructive.
It is a downside that the ML group has many years of tooling for.
Logistic regression offers you an interpretable and quick baseline.
Gradient boosting strategies like XGBoost or LightGBM deal with non-linearities and have interactions effectively.
Neural networks work when you’ve got high-dimensional or unstructured options.
The output from this stage is $hat{pi}(X) = P(Y > 0 | X)$, a calibrated chance that the result will probably be constructive.

The vital factor to get proper right here is calibration.
Since we’re going to multiply this chance by the conditional quantity within the subsequent stage, we want $hat{pi}(X)$ to be a real chance, not only a rating that ranks effectively.
In case your classifier outputs chances which are systematically too excessive or too low, the mixed prediction will inherit that bias.
Platt scaling might help in case your base classifier isn’t well-calibrated out of the field.

Stage 2: The Conditional Regression Mannequin. The second stage predicts the worth of $y$ conditional on $y > 0$.
That is the place the hurdle mannequin shines in comparison with commonplace approaches since you’re coaching a regression mannequin solely on the constructive subset of your knowledge, so the mannequin by no means has to cope with the spike at zero.
This implies you should utilize the complete vary of regression methods with out worrying about how they deal with zeros.

The selection of mannequin for this stage relies upon closely on the form of your constructive outcomes.
If $log(y | y > 0)$ is roughly regular, you should utilize OLS on the log-transformed goal (with applicable bias correction on back-transformation, which we’ll cowl beneath).
For right-skewed constructive steady outcomes, a GLM with a gamma household is a pure alternative.
When you’re coping with overdispersed depend knowledge, damaging binomial regression works effectively.
A simple technique is simply to make use of Autogluon because the ensemble mannequin and never have to fret concerning the distribution of your knowledge.
The output is $hat{mu}(X) = E[Y | X, Y > 0]$, the anticipated worth conditional on the result being constructive.

Mixed Prediction. The ultimate prediction combines each levels multiplicatively:

$$ hat{E}[Y | X] = hat{pi}(X) cdot hat{mu}(X) $$

This offers the unconditional anticipated worth of $Y$, accounting for each the chance that the result is constructive and the anticipated magnitude given positivity.
If a buyer has a 30% likelihood of buying and their anticipated spend given a purchase order is 100 {dollars}, then their unconditional anticipated spend is 30 {dollars}.
This decomposition additionally makes enterprise interpretation simple.
You possibly can individually get hold of function significance on each the chance of engagement versus what drives the depth of engagement to see what must be addressed.

Implementation

Coaching Pipeline. The coaching pipeline is easy.
We practice Stage 1 on the complete dataset with a binary goal, then practice Stage 2 on solely the constructive observations with the unique steady goal.
At prediction time, we get a chance from Stage 1 and a conditional imply from Stage 2, then multiply them collectively.

We are able to implement this in Python utilizing scikit-learn as a place to begin.
The next class wraps each levels right into a single estimator that follows the scikit-learn API, making it simple to drop into present pipelines and use with instruments like cross-validation and grid search.

import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.base import BaseEstimator, RegressorMixin

class HurdleModel(BaseEstimator, RegressorMixin):
    """
    Two-stage hurdle mannequin for zero-inflated steady outcomes.

    Stage 1: Binary classifier for P(Y > 0)
    Stage 2: Regressor for E[Y | Y > 0]
    """

    def __init__(self, classifier=None, regressor=None):
        self.classifier = classifier or LogisticRegression()
        self.regressor = regressor or GradientBoostingRegressor()

    def match(self, X, y):
        # Stage 1: Practice classifier on all knowledge
        y_binary = (y > 0).astype(int)
        self.classifier.match(X, y_binary)

        # Stage 2: Practice regressor on constructive outcomes solely
        positive_mask = y > 0
        if positive_mask.sum() > 0:
            X_positive = X[positive_mask]
            y_positive = y[positive_mask]
            self.regressor.match(X_positive, y_positive)

        return self

    def predict(self, X):
        # P(Y > 0)
        prob_positive = self.classifier.predict_proba(X)[:, 1]

        # E[Y | Y > 0]
        conditional_mean = self.regressor.predict(X)

        # E[Y] = P(Y > 0) * E[Y | Y > 0]
        return prob_positive * conditional_mean

    def predict_proba_positive(self, X):
        """Return chance of constructive end result."""
        return self.classifier.predict_proba(X)[:, 1]

    def predict_conditional(self, X):
        """Return anticipated worth given constructive end result."""
        return self.regressor.predict(X)

Sensible Issues

Function Engineering. One of many good properties of this framework is that the 2 levels can use completely completely different function units.
In my expertise, the options that predict whether or not somebody engages in any respect are sometimes fairly completely different from the options that predict how a lot they interact.
For Stage 1, behavioral alerts are inclined to dominate: previous exercise, recency, frequency, whether or not the shopper has ever bought earlier than.
Demographic indicators and contextual components like time of yr or day of week additionally assist separate the “will interact” group from the “gained’t interact” group.
For Stage 2, depth alerts matter extra: historic buy quantities, spending velocity, capability indicators like revenue or credit score restrict, and product or class preferences.
These options assist distinguish the 50 greenback spender from the five hundred greenback spender, conditional on each of them making a purchase order.
Moreover, we will use function boosting by feeding within the output of the stage 1 mannequin into the stage 2 mannequin as an extra function.
This permits the stage 2 mannequin to find out how the chance of engagement interacts with the depth alerts, which improves efficiency.

Dealing with Class Imbalance. If zeros dominate your dataset, say 95% of observations are zero, then Stage 1 faces a category imbalance downside.
That is widespread in purposes like advert clicks or insurance coverage claims.
The usual toolkit applies right here: you possibly can tune the classification threshold to optimize to your particular enterprise goal fairly than utilizing the default 0.5 cutoff, upweight the minority class throughout coaching by way of pattern weights, or apply undersampling to resolve this.
The hot button is to consider carefully about what you’re optimizing for.
In lots of enterprise settings, you care extra about precision on the high of the ranked record than you do about total accuracy, and tuning your threshold accordingly could make an enormous distinction.

Mannequin Calibration. For the reason that mixed prediction $hat{pi}(X) cdot hat{mu}(X)$ is a product of two fashions, each should be well-calibrated for the ultimate output to be dependable.
If Stage 1’s chances are systematically inflated by 10%, your mixed predictions will probably be inflated by 10% throughout the board, no matter how good Stage 2 is.
For Stage 1, examine calibration curves and apply Platt scaling if the uncooked chances are off.
For Stage 2, confirm that the predictions are unbiased on the constructive subset, that means the imply of your predictions ought to roughly match the imply of the actuals when evaluated on holdout knowledge the place $y > 0$.
I’ve discovered that calibration points in Stage 1 are the extra widespread supply of issues in follow, particularly when extending the classifier to a discrete-time hazard mannequin.

Analysis Metrics. Evaluating a two-stage mannequin requires fascinated about every stage individually after which trying on the mixed output.
For Stage 1, commonplace classification metrics apply: AUC-ROC and AUC-PR for rating high quality, precision and recall at your chosen threshold for operational efficiency, and the Brier rating for calibration.
For Stage 2, you need to consider solely on the constructive subset since that’s what the mannequin was skilled on.
RMSE and MAE offer you a way of absolute error, MAPE tells you about proportion errors (which issues when your outcomes span a number of orders of magnitude), and quantile protection tells you whether or not your prediction intervals are sincere.

For the mixed mannequin, have a look at total RMSE and MAE on the complete take a look at set, but additionally break it down by whether or not the true end result was zero or constructive.
A mannequin that appears nice on mixture is perhaps horrible at one finish of the distribution.
Carry charts by predicted decile are additionally helpful for speaking mannequin efficiency to stakeholders who don’t suppose when it comes to RMSE.

When to Use Hurdle vs. Zero-Inflated Fashions. It is a distinction value getting proper, as a result of hurdle fashions and zero-inflated fashions (like ZIP or ZINB) make completely different assumptions about the place the zeros come from.
Hurdle fashions assume that each one zeros come up from a single course of, the “non-participation” course of.
When you cross the hurdle, you’re within the constructive regime, and the zeros are totally defined by Stage 1.
Zero-inflated fashions, then again, assume that zeros can come from two sources: some are “structural” zeros (clients who may by no means be constructive, like somebody who doesn’t personal a automobile being requested about auto insurance coverage claims), and others are “sampling” zeros (clients who may have been constructive however simply weren’t this time).

To make this concrete with a retail instance: a hurdle mannequin says a buyer both decides to buy or doesn’t, and in the event that they store, they spend some constructive quantity.
A zero-inflated mannequin says some clients by no means store at this retailer (structural zeros), whereas others do store right here sometimes however simply didn’t at this time (sampling zeros).
In case your zeros genuinely come from two distinct populations, a zero-inflated mannequin is extra applicable.
However in lots of sensible settings, the hurdle framing is each easier and ample, and I’d suggest beginning there except you’ve got a transparent cause to imagine in two forms of zeros.

Extensions and Variations

Multi-Class Hurdle. Generally the binary break up between zero and constructive isn’t granular sufficient.
In case your end result has a number of significant states (say none, small, and huge), you possibly can prolong the hurdle framework right into a multi-class model.
The primary stage turns into a multinomial classifier that assigns every remark to one among $Ok$ buckets, after which separate regression fashions deal with every bucket’s conditional distribution.
Formally, this appears to be like like:

$$ P(Y) = start{instances} pi_0 & textual content{if } Y = 0 pi_1 cdot f_{textual content{small}}(Y) & textual content{if } 0 < Y leq tau pi_2 cdot f_{textual content{giant}}(Y) & textual content{if } Y > tau finish{instances} $$

That is significantly helpful when the constructive outcomes themselves have distinct sub-populations.
For example, in modeling insurance coverage claims, there’s typically a transparent separation between small routine claims and huge catastrophic ones, and attempting to suit a single distribution to each results in poor tail estimates.
The brink $tau$ might be set based mostly on area information or estimated from the info utilizing combination mannequin methods.

Generalizing the Levels. One factor value emphasizing is that neither stage must be a selected kind of mannequin.
All through this text, I’ve introduced Stage 1 as a binary classifier, however that’s simply the only model.
If the timing of the occasion issues, you would change Stage 1 with a discrete-choice survival mannequin that predicts not simply whether or not a buyer will buy, however when.
That is particularly helpful for subscription or retention contexts the place the “hurdle” has a temporal dimension.
Equally, Stage 2 doesn’t should be a single hand-tuned regression.
You may use an AutoML framework like AutoGluon to ensemble over a big set of candidate fashions (gradient boosting, neural networks, linear fashions) and let it discover the very best mixture for predicting the conditional quantity.
The hurdle framework is agnostic to what sits inside every stage, so you need to be at liberty to swap in no matter modeling strategy most closely fits your knowledge and use case.


Widespread Pitfalls

These are errors I’ve both made myself or seen others make when deploying hurdle fashions.
None of them are apparent till you’ve been bitten, in order that they’re value studying by way of even if you happen to’re already comfy with the framework.

1. Leaking Stage 2 Data into Stage 1. When you engineer options from the goal, one thing like “common historic spend” or “complete lifetime worth,” you’ll want to watch out about how that info flows into every stage.
A function that summarizes previous spend implicitly accommodates details about whether or not the shopper has ever spent something, which suggests Stage 1 is perhaps getting a free sign that wouldn’t be obtainable at prediction time for brand spanking new clients.
The repair is to consider carefully concerning the temporal construction of your options and ensure each levels solely see info that might be obtainable on the time of prediction.

2. Ignoring the Conditional Nature of Stage 2. This one is refined however vital.
Stage 2 is skilled solely on observations the place $y > 0$, so it must be evaluated solely on that subset too.
I’ve seen folks compute RMSE throughout the complete take a look at set (together with zeros) and conclude that Stage 2 is horrible.
So if you’re reporting metrics for Stage 2, all the time filter to the constructive subset first.
Equally, when diagnosing points with the mixed mannequin, ensure you decompose the error into its Stage 1 and Stage 2 parts.
A excessive total error is perhaps pushed completely by poor classification in Stage 1, even when Stage 2 is doing wonderful on the constructive observations.

4. Misaligned Practice/Take a look at Splits. Each levels want to make use of the identical practice/take a look at splits.
This sounds apparent, nevertheless it’s simple to mess up in follow, particularly if you happen to’re coaching the 2 levels in separate notebooks or pipelines.
If Stage 1 sees a buyer in coaching however Stage 2 sees the identical buyer in its take a look at set (since you re-split the positive-only knowledge independently), you’ve launched knowledge leakage.
The best repair is to do your practice/take a look at break up as soon as firstly on the complete dataset, after which derive the Stage 2 coaching knowledge by filtering the coaching fold to constructive observations.
When you’re doing cross-validation, the fold assignments have to be constant throughout each levels.

5.
Assuming Independence Between Levels.
Whereas we mannequin the 2 levels individually, the underlying options and outcomes are sometimes correlated in ways in which matter.
Clients with excessive $hat{pi}(X)$ (prone to interact) typically even have excessive $hat{mu}(X)$ (seemingly to spend so much after they do).
This implies the multiplicative mixture $hat{pi}(X) cdot hat{mu}(X)$ can amplify errors in methods you wouldn’t see if the levels had been actually unbiased.
Maintain this in thoughts when deciphering function significance.
A function that exhibits up as vital in each levels is doing double obligation, and its complete contribution to the mixed prediction is bigger than both stage’s significance rating suggests.

Remaining Remarks

Alternate Makes use of: Past the examples lined on this article, hurdle fashions present up in a shocking number of enterprise contexts.
In advertising, they’re a pure match for modeling buyer lifetime worth, the place many purchasers churn earlier than making a second buy, making a mass of zeros, whereas retained clients generate broadly various quantities of income.
In healthcare analytics, affected person value modeling follows the identical sample: most sufferers have zero claims in a given interval, however the claims that do are available vary from routine workplace visits to main surgical procedures.
For demand forecasting with intermittent demand patterns (spare components, luxurious items, B2B transactions), the two-stage decomposition naturally captures the sporadic nature of purchases and avoids the smoothing artifacts that plague conventional time sequence strategies.
In credit score danger, anticipated loss calculations are inherently a hurdle downside: what’s the chance of default (Stage 1), and what’s the loss given default (Stage 2)?
When you’re working with any end result the place zeros have a basically completely different that means than “only a small worth,” hurdle fashions are value contemplating as a primary strategy.

Two-stage hurdle fashions present a principled strategy to predicting zero-inflated outcomes by decomposing the issue into two conceptually distinct components: whether or not an occasion happens and what magnitude it takes conditional on incidence.
This decomposition provides flexibility, since every stage can use completely different algorithms, options, and tuning methods.
It provides interpretability, as a result of you possibly can individually analyze and current what drives participation versus what drives depth, which is commonly precisely the breakdown that product managers and executives wish to see.
And it typically delivers higher predictive efficiency than a single mannequin attempting to deal with each the spike at zero and the continual constructive distribution concurrently.
The important thing perception is recognizing that zeros and constructive values typically come up from completely different mechanisms, and modeling them individually respects that construction fairly than combating in opposition to it.

Whereas this text covers the core framework, we haven’t touched on a number of different vital extensions that deserve their very own remedy.
Bayesian formulations of hurdle fashions can incorporate prior information and supply pure uncertainty quantification, which might tie in properly with our hierarchical Bayesian sequence.
Think about estimating product-level hurdle fashions the place merchandise with sparse knowledge borrow energy from their class.
Deep studying approaches open up the opportunity of utilizing unstructured options (textual content, pictures) in both stage.
When you’ve got the chance to use hurdle fashions in your individual work, I’d love to listen to about it!
Please don’t hesitate to succeed in out with questions, insights, or tales by way of my e mail or LinkedIn.
When you’ve got any suggestions on this text, or wish to request one other subject in causal inference/machine studying, please additionally be at liberty to succeed in out.
Thanks for studying!

Related Articles

Latest Articles