predict_proba or decision_function as estimator confidence
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
predict_proba() and decision_function() are both useful, but they do not mean the same thing. If you want class probabilities, use predict_proba() when the estimator offers well-defined probabilities. If you want ranking strength or margin from the decision boundary, use decision_function().
What predict_proba() Returns
predict_proba() returns one probability per class for each sample. The values are constrained to the interval from 0 to 1, and each row sums to 1.
Example:
A binary classifier might produce rows such as:
That is convenient when you need thresholds like "only act if class 1 probability is at least 0.9."
What decision_function() Returns
decision_function() returns a score, not a probability. The score usually measures signed distance or margin relative to the learned decision boundary.
For binary classification:
- Positive values lean toward the positive class
- Negative values lean toward the negative class
- Larger magnitude usually means the model is more certain in its own internal scale
The important caveat is that the scale is model-specific. A score of 3.0 in one estimator is not directly comparable to 3.0 in another.
Which One Is "Confidence"
That depends on what you mean by confidence.
If you mean "estimated probability of belonging to a class," then predict_proba() is the right API.
If you mean "strength of the model's preference before converting it to a probability," then decision_function() is the better fit.
For tasks such as:
- Sorting examples from most positive to least positive
- Drawing ROC curves
- Comparing margins around a classifier boundary
decision_function() is often perfectly appropriate, and sometimes better.
Probabilities Are Not Always Well Calibrated
A second important caveat is that probabilities are not automatically trustworthy just because the method name says predict_proba(). Some classifiers produce poor probability calibration even when their ranking ability is strong.
If you need probabilities that reflect real-world frequencies, use calibration:
This is especially relevant for SVM-like models, where the raw margin is often more natural than the probability estimate.
Practical Rule of Thumb
Use predict_proba() when:
- You need probabilities for thresholds, risk estimates, or UI display
- Your estimator supports it directly or through calibration
Use decision_function() when:
- You care about relative ranking
- You are building ROC or precision-recall analysis
- The estimator naturally exposes margins rather than calibrated probabilities
Multi-Class Behavior
In multi-class problems, predict_proba() returns one probability per class, which makes it easy to explain the full class distribution. decision_function() may return one score per class or a one-vs-rest style margin depending on the estimator. That makes it useful for internal ranking logic, but less convenient when downstream code expects something that sums cleanly to 1.0.
Common Pitfalls
- Treating
decision_function()values as probabilities. - Assuming
predict_proba()is always well calibrated. - Comparing raw decision scores across different model families as if they shared a common scale.
- Forcing a probability interpretation when ranking is the real requirement.
Summary
- '
predict_proba()gives class probabilities.' - '
decision_function()gives raw model scores or margins.' - Probabilities are easier to explain, but not always calibrated.
- Decision scores are often better for ranking and threshold tuning.
- Choose the API based on the downstream use, not on which one looks more "confident."
Related reading
- .predict runs only on CPU even though GPU is available
- Predict single Image after training model in tensorflow
- Predicting a probability of a sentence using tensorflow
- Predicting a single image with Keras' ImageDataGenerator
- Predicting a users next action based on current day and time
- predicting class for new data using neuralnet
- Predicting how long an scikit-learn classification will take to run
- Predicting Missing Words in a sentence - Natural Language Processing Model
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.