الانتقال إلى المحتوى
Machine Learningتقييم الموديلات· 7 دقائق للقراءة

What predict_proba Really Means: Probability Calibration Explained

A score between 0 and 1 is only a probability if the model is calibrated. Check it with a calibration curve and fix it with CalibratedClassifierCV.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • scikit-learn 1.9
محتويات المقال

A trust and safety team uses a classifier on its queue of reported posts. To save reviewer time, it auto-dismisses any report the model scores under 5%, an error rate everyone agreed to. The model's ROC AUC is a solid 0.934. Three months later an audit samples the dismissed reports: 13.7% of them broke the rules. The model said those reports had a 0.2% chance on average. Nobody had checked whether its numbers meant what they said.

The common misconception

Many developers read predict_proba as the chance a prediction is right: a 0.8 means an 80% chance. It's an easy belief to hold:

  • The method is literally called predict_proba, and its output behaves like probabilities: between 0 and 1, summing to 1 across classes.
  • Logistic regression, the first classifier most people learn, often does give well-calibrated probabilities, so the habit forms early.
  • Good accuracy and ROC AUC feel like they certify everything the model outputs.

The half-truth: for some models, under some conditions, the outputs are good probabilities. But nothing in the API promises it. Whether a 0.8 means 80% is an empirical property of a model on a data distribution, and you have to measure it.

What actually happens

A classifier is trained to separate classes, and its scores only have to put the cases in the right order for that. Turning those scores into honest frequencies is a separate property with its own name.

Calibration is a statement about groups

scikit-learn's calibration guide defines it: a well-calibrated binary classifier is one where, among the samples it gives a predict_proba close to 0.8, about 80% actually belong to the positive class. That's a claim about a group of cases checked against outcomes, never about a single case. A calibrated 0.8 means "8 in 10 cases like this one". It also says nothing about how useful the model is: one that gave every case the base rate would be perfectly and useless. Ranking and calibration are two separate qualities, and a model can have either without the other.

Why scores drift from frequencies

Each model family distorts in its own way:

  • Naive Bayes assumes features are independent given the class. When several features carry the same evidence, it counts that evidence several times and pushes scores toward 0 and 1.
  • Max-margin methods such as SVMs and boosted trees push scores away from 0 and 1, a sigmoid-shaped distortion described by Niculescu-Mizil and Caruana; scikit-learn's guide shows random forests rarely reaching 0 or 1.
  • Modern neural networks are often poorly calibrated, Guo and colleagues found, and they link it to depth, width, weight decay and batch normalization.
  • Class weights and resampling change the class balance the model learns from, so its scores describe that rebalanced world, not yours.

Logistic regression is the friendly exception: the guide credits its log loss and logit link, provided the model fits the data well. In the example below, 10 of the 20 features are mixes of the 2 informative ones, the textbook trap for naive Bayes.

Python
from sklearn.calibration import calibration_curvefrom sklearn.datasets import make_classificationfrom sklearn.metrics import brier_score_loss, roc_auc_scorefrom sklearn.model_selection import train_test_splitfrom sklearn.naive_bayes import GaussianNB# 2 informative features plus 10 redundant mixes of themX, y = make_classification(n_samples=20_000, n_features=20, n_informative=2,                           n_redundant=10, random_state=11)X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.5, random_state=0)proba = GaussianNB().fit(X_tr, y_tr).predict_proba(X_te)[:, 1]low = proba < 0.05  # auto-dismissed as "under 5% likely"print(f"under 5%: {low.sum()} reports, {y_te[low].mean():.1%} violating")share, score = calibration_curve(y_te, proba, n_bins=5)print("mean score    ", score.round(2))print("share positive", share.round(2))auc, brier = roc_auc_score(y_te, proba), brier_score_loss(y_te, proba)print(f"ROC AUC {auc:.3f}, Brier {brier:.3f}")# under 5%: 5078 reports, 13.7% violating# mean score     [0.01 0.3  0.5  0.71 0.99]# share positive [0.16 0.55 0.57 0.7  0.93]# ROC AUC 0.934, Brier 0.121

The tells the story. The raw model's lowest bin averages a score of 0.01, yet 16% of those cases are positive; its top bin averages 0.99 and is 93% positive. That's the overconfident shape naive Bayes is known for. After isotonic calibration, each bin's mean score matches its share of positives within a point. The 5% rule now dismisses 1,839 reports instead of 5,078, and 4.7% of them violate, the error rate the team signed up for. It automates less, but its number finally means what it says.

ROC AUC is 0.934 both times. The calibration example in scikit-learn explains why: calibration is a monotonic transformation, so rank metrics aren't affected. The drops from 0.121 to 0.098. The guide adds a caution: Brier score and log loss mix calibration with discrimination, so a lower value doesn't prove better calibration on its own. Look at the curve.

How CalibratedClassifierCV fits

With cv=5, it fits a copy of the classifier on four fifths of the training data and fits the calibrator on the remaining fifth, five times, then averages the five calibrated models' probabilities. The calibrator never sees scores from rows the classifier trained on. Pick the method by your data:

  • "sigmoid" is Platt's method: a logistic regression on the scores, with few parameters, good for small data and sigmoid-shaped distortions.
  • "isotonic" fits any monotonic distortion, but the API reference warns it tends to overfit with well under 1,000 calibration samples.
  • "temperature", added in scikit-learn 1.8, divides the logits by one fitted value, and handles multiclass natively.
MythReality
predict_proba returns probabilitiesIt returns scores; they're probabilities only if calibrated, which you measure
A 0.8 means this case is 80% likelyA calibrated 0.8 means about 8 in 10 cases scored like it are positive
High ROC AUC means trustworthy scoresAUC 0.934, yet "under 5%" reports were 13.7% violations
Calibrating changes the model's rankingROC AUC stayed 0.934; calibration is monotonic
Calibrate once and you're doneCalibration holds for the data it was fit on; recheck when the base rate shifts

How to apply it in your project

  1. Decide whether you need probabilitiesRanking, or a cut-off tuned on validation data, works with any scores. Expected values, displayed confidence and fixed probability rules need calibration.
  2. Plot the curve on held-out dataUse calibration_curve with the counts per bin, for the model exactly as it's deployed.
  3. Calibrate with CalibratedClassifierCVUse sigmoid for small calibration sets, isotonic with more than about 1,000 samples, temperature for multiclass.
  4. Evaluate on data the calibrator never sawReport the curve with log loss or Brier score from a separate test split.
  5. Recheck after the world changesA new base rate, a new market or retraining with class weights can break calibration silently. Plot the curve on recent data.

Key takeaways

  • predict_proba gives scores; a 0.8 means 80% only if the model is calibrated, and that's something you measure.
  • Calibration is about groups: of all cases scored 0.8, about 80% should be positive.
  • Naive Bayes, max-margin models, deep networks and class weights all distort scores; here "under 5%" meant 13.7%.
  • CalibratedClassifierCV fixed it without changing the ranking: ROC AUC stayed 0.934.

📚 المصادر

  1. Probability calibration — scikit-learn User Guide
  2. Probability Calibration curves — scikit-learn examples
  3. CalibratedClassifierCV — scikit-learn API Reference
  4. Niculescu-Mizil and Caruana, Predicting Good Probabilities With Supervised Learning (ICML 2005)
  5. Guo et al., On Calibration of Modern Neural Networks (ICML 2017)

التعليقات (0)