Most people train models on what happened.
But sometimes you need to train them on what ALMOST happened.
The Danger Zone: 0 vs 1 Inventory
In operations, what's the difference between 0 inventory and 1 inventory?
Zero means you're screwed. One means you got lucky.
But both are skating the edge.
If you're building a prediction model to flag out-of-stock (OOS) risk, it's tempting to let the 1s slide. After all, the product wasn't out of stock. Technically.
Technically isn't helpful when you're trying to get ahead of problems that rarely occur.
Redefining Risk Through Labeling
Label the 1s as out-of-stock too.1
Not because they were. But because they almost were. And "almost" is what you actually care about.
Machine learning doesn't know what "dangerous" means. It doesn't have judgment.
It just learns from labels.
So if you only teach it to fear the zero, it won't raise a flag until it's too late. But if you teach it to treat the 1 as just as risky — because it is — now you've got a model that sees the edge coming, not just the cliff.
# --- DEFINE LABEL STRATEGIES (STRICT vs. LOOSE) --- #
# Traditional approach - only zeros are problems
df["strict_label"] = (df["inventory_true"] == 0).astype(int)
# Strategic approach - zeros AND ones signal risk
df["loose_label"] = (df["inventory_true"] <= 1).astype(int)
By changing how you label your data, you change what your model learns to predict.
The Paradox
Your model will sound the alarm near 1. Not just at zero.
But there's a trade-off. Your model does a better job at sounding the alarm near the danger zone. However, overall it generally performs "worse" by standard metrics.
Worse can't be better, can it?
Well, if identifying OOS risk is the most important thing, this could be one way to do that, even if the stats say performance degrades.2
Labels are levers
The big idea: labels are malleable.
They're not sacred. They're tools. So shape them to match the future you want to predict, not the past that already happened.
Call the 1s what they really are: warning shots.
Because in operations, if you're waiting for zero to act, you're already too late.
There are at least two more common ways to achieve this; class_weight="balanced" and predict_proba to modify the decision threshold.
The best approach is often to train both models and use them in combination - the strict model for accuracy metrics, and the loose model for early warning systems.