A bank’s model predicts which customers will say yes to an offer, and it’s 89.5% accurate. Is that good? On the same customers, a “model” that always says no is 88.3% accurate. To judge a classifier you need to see how it ranks people, how that changes when the thing you’re looking for is rare, and whether its “70% likely” really means 70%. Three questions, three tools: curves for ranking, average precision for rare yeses, calibration for honest chances.
One number hides the trade-off#
The data is real: 3,000 customers of a Portuguese bank that phoned people to sell a term deposit (the UCI Bank Marketing data). 351 of them, 11.7%, said yes. Three models trained on other customers give each one a chance of a yes, and the bank calls everyone above a threshold. If the four outcomes (true and false yeses and noes) are new to you, start with the confusion matrix explainer linked at the end; here we look at what to do with them.
Predict first
Gradient boosting, the best of the three models, gets 89.5% of the customers right at the usual 50% threshold. What accuracy does a model get if it just says no to everyone?
At 50%, gradient boosting makes 139 calls and 63% of them end in a yes, but three quarters of the people who would have said yes never hear from the bank. Drop the threshold to 10% and it makes 853 calls and finds 246 of the 351 yeses, 70%, while accuracy falls to 76%. Whether that’s better depends on what a call costs and what a yes is worth, not on accuracy, which here punishes exactly the calls the bank wants to make.
Every threshold at once#
Instead of picking one threshold to judge a model, draw what happens at all of them. Sort the customers by score and walk down the list, calling one more person at each step. The yellow dot in the figure is where your threshold puts you on that walk.
- The ROC curve plots the share of yeses found against the false alarm rate, the share of noes you’ve called too. A model guessing at random walks up the dashed diagonal. The area under the curve (ROC AUC) has a neat meaning: the chance that a random customer who said yes got a higher score than a random one who said no. Gradient boosting scores 0.80.
- The precision-recall curve plots the share of calls that succeed against the share of yeses found. Random guessing gives a flat line at 11.7%, the share of yeses. Its summary is average precision (AP): the precision you’d see as you work down the list, averaged over each yes you find. Gradient boosting scores 0.46.
Both say the same thing about which model is best here: boosting, then logistic regression (0.79 and 0.43), then naive Bayes (0.75 and 0.31). Differences of 0.01 between models can flip on a different sample of customers, so before trusting a small gap, check it with cross-validation.
When the yeses get rare#
The two summaries can disagree badly, though, and the reason is how rare the yeses are. Fraud, disease and faults are often much rarer than 1 in 8.5.
Predict first
Keep the same models and scores, but leave out most of the yeses so that only 1 customer in 100 said yes. What happens to the ROC area?
The ROC curve barely notices, because its false alarm rate divides by the number of noes, and with 2,649 noes a few hundred false alarms is a small rate. Precision feels every one of them: when yeses are 1 in 100, even a good model’s calls are mostly wasted. When the thing you’re looking for is rare, judge models by precision-recall and average precision, not ROC area alone. The ROC area is still useful for comparing models on the same data; it just can’t tell you whether the calls will be worth making.
Does 70% mean 70%?#
Ranking is one job. Sometimes you need the chance itself: to work out expected profit, to show a risk score to a doctor, or to combine it with costs. Then you need the model to be calibrated: of all the customers it gives 70%, about 70% should say yes.
Predict first
Naive Bayes gave 374 of the 3,000 customers a 99% chance of saying yes. How many of them said yes?
A calibrated model’s dots sit on the dashed line. Naive Bayes’s don’t: the big dot at 99% sits at 39%. Two scores sum this up. The Brier score is the average squared gap between the chance given and what happened (1 for yes, 0 for no). Log loss is the average surprise, −log of the chance the model gave to what really happened; it punishes confident mistakes hardest.
The fix here is Platt scaling, named after John Platt, who used it for support vector machines: fit a small logistic regression that maps the model’s scores to chances, on customers it wasn’t trained on. Switch to “After calibration”: naive Bayes’s log loss falls from 0.92 to 0.34 and its Brier score from 0.159 to 0.099, while its ROC area stays at 0.73, because the fix moves the chances but never the order. Gradient boosting was honest already, so calibrating it changes almost nothing (Brier 0.089 before, 0.090 after).
In code#
The same data and the same three ideas with scikit-learn, free and local (pip install scikit-learn pandas; the first run downloads the data from OpenML):
from sklearn.calibration import CalibratedClassifierCV
from sklearn.datasets import fetch_openml
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.metrics import accuracy_score, average_precision_score, brier_score_loss, roc_auc_score
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
import pandas as pd
bank = fetch_openml("bank-marketing", version=1, as_frame=True)
X = pd.get_dummies(bank.data.drop(columns=["V12"])) # V12 is the call's length: only known afterwards
y = (bank.target == "2").astype(int) # 2 = said yes to the term deposit
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, stratify=y, random_state=0)
models = {
"boosting": HistGradientBoostingClassifier(random_state=0),
"naive Bayes": GaussianNB(),
"naive Bayes, calibrated": CalibratedClassifierCV(GaussianNB(), method="sigmoid", cv=5),
}
print(f"always 'no': accuracy {1 - y_test.mean():.3f}")
for name, model in models.items():
p = model.fit(X_train, y_train).predict_proba(X_test)[:, 1]
print(f"{name}: accuracy {accuracy_score(y_test, p >= 0.5):.3f}, ROC AUC {roc_auc_score(y_test, p):.3f}, "
f"average precision {average_precision_score(y_test, p):.3f}, Brier {brier_score_loss(y_test, p):.3f}")
# always 'no': accuracy 0.883
# boosting: accuracy 0.895, ROC AUC 0.799, average precision 0.453, Brier 0.081
# naive Bayes: accuracy 0.838, ROC AUC 0.752, average precision 0.363, Brier 0.145
# naive Bayes, calibrated: accuracy 0.883, ROC AUC 0.752, average precision 0.366, Brier 0.091Look at the last line: once calibrated, naive Bayes never gives anyone more than 50%, so at the default threshold it calls nobody and its accuracy becomes exactly the “always no” score. Its ROC area doesn’t move. method="sigmoid" is Platt scaling; scikit-learn’s calibration_curve gives you the points for the calibration chart.
What to remember
- Accuracy hides the trade-off between finding more yeses and wasting calls; ROC and precision-recall curves show every threshold at once.
- When yeses are rare, the ROC area barely moves while average precision falls: judge rare-event models by precision and recall.
- If you use the chance itself, check calibration: a model can rank well and still say 99% when it means 40%, and Platt scaling fixes that without changing the ranking.