From one point to the whole curve
A threshold metric grades one operating point; a curve grades the model's entire repertoire - useful when the threshold will be chosen later, tuned per campaign, or argued about in b5. Tonight's two curves are ROC (the classic) and PR (the honest one on rare events), and the session's first rule of thumb costs you nothing to adopt: on imbalanced problems, report both AUCs and trust the pessimistic one. The second half asks a question no curve answers: when Lumen's model says 0.8, does that session convert 80% of the time? Same 2,000-session slice, same seed 42, same evaluator below.
Two curves, two verdicts 8 min live
The ROC curve plots true positive rate against false positive rate at every threshold; its area, AUC, is ranking quality - the probability that a random converter is scored above a random non-converter. Elegant, threshold-free, and on imbalanced data, flattering. The trick is in FPR's denominator: FPR = FP / (FP + TN), and true negatives dominate it. Lumen's slice holds 1,936 non-converters, so the model can rack up dozens of wasted flags while FPR barely twitches - the curve glides along the top-left looking heroic. The PR curve replots the same thresholds as precision against recall, and precision has no TN term to hide behind: every wasted flag lands in its denominator. Same model, same scores, honest sag.
LiveThe paper that settled it: Saito & Rehmsmeier 20154 min▶
This is not folklore - it has a citation. Saito and Rehmsmeier (PLOS ONE, 2015) showed that ROC plots can deceive on imbalanced datasets while PR plots are more informative, and the reason is structural: precision is prevalence-sensitive and the ROC axes are not. TPR and FPR are each computed within one actual class, so the class ratio never enters the plot - a model looks identical on ROC whether positives are half the data or 3.2% of it. Precision mixes the classes in its denominator, so the PR curve feels the base rate directly. On rare-event problems - which b1 argued are MOST valuable classification problems - the curve that feels the base rate is the curve that matches production experience.
LiveThe interpolation trap sklearn warns you about4 min▶
One more honesty clause, straight from sklearn's own docs: linear interpolation between points on a PR curve is overly optimistic. Precision does not move linearly between measured thresholds the way ROC's axes do, so computing PR-AUC with the trapezoidal rule (as auc(recall, precision) happily will) credits the model for area it never earned. This is why average_precision_score exists and deliberately avoids trapezoids - it is a step-wise weighted mean of precisions, not a geometric area.
from sklearn.metrics import roc_auc_score, average_precision_score
scores = model.predict_proba(X_test)[:, 1]
roc_auc_score(y_test, scores) # ranking quality - flattering on imbalance
average_precision_score(y_test, scores) # PR-AUC done right: step-wise,
# no optimistic trapezoids
Two-line takeaway for your next review: PR-AUC computed by trapezoid is a small silent inflation on top of a metric you chose FOR its honesty. Use average_precision_score and the inflation never happens.
Self-studyWhere each curve still wins2 min read▶
Neither curve is retired. ROC-AUC remains the right single number when classes are roughly balanced, when you care about ranking across the full score range, or when comparing models across datasets with different base rates (its prevalence-blindness becomes a feature). PR-AUC wins whenever the positive class is rare and the flags are what you act on - fraud queues, outreach lists, alert triage. Google's crash course teaches ROC/AUC as the default lens; this session adds the imbalance asterisk that Lumen's 3.2% base rate makes mandatory.
Does 0.8 mean 80%? 10 min live
Everything so far treated model scores as a RANKING - higher means more likely. Calibration asks for more: that predict_proba be interpretable as confidence, so a 0.8 means roughly 80% of such sessions actually convert. The diagnostic is the reliability diagram: bin the predicted probabilities, plot each bin's mean prediction against its actual positive rate, and compare to the diagonal - the diagonal is perfect calibration. Points sagging below it mean overconfidence (the model says 0.8, reality delivers 0.55); bulging above means underconfidence. Many good rankers are badly calibrated - boosted trees and SVMs are famous offenders - so this is a check you run, not a property you assume.
LiveDiagnose, then repair: the sklearn calibration kit6 min▶
Diagnosis and repair are three calls apart:
from sklearn.calibration import (CalibratedClassifierCV,
CalibrationDisplay, calibration_curve)
# diagnose: binned predicted vs actual - the reliability diagram
prob_true, prob_pred = calibration_curve(y_test, scores, n_bins=10)
CalibrationDisplay.from_predictions(y_test, scores, n_bins=10)
# repair: wrap the model, refit the mapping on held-out folds
cal = CalibratedClassifierCV(model, method="isotonic", cv=5)
cal.fit(X_train, y_train) # cal.predict_proba is now the trusted one
Two repair methods, one selection rule:
- Platt scaling (
method="sigmoid") fits a logistic curve to the scores - two parameters, hard to overfit, the safe pick on small data or when the distortion looks sigmoid-shaped. - Isotonic regression (
method="isotonic") fits a free-form monotonic step function - more expressive, and hungry: sklearn's guidance is to reach for it with more than ~1,000 calibration samples, or it will happily overfit the wiggles.
Lumen's slice clears the isotonic bar on raw count - but remember the minority class: 2,000 sessions hold only ~64 converters, and calibration in the high-score bins is only as good as the positives available there. When in doubt, sigmoid first, isotonic when the reliability diagram shows a distortion the sigmoid cannot bend to.
LiveThe Brier caveat - sklearn's own warning4 min▶
The Brier score - mean squared error between predicted probabilities and 0/1 outcomes - looks like the obvious "calibration metric." Here is the caveat, and it is sklearn's calibration guide speaking, not a blog: a lower Brier score does NOT necessarily mean better calibration. Brier mixes two ingredients - calibration (do the probabilities match reality?) and discrimination (does the model separate the classes?) - into one number. A sharper, better-discriminating model can post a lower Brier than a more honest one; you cannot tell from the score alone which ingredient improved, or whether one improved at the other's expense.
Why b5 needs tonight's second half. The cost-matrix session ahead rests on Elkan-style reasoning: given error costs, the optimal threshold falls out of the predicted probability. That rule ASSUMES the probabilities are calibrated. Feed it an overconfident model's 0.8-that-means-0.55 and the "cost-optimal" threshold it computes is optimal for a fantasy - your dollar numbers will be confidently, precisely wrong. Calibrate first; then price. Teams that skip the reliability diagram do cost-sensitive learning on fiction.
The slider IS the curve ★ 15 min · everyone runs it
Here is tonight's quiet unification: the PR curve is not a new object - it is b2's dial with the trail left on. Every slider position below is ONE point on the PR curve. The evaluator computes Lumen's precision and recall live at each cut; you supply the tracing paper.
Walk five positions. Set the threshold to 0.1, 0.3, 0.5, 0.7, 0.9. At each stop, write the (recall, precision) pair. Then sketch the five points on paper with recall on the x-axis and connect them. You have just drawn Lumen's PR curve by hand - the sag from the diagram above should appear under your pencil, baseline hovering near the 3.2% prevalence floor at the high-recall end.
Watch what accuracy does on the same walk. Across those five stops, the accuracy tile barely moves - it sits near the base-rate ceiling the whole way - while your penciled curve swings across most of its range. That flat tile is ROC-thinking on a rare event: a summary dominated by the 1,936 easy negatives. Your sketch is PR-thinking: every point priced in flags and catches. On rare events, trust the view that moves.
Say the unification out loud. "A threshold metric is one point; a curve is every point; the model is the curve, not the point." If your five-point sketch makes that sentence feel obvious, you are ready for b4's ranking metrics - and for b5, where one of these points gets a dollar sign.
Which scoring function, previewed read after class
Tonight touched two members of a bigger doctrine sklearn's guide organizes cleanly: match the metric to what the model outputs. Predicting probabilities? Grade with proper scoring rules - Brier, log loss - which are minimized only by the true probabilities. Predicting hard classes? Grade with the zero-one family - accuracy, precision, recall, F-scores - the metrics of b1 and b2. The doctrine extends to regression (means want squared error, medians want absolute error, quantiles want pinball loss) - the full table is b4's opening act.
Self-studylog loss vs Brier, one paragraph2 min read▶
Both are proper scoring rules over predicted probabilities; they differ in temperament. Brier is squared error on probabilities: bounded between 0 and 1, forgiving at the extremes - a confident wrong answer costs at most 1. Log loss charges the negative log of the probability assigned to the truth: unbounded, and brutal at the extremes - predict 0.99 for the wrong class and the penalty explodes toward infinity. Track log loss when confident wrongness is the failure mode you most need to punish (it is also what logistic-family models optimize); track Brier when you want a stable, bounded probability-quality number. And carry tonight's caveat to both: neither one, alone, certifies calibration - the reliability curve does.
Try it yourself - this week ◐ 25-35 min total
- On a classifier you own, compute
roc_auc_scoreandaverage_precision_scoreside by side. Write one sentence on the gap - the more imbalanced your data, the wider it should feel. - Draw the reliability diagram for the same model with
CalibrationDisplay.from_predictions, 10 bins. Diagnose in one word: overconfident, underconfident, or honest. - If the diagram sags, wrap the model in
CalibratedClassifierCV(sigmoid on small data, isotonic past ~1,000 samples) and redraw. Keep the before/after pair - it belongs in your b10 eval sheet. - Find one report or vendor deck quoting a single ROC-AUC on a rare-event problem. Ask for the PR-AUC. Note the reaction.
Official sources covered
This session teaches the curve-and-calibration core: the key PLOS ONE paper on PR vs ROC, sklearn's calibration guide with its own Brier warning quoted in spirit, the PR-interpolation caveat from the metrics guide, and Google's ROC/AUC lesson - all drilled against Lumen's live scores. This page covers:
Three questions before you go 🎯 ◐ 90 seconds
1 · Why does the ROC curve flatter Lumen's model while the PR curve sags?
FPR = FP / (FP + TN), and TNs are 96.8% of the slice - the model can waste dozens of flags while FPR barely twitches. Precision is prevalence-sensitive (Saito & Rehmsmeier's point), so the PR curve matches production experience on rare events. Report both AUCs; trust the pessimist.
2 · What does a reliability diagram actually show?
Bin the predictions, compare each bin's mean prediction to its observed frequency. On the diagonal, 0.8 really means ~80%. Sag below = overconfidence, bulge above = underconfidence - and the repair kit is Platt sigmoid or isotonic via CalibratedClassifierCV.
3 · Model A posts a lower Brier score than model B. What can you conclude about calibration?
sklearn's own guide warns that a lower Brier does not necessarily mean better calibration - the score blends two ingredients and hides which one moved. Calibration is assessed with the curve; Brier and log loss track overall probability quality. b5's cost math trusts whichever answer you give here.