Machine Learning
Machine learning is a way to build software by fitting models to examples instead of writing every rule by hand. A model sees data, optimizes an objective, and generalizes the learned pattern to new inputs.
What is Thresholded Adaptive Calibration Error (TACE) in classification?
Thresholded Adaptive Calibration Error (TACE) measures class probability calibration after discarding very small predicted probabilities , then grouping the remaining scores into approximately equal count bins. Nixon et al. proposed thresholding because modern many class models often assign near zero probabilities to most classes, which can dominate ordinary ACE. What happens in TACE? For each class, collect its predicted probabilities across examples and the corresponding one versus rest outcomes : 1 if that class is the true label, otherwise 0. Filter: retain only probabilities above a chosen threshold ε (for example, ε = 0.05). This is a measurement filter , not the threshold used to predict the winning class. Adaptively bin: sort the retained scores and split them into approximately equal sized groups. Measure: calculate the absolute difference between each bin's mean probability and its observed class frequency. Aggregate: average the gaps across valid bins and classes. Specify how you handle too few retained values, empty bins, and classes with no surviving predictions; implementations can differ. Beginner friendly numerical example: one class A three class model produces the following six probabilities for class A , with class A ground truth indicators: Example 1: probability 0.01 , true A? 0 . Example 2: probability 0.03 , true A? 0 . Example 3: probability 0.10 , true A? 0 . Example 4: probability 0.40 , true A? 0 . Example 5: probability 0.60 , true A? 1 . Example 6: probability 0.80 , true A? 1 . Step 1 — Filter with ε = 0.05. Discard 0.01 and 0.03; keep 0.10, 0.40, 0.60, 0.80 . Step 2 — Create two adaptive bins , each with two surviving predictions: Lower bin: [0.10, 0.40]; mean confidence = 0.25 ; actual class A frequency = 0/2 = 0 ; gap = |0.25 − 0| = 0.25 . Higher bin: [0.60, 0.80]; mean confidence = 0.70 ; class A frequency = 2/2 = 1.00 ; gap = |0.70 − 1.00| = 0.30 . Step 3 — Average this class's bin gaps: (0.25 + 0.30)/2 = 0.275 , or 27.5 percentage points . Important: 0.275 is the class A contribution/average in this toy example , not the model's full multiclass TACE . Repeat the process for classes B and C, then average valid classwise results to obtain a complete multiclass estimate. How does TACE differ from ACE? ACE: adaptively bins all class probabilities, including many near zero values. TACE: filters out probabilities at or below ε before adaptive binning, so the evaluation focuses on class probabilities large enough to matter for the chosen threshold. TACE is not necessarily smaller or better than ACE: it measures calibration over a different subset of scores, so the values are not directly comparable without stating their definitions and thresholds. Simple Python demonstration for class A Advantages, limitations, and applications Useful for many class networks: avoids letting enormous numbers of tiny probabilities overwhelm the adaptive bin calculation. Threshold sensitivity: changing ε changes which predictions contribute and can change the metric substantially. Report ε , bin count, sample size, and class coverage. Can omit rare class evidence: higher thresholds can remove almost every probability for a rare class; do not silently label missing class bin results as perfect calibration. Binning remains noisy: sparse surviving scores, ties, and wide adaptive intervals can make estimates unstable or hide local problems. Does not assess all confidence values: a low TACE says little about excluded probabilities, classification accuracy, or minority group outcomes. Applications: auditing classwise confidence for image classifiers and other multi category models, especially when thousands of non winning class probabilities are tiny. Key takeaway: TACE = classwise adaptive calibration assessment after filtering near zero probabilities . It improves focus, but the score is meaningful only alongside the threshold and binning procedure. References Nixon et al. (2019), Measuring Calibration in Deep Learning Extended paper (arXiv:1904.01685)
What is temperature scaling for probability calibration?
Temperature scaling is a post training method that adjusts a classifier's predicted probabilities using one positive parameter T , without changing the order of its class scores. It is useful when a model frequently makes predictions with more or less confidence than its correctness warrants. How it works Logits are the raw scores output by a classification model before softmax. Convert logits z to probabilities with softmax(z / T) : for class j, probability = exp(zⱼ/T) / Σₖ exp(zₖ/T). T = 1: original probabilities. T 1: spreads probability more evenly across classes (softens confidence). 0 < T < 1: makes the largest logits more dominant (sharpens confidence). Because every logit is divided by the same positive number , the highest scoring class is unchanged. Temperature scaling usually leaves hard label accuracy unchanged, but changes probability based metrics. Beginner friendly numerical example Suppose a three class image classifier produces logits [2, 1, 0] for [Cat, Dog, Bird]. Step 1 — Original probabilities (T = 1) Exponentials: exp(2) ≈ 7.389, exp(1) ≈ 2.718, exp(0) = 1; sum ≈ 11.107. Softmax ≈ [0.665, 0.245, 0.090] . The model predicts Cat with 66.5% confidence. Step 2 — Soften with T = 2 Adjusted logits: [1, 0.5, 0] . Exponentials: approximately [2.718, 1.649, 1] , sum ≈ 5.367. Softmax ≈ [0.506, 0.307, 0.186] . Cat remains the top prediction, but its confidence drops to 50.6% . Step 3 — Sharpen with T = 0.5 Adjusted logits: [4, 2, 0] . Exponentials: approximately [54.598, 7.389, 1] , sum ≈ 62.987. Softmax ≈ [0.867, 0.117, 0.016] . Cat confidence increases to 86.7% . Key observation: Cat remains the top class at all three temperatures. The probabilities change, not the predicted class. How is the temperature fitted? 1. Train the base classifier normally; freeze its model weights . 2. Prepare a separate, representative calibration/validation set not used to fit the classifier or evaluate its final test performance. 3. Compute the frozen model's logits for that set. 4. Find a single T 0 that minimizes the mean negative log likelihood (cross entropy) of the true labels after softmax(z/T). Optimize log(T), or otherwise constrain T to remain positive. 5. Apply that same learned T to future logits at inference time; assess resulting probabilities on an untouched test set. Simple PyTorch sketch: How does this relate to calibration metrics? Reliability diagrams help reveal whether confidence matches empirical accuracy in confidence regions. ECE, MCE, ACE, and TACE provide different summaries of the remaining calibration mismatch, depending on how scores are grouped or filtered. Brier score and negative log likelihood evaluate full predictive probabilities. Minimizing validation log loss does not guarantee improving every other calibration metric; verify on held out data. Temperature scaling is a calibration method , not a new metric or a way to improve ranking. Applications and limitations Applications: image classification, document labeling, and decision support systems where reliable class probabilities matter. One global parameter: a single T may not fix class specific or subgroup specific calibration errors. Ranking unchanged: temperature scaling cannot correct which class was ranked first or improve top 1 accuracy by itself. Data shift: a temperature learned on past validation data may not calibrate future inputs after distribution changes. Do not confuse with generation temperature: both change softmax sharpness, but fitting temperature to classification labels for probability calibration is a specific post hoc procedure. Key takeaway: Learn one temperature on held out data to soften or sharpen class probabilities while preserving the predicted label. References Guo et al. (2017), On Calibration of Modern Neural Networks scikit learn Probability Calibration
What is Platt scaling for probability calibration?
Platt scaling turns a binary classifier's raw decision scores into estimated probabilities by fitting a sigmoid (logistic) mapping on separate calibration data. It is commonly used with support vector machines (SVMs), whose decision scores are not probabilities. Step by step numerical example Suppose a frozen fraud classifier produces a decision score s : larger values generally mean “more likely fraud.” On independent calibration data, a fitted sigmoid has illustrative parameters w = 1.2 and b = −0.4 . Step 1 — Apply the fitted mapping: P(fraud | s) = 1 / [1 + exp(−(1.2 × s − 0.4))]. These parameter values are illustrative ; they must be learned from labeled calibration examples, not guessed for a real deployment. Step 2 — Convert a score of s = 0: Adjusted score = 1.2 × 0 − 0.4 = −0.4 . Probability = 1 / (1 + exp(0.4)) ≈ 0.401 , or 40.1% . Step 3 — Convert s = 1: Adjusted score = 1.2 × 1 − 0.4 = 0.8 . Probability = 1 / (1 + exp(−0.8)) ≈ 0.690 , or 69.0% . Step 4 — Convert s = 2: Adjusted score = 1.2 × 2 − 0.4 = 2.0 . Probability = 1 / (1 + exp(−2)) ≈ 0.881 , or 88.1% . These scores now have probability like values ; whether they are well calibrated depends on how frequently fraud actually occurs among examples given comparable probabilities. How are the sigmoid parameters learned? 1. Train the base classifier on its training data . 2. Hold out a disjoint, representative calibration set , or obtain out of fold scores with cross validation. 3. Run the trained classifier on each calibration example to obtain a raw decision score sᵢ and its actual binary label yᵢ . 4. Fit w and b to minimize binary negative log likelihood: the same fitting idea as logistic regression with one numeric input, the frozen model's score . 5. Freeze the fitted mapping and evaluate its reliability on an untouched test set ; apply it to future model scores during inference. Why two parameters? The sigmoid's slope changes its steepness, while the intercept shifts where it transitions through 50%. Python example: scikit learn Platt scaling versus temperature scaling Platt scaling: fits a slope and intercept on binary scores; it can both reshape and shift probabilities. Temperature scaling (Question 212): fits one positive temperature dividing logits before softmax; multiclass predicted label ordering stays unchanged. Platt scaling is naturally binary . In scikit learn, sigmoid based multiclass calibration uses one vs rest mappings followed by renormalization , which is not identical to multiclass softmax temperature scaling. A positive Platt slope preserves binary score ordering, but do not assume all fitted or multiclass calibrations preserve the original decisions or rankings . When should you use it? SVM margins: convert raw decision function scores to usable probability estimates for downstream decisions. Other binary scorers: where held out results suggest a roughly sigmoid shaped calibration correction. Applications: fraud triage, document classification, quality inspection, and probability based review queues. Limitations Needs separate representative labels: calibrating on the classifier's training predictions can cause overfitting and overly optimistic evaluation. Parametric shape: a single sigmoid cannot correct every irregular calibration pattern; more flexible approaches may work better with sufficient data. Dataset shift: fitted probabilities may cease to match observed frequencies after prevalence or input distributions change. Imbalanced classes: the available calibration labels and class frequencies matter; inspect minority class performance and calibration. No guarantee of improved classification: optimization targets a probabilistic loss, not accuracy, and can change threshold based decisions. Check results: assess held out reliability and appropriate probability metrics rather than assuming the sigmoid fixed every issue. Key takeaway: Platt scaling learns a two parameter sigmoid from held out classifier scores to observed binary outcomes , then uses it to turn future scores into probability estimates. References scikit learn: Probability calibration scikit learn: CalibratedClassifierCV Classifier calibration survey
What is isotonic regression for probability calibration?
Isotonic regression calibrates a binary classifier by learning a non decreasing mapping from raw decision scores or predicted probabilities to observed positive event rates. Unlike Platt scaling's fixed sigmoid, it can learn flat sections and changes in slope while preserving the rule that a larger score cannot map to a smaller calibrated probability. Beginner friendly example: sorting and pooling scores A frozen classifier generates these six scores and actual binary outcomes on a separate calibration set : Score 0.10 , outcome 0 . Score 0.20 , outcome 1 . Score 0.30 , outcome 0 . Score 0.40 , outcome 1 . Score 0.50 , outcome 0 . Score 0.60 , outcome 1 . Step 1 — Sort by classifier score. These scores are already ascending. If we used the raw labels as probabilities, the sequence would be [0, 1, 0, 1, 0, 1] . This is not non decreasing: it jumps downward twice. Step 2 — Pool Adjacent Violators Algorithm (PAVA). Start with one block per score, each assigned its observed outcome. When a lower score block has a higher average outcome than the block directly after it, merge the blocks and replace their fitted values by the combined outcome average. At scores 0.20 and 0.30 , the block values 1, 0 violate monotonicity. Pool them into (1 + 0)/2 = 0.50 . At scores 0.40 and 0.50 , again pool 1, 0 into 0.50 . Re check neighboring blocks and continue until no downward step remains. Step 3 — Fitted probabilities at observed scores: [0, 0.50, 0.50, 0.50, 0.50, 1] . The function is now non decreasing. Step 4 — Interpret the mapping: the calibration fit places scores from 0.20 to 0.50 on a plateau of 50% estimated probability at the observed calibration points. This tiny example illustrates the algorithm; probabilities of exactly 0 or 1 are especially unstable with so little data. Why PAVA works Isotonic regression finds fitted values that minimize the sum of squared differences from the observed outcomes , subject to a non decreasing constraint as scores rise. PAVA efficiently enforces that constraint by pooling neighboring blocks whose fitted averages are out of order . Each pooled block's value is its average observed outcome (or weighted average with sample weights). When using the fitted function on scores between training points, the interpolation and out of range behavior depend on the chosen implementation. Python example For an entire scikit learn classifier, CalibratedClassifierCV(estimator=base model, method="isotonic", cv=5) obtains calibration scores from separate folds, helping avoid leakage. Isotonic regression versus Platt scaling Mapping: isotonic learns a flexible monotone function ; Platt scaling learns a two parameter sigmoid . Data needs: isotonic can fit irregular calibration relationships but needs more representative calibration observations . scikit learn cautions against isotonic calibration on small datasets (much less than about 1,000 calibration samples). Ranking: isotonic can create ties (flat probability plateaus) and therefore may change ranking metrics such as ROC AUC; a strictly increasing sigmoid preserves the order of binary scores. Choice: compare both methods using independent evaluation data and probability focused metrics; neither method guarantees better downstream decisions. Applications and limitations Applications: post hoc calibration of fraud, churn, credit risk, or binary classification scores when score to frequency distortion is not well described by a sigmoid. Overfitting: on a small calibration set the learned steps can follow noise. Do not calibrate on the same predictions used to train the base model. Coverage: scores beyond the observed calibration range need a documented extrapolation policy; out of bounds="clip" clips to the end fitted values. Monotonicity assumption: the method cannot learn mappings where higher raw scores should legitimately imply lower event rates. Multiclass nuance: a common approach calibrates each class one vs rest and then normalizes probabilities; this is not the same as independently producing a joint probability distribution without correction. Deployment: calibration may deteriorate under data shift. Monitor results on representative held out or production data. Key takeaway: Isotonic regression learns a monotone score to probability map by pooling local violations. It is flexible, but needs enough data to avoid fitting noise. References scikit learn Probability calibration scikit learn IsotonicRegression
What is beta calibration for classification probabilities?
Beta calibration is a post training method for improving a binary classifier's predicted probabilities . It applies a flexible three parameter mapping that uses both the logarithm of a predicted probability and the logarithm of its complement. Unlike a sigmoid fitted directly to a raw score, beta calibration can represent the identity mapping —leaving already well calibrated probabilities unchanged. Mapping and its two logarithms Start with a raw predicted positive class probability p , with 0 < p < 1 . Compute u = a × ln(p) − b × ln(1 − p) + c . Output the calibrated probability q = sigmoid(u) = 1 / (1 + exp(−u)) . ln(p) responds strongly to small values of p, while −ln(1 − p) responds strongly to values near 1. Separate a and b allow different corrections at the two ends. With a ≥ 0, b ≥ 0 , the mapping is non decreasing. a = b = 1, c = 0 gives q = p : the identity mapping. The parameter values below are for explanation, not learned from real data. Beginner friendly step by step numerical example Suppose the fitted parameters were a = 2, b = 1, c = 0 . Example A — raw probability p = 0.20 ln(0.20) ≈ −1.6094 , ln(0.80) ≈ −0.2231 . u = 2(−1.6094) − 1(−0.2231) = −2.9957 . q = sigmoid(−2.9957) ≈ 0.0476 , or 4.8% . Example B — raw probability p = 0.50 ln(0.50) ≈ −0.6931 ; ln(1−0.50) is the same. u = 2(−0.6931) − (−0.6931) = −0.6931 . q = sigmoid(−0.6931) = 0.3333 , or 33.3% . Example C — raw probability p = 0.80 ln(0.80) ≈ −0.2231 , ln(0.20) ≈ −1.6094 . u = 2(−0.2231) − (−1.6094) = 1.1632 . q = sigmoid(1.1632) ≈ 0.7619 , or 76.2% . The fitted curve has changed 20% → 4.8%, 50% → 33.3%, 80% → 76.2% . These numbers illustrate the arithmetic, not that these adjustments improve an arbitrary classifier. How are the parameters learned? 1. Fit the original classifier using its training set ; freeze it. 2. Obtain its predicted positive class probabilities on a separate labeled calibration set (or use carefully constructed out of fold predictions). 3. Transform each probability into two features: ln(p) and −ln(1−p) . Clip exact 0 and 1 values to a small safe interval before taking logs. 4. Fit a logistic regression mapping on these transformed features by minimizing binary negative log likelihood on the calibration labels, preferably enforcing a, b ≥ 0 to preserve monotonicity. 5. Keep the learned mapping fixed. Test it on an untouched evaluation set , then apply it to future probabilities. Python example: apply illustrative fitted parameters Comparison with Platt scaling and isotonic regression Platt scaling (Q213): applies a two parameter logistic curve to a classifier decision score. It may struggle with asymmetric distortions in probability valued outputs. Beta calibration: uses the two log probability features with three parameters . It can model asymmetry and can leave already calibrated scores unchanged. Isotonic regression (Q214): learns a flexible non decreasing mapping with flat sections. It can fit more shapes, but typically needs more calibration data and can overfit small sets. Nuance: with a = b , beta calibration is equivalent to logistic calibration applied to the log odds of p ; this is not the same as Platt scaling on an arbitrary raw decision score. Benefits, limitations, and applications Benefits: flexible parametric correction of skewed probability distortions; simple fitting with logistic regression style optimization; identity mapping is representable. Limitations: must start with probability like scores in [0,1], requires a representative held out set, and can still overfit or fail under distribution shift. Careful fitting or constraints are needed to keep the mapping monotone. Evaluation: compare held out log loss, Brier score, and reliability diagrams. A numerically different probability is not automatically a better probability . Applications: probabilistic outputs of Naive Bayes, AdaBoost, fraud risk, churn, and other binary classifiers where calibration matters. Key takeaway: Beta calibration learns a, b, c to transform p through sigmoid(a ln p − b ln(1−p) + c) . Its extra shape flexibility makes it a useful alternative to Platt scaling, while remaining simpler than unrestricted isotonic fitting. References Kull, Silva Filho & Flach (2017), Beta calibration Classifier calibration survey
What is the difference between calibration and discrimination in classification?
Calibration asks whether predicted probabilities match event frequencies. Discrimination asks whether the model ranks examples that experience the event ahead of those that do not. A model can be strong on one property and weak on the other. Beginner friendly numerical example: two classifiers, six customers Actual outcomes (churn = 1, no churn = 0) for Customers 1–6: [1, 1, 1, 0, 0, 0] . Model A — calibrated overall, but weak discrimination Gives every customer 0.50 predicted churn probability: [.50, .50, .50, .50, .50, .50] . Calibration: among the six 50% confidence predictions, 3/6 = 50% actually churn. Thus it is perfectly calibrated on this single observed group . Discrimination: all customers are tied. ROC AUC = 0.50 using the usual half credit convention for tied positive–negative pairs. Model A offers no useful ordering for prioritizing customers despite matching the group event rate. Model B — perfect discrimination, poorly calibrated probabilities Gives churners 0.60 and non churners 0.40 : [.60, .60, .60, .40, .40, .40] . Discrimination: every positive score exceeds every negative score. There are 3 × 3 = 9 positive–negative pairs, all correctly ordered, so ROC AUC = 9/9 = 1.00 . Calibration: the 60% score group actually churns 3/3 = 100% ; the 40% score group churns 0/3 = 0% . Both groups' event frequencies differ from their predicted probabilities. Model B ranks customers perfectly here but underestimates risk for churners and overestimates it for non churners in these two groups. Important: With just six observations, these are illustrative sample level findings, not reliable evidence of population calibration. Which metrics evaluate each property? Calibration: reliability diagrams, ECE/MCE and their variants describe probability–frequency gaps; Brier score and log loss assess overall probabilistic quality, but also reflect discrimination/resolution. Discrimination: ROC AUC measures pairwise ranking across positive and negative cases; PR AUC/average precision can be especially informative when positives are rare. Decision usefulness: threshold specific precision, recall, false positive rates, workload, and error costs answer operational questions neither property resolves alone. Practical engineering implications Risk ranking: for deciding which customers to contact first, ranking ability matters. Risk estimates: for reporting “this customer has a 70% churn risk,” credible probabilities matter. Both matter: a financial or medical triage workflow may need both reliable risk ordering and probabilities for resource allocation. Post hoc calibration: strictly increasing mappings such as positive slope sigmoid calibration can change probabilities without changing ROC AUC; flat isotonic mappings can create ties and alter ranking metrics. Data shift and class prevalence: calibrate and evaluate on data representative of the intended deployment; both properties may change over time. Python check Limitations One metric is not enough: excellent ROC AUC does not guarantee trustworthy probabilities, and low ECE need not imply useful ranking. Small calibration groups: perfect looking agreement on few examples can be chance; use adequate support and confidence intervals when possible. Calibration depends on grouping: a population average 50% forecast may be calibrated at that one score while unhelpful for individual prioritization. Operational costs differ: neither calibration nor ROC AUC alone tells you the optimal action threshold. Key takeaway: Calibration is about the numerical meaning of probabilities; discrimination is about the ordering of cases. Inspect both when predicted risks drive decisions. References scikit learn: Probability calibration scikit learn: ROC AUC score scikit learn: model evaluation
What is selective classification, and how does a reject option work?
Selective classification (classification with a reject option ) lets a model either return its predicted class or abstain when the example is too uncertain. Instead of forcing a prediction for every input, the system can route rejected cases to human review or a safer fallback. Its central design problem is the trade off between coverage and risk on the accepted cases . Beginner friendly numerical example: support ticket routing A model predicts the appropriate ticket queue. It supplies a predicted label and the confidence of that top prediction. Suppose we test it on eight labeled tickets , ordered from highest to lowest confidence: Ticket 1: 0.98 , prediction correct . Ticket 2: 0.95 , correct . Ticket 3: 0.91 , correct . Ticket 4: 0.87 , incorrect . Ticket 5: 0.83 , correct . Ticket 6: 0.76 , correct . Ticket 7: 0.62 , incorrect . Ticket 8: 0.54 , incorrect . Step 1 — Classify all eight. With no reject option, 5/8 are correct . Overall error rate = 3/8 = 37.5% ; coverage is 100% . Step 2 — Set acceptance threshold τ = 0.80. Accept a prediction only when top label confidence ≥ 0.80 . Accepted: Tickets 1–5; five predictions. Abstained: Tickets 6–8; three predictions. Importantly, one rejected prediction (Ticket 6) would have been correct: abstention is not a perfect error detector. Step 3 — Calculate coverage. Coverage = accepted / all = 5/8 = 62.5%. Abstention rate = rejected / all = 3/8 = 37.5%. Step 4 — Calculate selective risk. Among accepted tickets 1–5, only Ticket 4 is wrong. With 0–1 loss , selective risk = wrong accepted predictions / accepted predictions = 1/5 = 20%. Selective accuracy = 4/5 = 80%. This is not accuracy across all eight tickets. Step 5 — Try a stricter threshold τ = 0.90. Accept only Tickets 1–3, all correct. Coverage falls to 3/8 = 37.5% , and observed selective risk becomes 0/3 = 0% . A zero error on three examples is not a reliable guarantee of zero future risk. How is this different from a normal classification threshold? A class decision threshold chooses which label to output (for example, fraud versus not fraud). A reject threshold chooses whether to trust and output the classifier's proposed label at all. Low scoring inputs receive abstain/review , not automatically the negative class. In multiclass classification, a common acceptance score is the maximum predicted class probability ; other uncertainty scores or learned selection functions are possible. How should selective classifiers be evaluated? Coverage: fraction of inputs automatically handled. Selective risk: average loss only on accepted inputs ; for 0–1 loss, this is the accepted error fraction. Risk–coverage curve: vary the acceptance threshold and plot selective risk against coverage to reveal the operational trade off. Rejected case workload: count how many examples require human review and measure resulting delay or cost. Full system quality: evaluate what happens to abstained cases; lower model only selective risk is not enough if the fallback process fails. Python illustration Applications and limitations Applications: customer support routing, document classification, quality inspection, and high stakes decision support with a qualified human fallback. Confidence can be misleading: an overconfident wrong prediction may still be accepted. Check calibration and the ability of confidence to distinguish correct from incorrect predictions. Selection bias: the accepted subset becomes easier as coverage falls. Always report risk with coverage; comparing risk alone is unfair. Threshold selection: use a representative validation set to select the operating point. Then report held out performance and uncertainty; avoid tuning on the final test set. Review capacity: a stricter threshold may reduce automated errors but generate an unsustainable manual queue. Fairness and shift: acceptance rates and errors can differ by subgroup or change after deployment; monitor both. Zero acceptance: when no cases are accepted, empirical selective risk has a zero denominator and is undefined. Key takeaway: Selective classification allows “ I am not confident enough to decide .” It trades automatic coverage for potentially lower error among the predictions it does return. References El Yaniv & Wiener (2010), Foundations of Selective Classification Geifman & El Yaniv (2017), Selective Classification for Deep Neural Networks
What is a risk–coverage curve in selective classification?
A risk–coverage curve shows how a classifier's error rate among accepted predictions changes as the system accepts more or fewer examples. It is especially useful for deciding whether a model can automate a target percentage of cases while keeping mistakes within an acceptable range. Construct a risk–coverage curve For each labeled evaluation example, record its model confidence or selection score and whether its prediction is correct. Sort examples from highest to lowest selection score . At each accepted prefix size k , compute coverage = k/N and selective risk = (number of errors among the first k) / k for zero–one error loss. Plot coverage on the x axis and selective risk on the y axis . Lower curves indicate fewer errors at comparable coverage. Beginner friendly numerical example: 5 support tickets Here are five predictions, already sorted by decreasing confidence: Ticket 1: confidence 0.98 — correct . Ticket 2: confidence 0.91 — correct . Ticket 3: confidence 0.84 — incorrect . Ticket 4: confidence 0.72 — correct . Ticket 5: confidence 0.55 — incorrect . Step 1 — Accept only Ticket 1: coverage 1/5 = 20% ; errors 0/1 → selective risk 0% . Step 2 — Accept Tickets 1–2: coverage 2/5 = 40% ; errors 0/2 → risk 0% . Step 3 — Accept Tickets 1–3: coverage 3/5 = 60% ; errors 1/3 → risk 33.3% . Step 4 — Accept Tickets 1–4: coverage 4/5 = 80% ; errors 1/4 → risk 25% . Step 5 — Accept all five: coverage 5/5 = 100% ; errors 2/5 → risk 40% . The curve need not rise monotonically : adding a correct, lower confidence example can reduce the running error fraction, as occurs between 60% and 80% coverage. Area Under the Risk–Coverage Curve (AURC) AURC summarizes selective risk across coverage levels . Lower AURC is better for the same evaluation task and loss definition. A common finite sample convention computes AURC ≈ (1/N) × Σₖ₌₁ᴺ risk(k/N) , treating each accepted prefix risk as representing one coverage interval. For these five tickets: AURC ≈ (0 + 0 + 1/3 + 1/4 + 2/5)/5 = 0.1967 , or approximately 19.7% . Numerical AURC estimates can differ by interpolation, normalization, tie handling, and integration conventions. Always state the calculation method. AURC reflects both the base classifier's error rate and its confidence ranking: comparisons across models with different accuracies need care. Python example Selecting an operational threshold Start with an operational constraint , such as “human reviewers can inspect no more than 40% of tickets” or “accepted error should stay below 5%.” Use separate validation data to find the largest feasible coverage satisfying the risk or review capacity requirement; choose the corresponding confidence threshold. Confirm the choice on an untouched test set and report risk/coverage uncertainty rather than trusting a small sample point estimate. Evaluate downstream processing of abstained items: human review errors, delay, and cost belong in the full system evaluation. Limitations and practical applications Risk on accepted cases is conditional: it does not measure quality or workload for rejected cases. Not monotonic in small samples: an operating point chosen from a noisy curve can fail on unseen data. Ties: identical confidence scores can prevent reaching some exact coverages using a simple threshold. State how ties are handled. Confidence may not predict correctness well: a highly confident error creates elevated risk even at low coverage. Data shift and subgroup behavior: selection risk may worsen on new data or differ across groups; track coverage and error rate together. Applications: automated document processing, customer support routing, visual quality inspection, and regulated decision support with human escalation. Key takeaway: A risk–coverage curve shows the price of automating more cases in terms of mistakes among the accepted cases. AURC summarizes the full trade off but cannot replace choosing an operational threshold. References Geifman et al. (2019), SelectiveNet: A Deep Neural Network with an Integrated Reject Option TorchUncertainty AURC documentation
What is the difference between uncertainty estimation and confidence scoring in classification?
Confidence scoring assigns a number indicating how strongly a classifier favors a prediction. Uncertainty estimation tries to characterize how unsure a prediction is—and, with appropriate methods, why. A softmax based confidence is a useful score , but it is not by itself a reliable estimate of every kind of uncertainty. Beginner friendly numerical example: three classes Consider predictions for Cat, Dog, Bird . Photo A: probabilities [0.80, 0.10, 0.10] . The maximum softmax probability (MSP) is 0.80 , so the model strongly favors Cat. Photo B: probabilities [0.50, 0.25, 0.25] . MSP is 0.50 , suggesting less confidence about Cat. Step 1 — Maximum softmax probability: MSP = max(class probabilities). Photo A: 0.80 . Photo B: 0.50 . Step 2 — Predictive entropy: measure the uncertainty spread over all classes: H(p) = −Σ pᵢ log₂(pᵢ) , where 0 log 0 is defined as zero. Photo A: −[0.8 log₂ 0.8 + 0.1 log₂ 0.1 + 0.1 log₂ 0.1] ≈ 0.922 bits . Photo B: −[0.5 log₂ 0.5 + 0.25 log₂ 0.25 + 0.25 log₂ 0.25] = 1.500 bits . For three classes, maximum entropy is log₂ 3 ≈ 1.585 bits , reached at equal probabilities. Interpretation: Photo B has lower top class confidence and higher overall uncertainty. MSP only looks at the winning class, while entropy reflects the whole probability distribution . Why entropy can reveal something MSP cannot Two three class predictions might both have maximum probability 0.60 . Distribution [0.60, 0.40, 0.00] has entropy ≈ 0.971 bits . Distribution [0.60, 0.20, 0.20] has entropy ≈ 1.371 bits . Their MSP scores match, but entropy shows the second prediction spreads more uncertainty across alternatives. Entropy is a summary , not proof the classifier knows which outputs it should trust. What can uncertainty aware methods estimate? Predictive uncertainty: uncertainty in the predicted class distribution; softmax entropy is one simple proxy. Aleatoric (data) uncertainty: irreducible ambiguity or noise, such as an obscured photo or genuinely overlapping categories. Epistemic (model) uncertainty: uncertainty from limited training evidence or uncertainty about model parameters; more representative training data may reduce it. Ensembles, Bayesian methods, or repeated stochastic predictions can help investigate model uncertainty by comparing outputs across plausible models. A single softmax vector generally cannot disentangle aleatoric and epistemic uncertainty. Python example For exact zeros, use a safe entropy implementation (such as scipy.stats.entropy) to handle 0 log 0 . Selective classification: how to use these scores A review workflow may accept high MSP predictions or accept low entropy predictions , and abstain on the rest. Fit the operating rule using validation data and compare coverage, accepted set error, and risk–coverage performance on a held out test set. Score choice matters: different signals can order uncertain cases differently, affecting which examples are sent to review. A low entropy does not guarantee correctness: out of distribution inputs and overconfident mistakes can appear extremely certain. Evaluation, applications, and limitations Error detection: assess whether an uncertainty score identifies incorrect predictions using AUROC or area under the risk–coverage curve; specify which direction means greater uncertainty. Probability reliability: use held out calibration diagnostics and proper scoring rules, but remember calibration and uncertainty type decomposition are different questions. Distribution shift: test on challenging and out of distribution data where possible. Applications: medical image triage, document routing, quality inspection, and labeling queues. Limitations: MSP and entropy depend on class count and probability quality; softmax confidence can be misleading, and neither score guarantees a separation between reducible and irreducible uncertainty. Operational trade off: a human fallback has costs, so evaluate errors and review workload. Key takeaway: Confidence is often a scalar model preference score; uncertainty estimation is the broader task of quantifying and understanding predictive doubt. Entropy uses all class probabilities, but richer methods are needed to distinguish model and data uncertainty. References Hendrycks & Gimpel (2017), A Baseline for Detecting Misclassified and Out of Distribution Examples A survey of uncertainty in deep neural networks
What is predictive entropy in classification, and how is it calculated?
Predictive entropy measures how spread out a classifier's probability distribution is across its possible classes. It is the Shannon entropy of the predicted class probabilities : a single nearly certain class gives low entropy; an even distribution gives high entropy. Formula For K classes with probabilities p₁ through pₖ (each nonnegative, summing to 1): H(p) = −Σᵢ pᵢ log₂(pᵢ) , measured in bits . Treat 0 × log₂(0) as 0 (its limiting value), rather than attempting to calculate log(0). Using natural logarithms gives nats instead. Choose one base and use it consistently. Step by step numerical examples: three classes Imagine a model classifying an image as Cat, Dog, or Bird. Example A — Fairly confident: p = [0.80, 0.10, 0.10] 1. Contributions: −0.80 log₂(0.80) ≈ 0.2575 ; each −0.10 log₂(0.10) ≈ 0.3322 . 2. Add: H ≈ 0.2575 + 0.3322 + 0.3322 = 0.9219 bits . 3. Interpretation: most probability goes to Cat, so entropy is relatively low. Example B — More uncertain: p = [0.50, 0.25, 0.25] 1. Contributions: −0.50 log₂(0.50) = 0.50 ; each −0.25 log₂(0.25) = 0.50 . 2. Add: H = 0.50 + 0.50 + 0.50 = 1.50 bits . 3. Interpretation: the prediction distributes probability among more plausible alternatives. Example C — Uniform: p = [1/3, 1/3, 1/3] 1. Each contribution is −(1/3) log₂(1/3) ≈ 0.5283 . 2. Add: H = log₂(3) ≈ 1.5850 bits , the maximum possible for three classes. Example D — Certain: p = [1, 0, 0] H = 0 bits because the distribution assigns all mass to one class. This describes the model's output , not a guarantee that its prediction is correct. Normalizing entropy across class counts With K ≥ 2 , normalized entropy = H(p) / log₂(K) . For Example A: 0.9219 / 1.5850 ≈ 0.582 (58.2% of the maximum possible entropy for three classes). For Example B: 1.50 / 1.5850 ≈ 0.946 . Uniform predictions yield 1 , and fully concentrated predictions yield 0 . Normalization helps display values on a shared 0 to 1 scale , but it does not make uncertainty across fundamentally different classification tasks directly equivalent . For K = 1, the denominator is zero, so normalized entropy is undefined. Python example Numerical stability Do not evaluate p log(p) naively at p = 0; it can produce NaN. Use scipy.stats.entropy, scipy.special.xlogy, or explicitly mask positive probabilities. Ensure probabilities are finite, nonnegative, and sum to one (up to floating point tolerance). A probability vector is not a raw logit vector. If computing entropy from logits, first use a numerically stable softmax such as scipy.special.softmax rather than directly exponentiating huge scores. Applications and limitations Applications: ranking cases for human review, flagging ambiguous image/document classifications, active learning, and inspecting predictive distributions. Higher entropy is not always higher error: a confidently wrong model can have low entropy; evaluate whether entropy predicts mistakes on representative labeled data. Class count dependence: the upper bound grows as log₂(K). Report K, log base, and normalization when comparing models. No separation of uncertainty sources: predictive entropy of one model's output does not, by itself, distinguish noise driven uncertainty from uncertainty due to limited model knowledge. Shift sensitivity: entropy may fail to flag unfamiliar or out of distribution inputs. Validate on realistic challenging examples. Key takeaway: Predictive entropy converts the entire predicted probability vector into an uncertainty summary, ranging from 0 to log₂(K) bits . References SciPy entropy documentation Shannon (1948), A Mathematical Theory of Communication