Calibrating Confidence Scores for a Custom Decision Model: Reliability Diagrams, Brier Score and Thresholds
A decision score becomes a probability only after it is fitted and tested against real outcomes on held-out data. The accept-or-defer threshold is a separate choice, made on separate data, from the cost of each kind of mistake.
To calibrate confidence scores for a custom decision model, fit a mapping from raw scores to observed outcomes on held-out data. Then test that mapping on an untouched set with a reliability diagram, log loss and Brier score. Start with sigmoid scaling for a binary score, or temperature scaling for option logits, and keep the unchanged score as a baseline. Choose the threshold for accepting or deferring a decision afterwards, on its own data, from the cost of errors and the cost of deferrals.
A confidence score counts as a probability only after it is checked against labeled outcomes
Guo and colleagues, in their 2017 ICML paper on the calibration of neural networks, give the plain test. If a model makes 100 predictions at 0.8 confidence, about 80 of them should be correct. Scikit-learn's calibration guide uses the same idea for binary classifiers. Among cases scored near 0.8, about 80% should turn out positive.
That test needs a defined event and a label for it. A custom decision model can produce three different numbers, and each one needs its own label:
- A class probability answers whether a case belongs to a class, such as "this claim is fraudulent." The label is the true class.
- A per-option suitability score rates each candidate action on its own, such as "refund is an acceptable reply." The label is whether that option was acceptable, and several options can be acceptable at once.
- The probability that the selected decision is correct covers only the option that the system finally picks. The label is whether that pick was right.
The third number is usually the one that matters for automation, because it is the number that a gate compares with a threshold. It is also the one that the first two do not supply. A model can rank options well and still be wrong about how often its top pick is right.
The same rule applies to rule engines. A weighted sum of rule scores can be useful for sorting cases. It becomes an empirical probability only after it has been mapped to observed outcomes. If no outcomes have been labeled yet, the score can still be used, but it should not be described as a probability.
Each stage of the work needs its own slice of data
Scikit-learn's guide explains why the calibrator must be fitted on data that the model never trained on. A model performs better on its own training data than on new data. A calibrator fitted on those outputs is biased toward probabilities closer to 0 and 1 than they should be. The library's threshold guide adds a parallel rule: never use the same data to train the classifier and to tune the threshold.
A leakage-resistant design therefore keeps four sets apart:
- The training set fits the model or the rule weights.
- The calibration set fits the mapping from score to probability.
- The threshold set chooses the accept-or-defer cut-off on calibrated outputs.
- The test set stays untouched until the final report, as scikit-learn's cross-validation guide requires.
Two kinds of structure in decision data break a random split. Decisions from the same customer, ticket or session are related, and scikit-learn's cross-validation guide states that grouped samples break the independence assumption. GroupKFold and StratifiedGroupKFold keep each group inside one fold. Decisions also change over time, and the same guide warns that shuffling time-ordered data inflates validation scores. TimeSeriesSplit trains on earlier data and tests on later data. For most production decision logs, a sensible design splits by time first and by group within each period.
The report should state the number of labeled decisions in every stage. As an illustration, a team with 20,000 labeled decisions might use 12,000 for training, 3,000 for calibration, 2,000 for threshold selection and 3,000 for the final test. If data is scarce, cross-validation can replace the separate calibration set. CalibratedClassifierCV accepts a custom splitter, so grouped or time-based folds can be passed in directly.
The calibration method has to match the kind of score that the model outputs
Each standard method assumes a specific score contract, and the wrong pairing either fails or overfits. The options in scikit-learn 1.9.1 cover the common cases:
- Sigmoid scaling, also called Platt scaling, fits a logistic curve to a single binary score. Scikit-learn's guide states that it is most effective for small samples and that it keeps the ranking unchanged.
- Isotonic regression fits any monotonically increasing step function. According to scikit-learn's guide, it matches or beats sigmoid with more than about 1,000 samples but tends to overfit on far fewer.
- Temperature scaling divides a vector of logits by one learned number before the softmax. Guo and colleagues found it the most effective method on their vision tasks, and it does not change which option is ranked first.
- The unchanged score is the baseline that every method must beat on the test set.
The multiclass assumptions matter for decision models. Scikit-learn calibrates sigmoid and isotonic one class at a time and then renormalizes the results. That design requires a fixed set of class columns. A decision model that chooses among a different list of options for every case has no fixed columns, so one-vs-rest calibration does not fit it.
Temperature scaling does fit variable option sets, because one temperature applies to any number of options. A model that returns only probabilities can still be calibrated this way. Taking the logarithm of the probabilities recovers the logits up to a constant, and the softmax ignores that constant. The temperature is fitted by minimizing log loss on the calibration set:
import numpy as np
from scipy.optimize import minimize_scalar
from scipy.special import log_softmax
def fit_temperature(option_logprobs, correct_idx):
# option_logprobs: one array per decision, of any length
# correct_idx: position of the correct option in each array
# Cases with no correct option on the shortlist cannot be fitted here
# but still count as errors in the evaluation
def nll(t):
return -np.mean([log_softmax(lp / t)[i]
for lp, i in zip(option_logprobs, correct_idx)])
return minimize_scalar(nll, bounds=(0.05, 20), method="bounded").x
For a binary score from a fitted model, scikit-learn's FrozenEstimator wrapper lets CalibratedClassifierCV fit only the calibrator on the calibration set. No method is guaranteed to help. If the calibrated model does not beat the unchanged score on held-out log loss and on the reliability diagram, the unchanged score should stay.
The evaluation report needs several metrics because each one hides something different
A reliability diagram groups predictions into bins and plots the observed rate of correct outcomes against the average confidence in each bin. Guo and colleagues point out a weakness: the diagram does not show how many samples fall in each bin. A bin with 12 decisions at 0.97 confidence looks as reliable as one with 1,200. The report should print the count under each bin and add a confidence interval for each observed rate, for example from a bootstrap over decisions.
Binning choices change the picture. Scikit-learn's calibration_curve defaults to five equal-width bins and also offers strategy="quantile", which puts an equal number of samples in each bin. Arrieta-Ibarra and colleagues, writing in the Journal of Machine Learning Research in 2022, describe the trade-off. Wider bins average away noise but lose resolution, and narrower bins do the reverse. They propose cumulative-difference plots, which avoid binning, as a complement.
The scalar metrics each answer a different question:
- Log loss punishes confident wrong answers heavily, and it is the quantity that temperature scaling minimizes.
- Brier score is the mean squared gap between predicted probability and outcome. Scikit-learn's guide explains that it mixes calibration, discrimination and the randomness of the data, so a lower Brier score does not prove better calibration.
- Discrimination, measured with ROC AUC, shows whether correct decisions receive higher scores than incorrect ones. Sigmoid and temperature scaling keep it unchanged, while isotonic regression can shift it by creating ties.
- Accuracy of the selected option shows whether calibration changed which option wins. Temperature scaling leaves it unchanged by design.
All of these numbers should be reported before and after calibration, on the same untouched test set, for every method including the unchanged baseline. No published experiment has measured these effects on a shortlist-and-reranker decision pipeline, so each team has to produce its own results before relying on them.
For option selection, the event to calibrate is whether the final pick was correct after the whole pipeline
Many decision systems first retrieve a shortlist of candidate options and then rerank it. The reranker's probabilities sum to one across the shortlist. If the retriever leaves out the correct option, the top probability still looks high, even though every pick on that shortlist is wrong.
Calibration should therefore be fitted and evaluated on the output of the complete pipeline. A case in which the correct option was missing from the shortlist counts as an incorrect decision. The report should also give the rate at which the correct option was missing, separately, because no recalibration of the reranker can fix a retrieval miss.
The number of candidates shifts the scores too. With two options, a top probability of 0.6 is barely above chance. With 50 options, the same number is a strong signal. Reliability diagrams should be split by option count, at least into a few ranges, so that a mapping that works for short lists is not assumed to work for long ones.
Every component should be pinned by version, including the model weights, any adapter, the retriever, the serving settings and the dataset snapshot. A calibration map fitted on one build does not transfer to another. Parsec's TOD decision model shows why. Its predict function returns one probability per supplied option, summing to one, and its repo states that it was measured with up to 300 options. According to the repo, the release is a LoRA adapter on google/gemma-4-12B-it plus a ModernBERT retriever. The repo also warns against bitsandbytes int8 quantization, which it states flips 8% of picks. A temperature fitted on full-precision outputs cannot be assumed to hold after such a change. A team using TOD would still need to run this evaluation on its own decisions and on the exact serving configuration that runs in production.
The accept-or-defer threshold is a cost decision made on separate data
Scikit-learn's threshold guide divides the work into a statistical problem, predicting probabilities, and a decision problem, acting on them. Calibration solves the first problem. The threshold solves the second, and the default of 0.5 is rarely right. In the guide's insurance example, the tuned threshold is about 0.02.
With calibrated probabilities, the break-even threshold follows directly from costs. Suppose that a wrong automatic decision costs E and that deferring a case to a person or a larger model costs D. Accepting a decision with probability p of being correct has an expected cost of (1 − p) × E. Accepting is cheaper than deferring when p is greater than 1 − D/E. If an error costs ten times as much as a deferral, the threshold is 0.9.
That formula is only a starting point, because real operations add constraints:
- A cap on deferrals follows from reviewer capacity, so the threshold may have to sit lower than the cost formula suggests.
- The outcome of the fallback has its own error rate, so the cost of a deferral should include the chance that the fallback also gets it wrong.
- The risk-coverage curve shows the error rate among accepted decisions at each share of decisions accepted, which is the trade-off that Geifman and El-Yaniv formalized as selective classification.
Scikit-learn's TunedThresholdClassifierCV searches thresholds against any scoring function, including a custom cost function built with make_scorer. Its documentation warns that cv="prefit" overfits if the threshold is tuned on the training data. The threshold should be chosen on the threshold set and then reported once on the test set, as a risk-coverage curve with the fallback outcomes alongside.
Confidence in a selection should stay separate from the authority to act on it. A calibrated 0.99 means that such picks are usually right. It does not mean that the system is permitted to issue a refund or delete an account. Permissions for each action belong in a separate check that does not depend on the confidence score.
Calibration needs monitoring because the mapping between scores and outcomes drifts
A mapping that fits last quarter's decisions can fail after a product launch, a policy change or a new option list. Newly labeled outcomes should feed a rolling reliability diagram and a rolling log loss, split by option count. A change to any pinned component is a clear trigger for recalibration. So is a shift in the mix of option counts, a rise in missing correct options, or a change in the deferral rate at a fixed threshold. Recalibration should use the most recent labeled period, with TimeSeriesSplit or a held-out later window, and the threshold should be chosen again afterwards on separate data.
Sources
- scikit-learn 1.9.1, Probability calibration: https://scikit-learn.org/stable/modules/calibration.html
- scikit-learn 1.9.1, CalibratedClassifierCV: https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html
- scikit-learn 1.9.1, calibration_curve: https://scikit-learn.org/stable/modules/generated/sklearn.calibration.calibration_curve.html
- scikit-learn 1.9.1, brier_score_loss: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.brier_score_loss.html
- scikit-learn 1.9.1, Tuning the decision threshold for class prediction: https://scikit-learn.org/stable/modules/classification_threshold.html
- scikit-learn 1.9.1, TunedThresholdClassifierCV: https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TunedThresholdClassifierCV.html
- scikit-learn 1.9.1, Cross-validation: https://scikit-learn.org/stable/modules/cross_validation.html
- Guo, Pleiss, Sun and Weinberger, On Calibration of Modern Neural Networks (ICML 2017): https://proceedings.mlr.press/v70/guo17a.html
- Arrieta-Ibarra, Gujral, Tannen, Tygert and Xu, Metrics of calibration for probabilistic predictions (JMLR 2022): https://arxiv.org/abs/2205.09680
- Geifman and El-Yaniv, Selective Classification for Deep Neural Networks: https://arxiv.org/abs/1705.08500
- Parsec, TOD: https://parseclab.ai/tod/
- Parsec, TOD repository: https://github.com/daseinlabs/tod