Bring the mental model from Logistic Regression; this page will reuse it instead of restarting from zero.
Machine Learning
Classification Metrics, Thresholds, and Calibration
Classification metrics turn scores into decisions, expose threshold tradeoffs, and check whether probabilities mean what they claim.
Concept Structure
Classification Metrics, Thresholds, and Calibration
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
Classification Metrics, Thresholds, and CalibrationConceptual Bridge
What should feel connected as you move through this page.
Classification metrics turn scores into decisions, expose threshold tradeoffs, and check whether probabilities mean what they claim.
The next edge should feel earned: use the demo prediction here before following Model Selection and Hyperparameter Search.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
You are here because a classifier rarely gives only "yes" or "no." It usually gives a score or probability first, then someone chooses a threshold that turns that score into an action.
Before this, know logistic regression and why train/dev/test separation matters. By the end, you should be able to explain why precision and recall trade off, why ROC and precision-recall curves sweep thresholds, and why a confident probability can still be badly calibrated.
Start with a spam filter, medical screen, fraud detector, or safety classifier. The model says:
I think this case has score .
That score is not yet the decision. If the threshold is , the case is positive. If the threshold is , the same case is negative. Changing does not retrain the model; it changes what kinds of mistakes you are willing to make.
Two mistakes matter:
- A false positive says "positive" when the true label is negative.
- A false negative says "negative" when the true label is positive.
Precision asks: among the cases we called positive, how many were truly positive? Recall asks: among the truly positive cases, how many did we catch?
Raising the threshold often increases precision because the model only accepts stronger positive scores. But it usually lowers recall because more true positives fall below the threshold. Lowering the threshold usually does the opposite.
Calibration asks a different question. If the model says on many examples, are about of those examples actually positive? A classifier can rank examples well and still be overconfident. A threshold can create a useful decision rule and still sit on top of probabilities that should not be trusted as frequencies.
Three caveats keep this honest:
- Choose thresholds on dev data, not test data. Test is for the final estimate after the threshold rule is fixed.
- No metric is universal. Precision, recall, F1, ROC AUC, PR AUC, and calibration each hide a different value judgment.
- Calibration is about probabilities, not only accuracy. A model can be accurate and still have probabilities that are too sharp or too timid.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
For binary labels and model scores , a threshold creates hard predictions
From those predictions, define the confusion counts:
Precision and recall are
F1 is their harmonic mean:
The harmonic mean is harsh when either side is small. That is useful when you want both "few false alarms" and "few misses," but it is not a replacement for a real utility or safety cost.
ROC curves sweep and plot true positive rate against false positive rate:
Precision-recall curves also sweep , but plot precision against recall. When positives are rare, precision-recall views often make the positive-class tradeoff easier to see than ROC views.
Calibration ignores the hard threshold and asks whether scores behave like probabilities. For a score bin , define
A perfectly calibrated model would satisfy for meaningful bins. A simple reliability-gap summary is
The Brier score keeps the probability scale directly:
The threshold changes decisions. Calibration changes what the scores mean. In a clean workflow, you learn the model on train, choose thresholds or calibration parameters on dev or cross-validation folds, and report final metrics once on test.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
y = np.array([1,1,1,1,1,0,0,0,0,0,0,0])
s = np.array([.93,.82,.74,.58,.41,.88,.63,.52,.37,.22,.18,.07])
t = 0.70
yhat = (s >= t).astype(int)
tp = int(np.sum((yhat == 1) & (y == 1)))
fp = int(np.sum((yhat == 1) & (y == 0)))
fn = int(np.sum((yhat == 0) & (y == 1)))
tn = int(np.sum((yhat == 0) & (y == 0)))
precision = tp / max(tp + fp, 1)
recall = tp / max(tp + fn, 1)
f1 = 2 * precision * recall / max(precision + recall, 1e-12)
brier = np.mean((s - y) ** 2)
bins = [(0.0, 0.25), (0.25, 0.50), (0.50, 0.75), (0.75, 1.0)]
ece = 0.0
for lo, hi in bins:
mask = (s > lo) & (s <= hi)
if np.any(mask):
conf = np.mean(s[mask])
acc = np.mean(y[mask])
ece += mask.mean() * abs(acc - conf)
print("confusion:", {"tp": tp, "fp": fp, "fn": fn, "tn": tn})
print("precision, recall, f1:", np.round([precision, recall, f1], 3))
print("brier, ece:", round(brier, 3), round(ece, 3))
The code mirrors the math. yhat = (s >= t) is the threshold step, the confusion counts create precision and recall, and the calibration bins compare average confidence to empirical accuracy.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Move the threshold and choose a score shape. Before revealing the metrics, predict the dominant issue: false alarms, misses, or probability calibration.
The bars show the confusion counts after reveal. The metric panel reports precision, recall, F1, Brier score, and a reliability gap. The point is not to worship one number. The point is to ask which decision cost, class balance, and probability meaning your metric is silently choosing for you.
Live Concept Demo
Explore Classification Metrics, Thresholds, and Calibration
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Classification Metrics, Thresholds, and Calibration should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Classification metrics turn scores into decisions, expose threshold tradeoffs, and check whether probabilities mean what they claim.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Classification Metrics, Thresholds, and Calibration should make visible.
Visual Inquiry
Make the image answer a mathematical question
Classification metrics turn scores into decisions, expose threshold tradeoffs, and check whether probabilities mean what they claim.
Which visible object should carry the first intuition?
Pick the cue that should make Classification Metrics, Thresholds, and Calibration easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Source for confusion-matrix-derived metrics such as precision, recall, F1, ROC AUC, and precision-recall evaluation.
Open sourceSource for the separation between probability estimation and decision thresholding.
Open sourceSource for calibration curves, reliability diagrams, and the meaning of calibrated probabilities.
Open sourceSource for modern neural networks often being miscalibrated and for temperature scaling as a post-hoc calibration method.
Open sourceClaim Review
Classification metrics turn scores into decisions, expose threshold tradeoffs, and check whether probabilities mean what they claim.
Claims without a substantive review badge still need exact source-support review.
sklearn-classification-metrics, sklearn-threshold-tuning, sklearn-probability-calibration, guo-modern-calibration
Use equation, code, and demo objects to check whether the source support is operational.
scikit-learn supports confusion-matrix metrics, ROC/PR evaluation, threshold tuning as a separate decision step, and calibration curves/reliability diagrams; Guo et al. support the warning that high accuracy or cross-entropy training does not guarantee calibrated probabilities.
Sources: scikit-learn User Guide: Classification metrics, scikit-learn User Guide: Tuning the decision threshold for class prediction, scikit-learn User Guide: Probability calibration, On Calibration of Modern Neural NetworksThis claim covers binary classification evaluation and calibration intuition; it does not certify a universal best metric, a deployment-specific utility function, multiclass averaging choices, or medical/legal safety thresholds.A bounded review summary is present; still check caveats and exact source scope.Substantively reviewed after GPT Pro found one blocker: pre-reveal demo-state leakage of hidden metrics into the companion path. Fixed emitDemoState so metrics appear only after reveal, aligned reliability-bin wording, and kept source support tied to scikit-learn metrics/threshold/calibration docs plus Guo et al. Caveats: binary classification teaching setup only; no universal metric or deployment threshold guarantee.
Reviewer: gpt-pro; reviewed 2026-06-28Source support candidates
documentation 2026scikit-learn User Guide: Classification metricsSource for confusion-matrix-derived metrics such as precision, recall, F1, ROC AUC, and precision-recall evaluation.
documentation 2026scikit-learn User Guide: Tuning the decision threshold for class predictionSource for the separation between probability estimation and decision thresholding.
documentation 2026scikit-learn User Guide: Probability calibrationSource for calibration curves, reliability diagrams, and the meaning of calibrated probabilities.
paper 2017On Calibration of Modern Neural NetworksSource for modern neural networks often being miscalibrated and for temperature scaling as a post-hoc calibration method.
Practice Loop
Try the idea before it explains itself
Classification metrics turn scores into decisions, expose threshold tradeoffs, and check whether probabilities mean what they claim.
Before touching the demo, predict one visible change that should happen in Classification Metrics, Thresholds, and Calibration.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Classification Metrics, Thresholds, and Calibration
What is the smallest example that makes Classification Metrics, Thresholds, and Calibration click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:machine-learning/classification-metrics-calibration.
- Source ids to inspect: sklearn-classification-metrics, sklearn-threshold-tuning, sklearn-probability-calibration, guo-modern-calibration
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Classification Metrics, Thresholds, and Calibration Object key: concept:machine-learning/classification-metrics-calibration Context: Machine Learning Anchor id: concept/concept-notebook/machine-learning/classification-metrics-calibration Open question: What is the smallest example that makes Classification Metrics, Thresholds, and Calibration click without losing the math? Evidence to inspect: - Source ids to inspect: sklearn-classification-metrics, sklearn-threshold-tuning, sklearn-probability-calibration, guo-modern-calibration - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/machine-learning/classification-metrics-calibration
concept:machine-learning/classification-metrics-calibration