ML fundamentals7 / 22

Lesson 7 · Will it work on new data?

Measuring success

The problem

The pizza shop wants to text customers whose pizza will probably be late, so they aren't left waiting and wondering. In this year's records, a delivery counts as late if it takes more than 45 minutes (a different cut-off from the 300-row table's 30 minutes).

In the first nine months, the shop made 900 deliveries and 93 of them were late: about 10%. (Later in the year a second branch opened and lateness jumped. That part of the year comes back in the lesson on evaluation you can trust.)

Someone proposes a model that needs no training at all: it says "on time" for every delivery.

Predict first

10% of deliveries are late. A model always says 'on time'. What share of deliveries does it get right?

For a real model, we use logistic regression. It has four features: distance, traffic, rain, and whether the order was sent in the rush (18:00 to 19:59). It gives each delivery a probability of being late. Each delivery's probability comes from 5-fold cross-validation: the model that scored a delivery never saw it in training. The model warns a customer when that probability is at least 0.5.

Always says “on time”

The lazy model: 0 true positives, 93 false negatives, 0 false positives, 807 true negatives.
Model predicted
Actuallylateon time
late
0true positive
93false negative
on time
0false positive
807true negative
Accuracy
89.7%
Precision
–
Recall
0%

Logistic regression, threshold 0.5

Confusion matrix of 900 examples: 57 true positives, 36 false negatives, 19 false positives, 788 true negatives.
Model predicted
Actuallylateon time
late
57true positive
36false negative
on time
19false positive
788true negative
Accuracy
93.9%
Precision
75%
Recall
61.3%

Rows: what really happened. Columns: what the model said. ✓ right, ✗ wrong.

The lazy model and logistic regression on the same 900 deliveries. Each table counts the four ways an answer can come out.

The share of answers a classifier gets right is its accuracy. The lazy model scores 89.7%. Logistic regression scores 93.9%, only about 4 points more. Yet one of them catches 57 late pizzas and the other catches none.

Accuracy misleads here because late deliveries are rare. When one class is much rarer than the other, we have class imbalance. Fraud, disease and machine faults are all like this. The rare class is usually the one you care about. With imbalance, a model can score high accuracy by ignoring the rare class completely.

The confusion matrix

Accuracy squashes everything into one number. To see what went wrong, count the four kinds of answer separately. Call "late" the positive class, because it's the one we're looking for.

  • True positive (TP): late, and the model said late. A useful warning.
  • False positive (FP): on time, but the model said late. A false alarm.
  • False negative (FN): late, but the model said on time. A missed late pizza.
  • True negative (TN): on time, and the model said on time.

"True" and "false" say whether the model was right. "Positive" and "negative" say what it predicted. This 2×2 table of counts is the confusion matrix. Its rows are what happened, and its columns are what the model said.

In the figure above, the lazy model has 93 false negatives and no true positives at all. Logistic regression has 57 true positives, 19 false alarms and 36 misses.

Precision and recall

Two questions matter to the shop, and the confusion matrix answers both.

  1. When we send a warning, how often is the pizza late? Too many false alarms, and customers stop trusting the texts.
  2. Of the late pizzas, how many did we warn about? Each miss is an annoyed customer.

The first is precision: of the deliveries flagged late, the share that were late. The second is recall: of the late deliveries, the share that were flagged.

Worked example

Precision and recall from 100 deliveries

  1. Take 100 deliveries, 10 of them late. A model warns 12 customers. 8 of those pizzas are late (TP = 8) and 4 are on time (FP = 4).

In symbols:

precision=TPTP+FP,recall=TPTP+FN.\text{precision} = \frac{TP}{TP + FP}, \qquad \text{recall} = \frac{TP}{TP + FN}.

Both have TP on top. Precision divides by everything the model flagged (the "said late" column). Recall divides by everything that was truly late (the "late" row). In the language of conditional probability, precision is P(late | warned) and recall is P(warned | late). Swapping the two is a common mistake.

For logistic regression at 0.5: precision is 57/76=75%57 / 76 = 75\% and recall is 57/93=61%57 / 93 = 61\%. The lazy model never flags anything, so its recall is 0. (Its precision is 0 divided by 0, which scikit-learn reports as 0.)

Sometimes you want one number that is high only when both are high. The F1 score is their harmonic mean:

F1=2⋅precision⋅recallprecision+recall=2 TP2 TP+FP+FN.F_1 = \frac{2 \cdot \text{precision} \cdot \text{recall}}{\text{precision} + \text{recall}} = \frac{2\,TP}{2\,TP + FP + FN}.

In the worked example it's 16/(16+4+2)=0.7316 / (16 + 4 + 2) = 0.73. For the model at 0.5 it's 0.67. A harmonic mean sits close to the smaller of the two numbers: precision 100% with recall 2% gives F1 of only 0.04.

Moving the threshold

The model doesn't say "late" or "on time". It says a probability, and the shop chose to warn when it's at least 0.5. That cut-off is the decision threshold. Nothing forces it to be 0.5.

Predict first

The shop lowers the threshold from 0.5 to 0.3. What happens to precision and recall?

Slide the threshold and watch the counts move.

Confusion matrix of 900 examples: 57 true positives, 36 false negatives, 19 false positives, 788 true negatives.
Model predicted
Actuallylateon time
late
57true positive
36false negative
on time
19false positive
788true negative
Accuracy
93.9%
Precision
75%
Recall
61.3%
F1
67.5%
00.20.40.60.8100.20.40.60.81false-positive ratetrue-positive raterandom guessAUC = 0.97

logistic regressionthreshold 0.52

The shop warns 76 customers. 57 of them really get a late pizza; 36 late pizzas get no warning.

Drag the slider, or the dot along the curve. True-positive rate is recall; false-positive rate is the share of on-time deliveries warned.

Logistic regression's warnings at any threshold: the confusion matrix with accuracy, precision, recall and F1, and the ROC curve. The dot marks the lowest score still warned at this threshold.

Things to notice:

  • At 0.9 the shop sends only 16 warnings, and 15 are right: 94% precision. But it catches only 15 of 93 late pizzas: 16% recall.
  • At 0.1 it catches 88 of 93 (95% recall), but sends 190 warnings, and more than half are false alarms (46% precision).
  • Accuracy barely moves. It stays between 88% and 94% for every threshold from 0.1 to 0.95. It can't see the trade the shop cares about.
  • F1 peaks in the middle, around a threshold of 0.3 (0.71 there).

Which threshold is best depends on what each mistake costs, not on the model. A false alarm costs a customer a moment of worry. A missed late pizza costs an angry phone call. If misses are three times as bad, a lower threshold makes sense.

DigressionWhich metric? Count the cost of each mistakePut a price on a false alarm and on a miss, and the best threshold falls out. · 2 min

Say a false alarm costs the shop £1, for a voucher to say sorry for the worry. A missed late pizza costs £5, for a refund. The cost of a threshold is

cost=1×FP+5×FN.\text{cost} = 1 \times FP + 5 \times FN.

At 0.5: 19+5×36=£19919 + 5 \times 36 = £199. At 0.3: 38+5×21=£14338 + 5 \times 21 = £143. At 0.1: 102+5×5=£127102 + 5 \times 5 = £127. With these prices, warning more people is cheaper, even with all those false alarms.

Change the prices and the answer changes. If a false alarm cost £5 too, then 0.5 costs 5×19+5×36=£2755 \times 19 + 5 \times 36 = £275 and 0.3 costs 5×38+5×21=£2955 \times 38 + 5 \times 21 = £295. Now 0.5 is the cheaper choice.

So the choice of metric is a business question first. Precision matters when acting on a flag is expensive (sending an engineer, blocking a card). Recall matters when a miss is expensive (a disease, a fraud). Ask what each mistake costs before you pick a number to optimise.

The ROC curve

Every threshold gives a different confusion matrix. To see them all at once, plot two rates for each threshold:

  • The true-positive rate: the share of late deliveries that got a warning. That's recall, TP/(TP+FN)TP / (TP + FN).
  • The false-positive rate: the share of on-time deliveries that got a warning, FP/(FP+TN)FP / (FP + TN).

Sweep the threshold from 1 down to 0. At 1, nobody is warned: both rates are 0. At 0, everyone is warned: both rates are 1. In between, the points trace the ROC curve. (ROC stands for "receiver operating characteristic", a name from radar engineering in the Second World War.)

A model that guesses at random warns late and on-time deliveries alike, so its two rates are equal: the diagonal. A perfect model reaches the top-left corner, catching every late pizza with no false alarms. The closer the curve hugs that corner, the better the model separates the two classes.

One number sums up the curve: the AUC, the area under it. Random guessing scores 0.5 and a perfect model 1. Logistic regression scores 0.968.

The AUC doesn't depend on any threshold. It asks how well the model's scores rank late deliveries above on-time ones. That makes it a good way to compare models before you've chosen a threshold.

DeeperAUC as a ranking chancePick one late and one on-time delivery at random. AUC is the chance the late one scored higher. · 3 min

There are 93 late and 807 on-time deliveries, so there are 93×807=75,05193 \times 807 = 75{,}051 ways to pick one of each. For each pair, ask: did the model give the late delivery the higher probability?

For logistic regression, the answer is yes for 72,644 pairs. And 72,644/75,051=0.96872{,}644 / 75{,}051 = 0.968: exactly the area under the ROC curve. (A tie counts as half; there are none here.)

Why are they the same? Walk down the ROC curve one delivery at a time, from the highest score. Each late delivery you pass moves the curve up by 1/931/93. Each on-time delivery moves it right by 1/8071/807.

A step right adds a thin strip of area. Its height is the share of late deliveries already passed: the late deliveries that outrank this on-time one. Add up the strips and you've counted the winning pairs.

So an AUC of 0.968 means this. Show the model a random late delivery and a random on-time one. 96.8% of the time, it gives the late one the higher score.

When the positive class is rare: precision–recall curves

The ROC curve has a blind spot. Its two rates are each worked out within one class: recall within the late deliveries, and the false-positive rate within the on-time ones. So the curve doesn't change if late deliveries get rarer or more common. Precision does change, because it mixes the two classes.

To see this, keep every score the same, and pretend late deliveries were rarer by counting each on-time delivery several times. Then do the opposite.

ROC curve

00.20.40.60.8100.20.40.60.81false-positive ratetrue-positive raterandom guessAUC = 0.97

logistic regressionthreshold 0.52

Precision–recall curve

00.20.40.60.8100.20.40.60.81recallprecisionrandom guessaverage precision = 0.77

threshold 0.5

At threshold 0.5: recall 61% in every case · precision 75%

Same model, same scores. Only the number of on-time deliveries changes: each one counts 1.0 times.

The same scores in three worlds: half the deliveries late, 10.3% late (the real data), and 1% late. First the ROC curve, then precision against recall with its area (average precision). The dot is threshold 0.5.

Things to notice:

  • The ROC curve doesn't move. Its AUC is 0.968 in all three worlds.
  • The precision–recall curve sinks as late deliveries get rarer. Its area, called average precision, falls from 0.96 to 0.77 to 0.34.
  • At threshold 0.5, recall stays at 61%. But precision falls from 96% to 75% to 21%. With 1% late, four out of five warnings would be false alarms.

Why? At 1% late, there are about 99 on-time deliveries for each late one. Even a small false-positive rate, applied to that many on-time deliveries, makes a lot of false alarms. The ROC curve hides this, because 19 false alarms out of 807 on-time deliveries is only 2%.

So when the positive class is rare, look at precision and recall, or the precision–recall curve, as well as the ROC curve. The precision of a random guesser is the share of positives, so the dashed baseline drops with it.

Calibration: can you trust the probabilities?

So far we've used the probabilities only to rank deliveries and set a threshold. But the shop might want to text "there's a 70% chance your pizza will be late." For that, the number itself has to be right.

A model's probabilities are well calibrated if, of all the deliveries it gives about 70%, about 70% are late. This is calibration.

To check it, sort the deliveries into bins by their predicted probability: 0 to 0.2, 0.2 to 0.4, and so on. In each bin, compare the average prediction with the share that were late. Plot one against the other. This is a reliability diagram. A well-calibrated model sits on the diagonal.

For contrast, here's a common mistake. To deal with class imbalance, someone trains the same logistic regression with scikit-learn's class_weight="balanced". It counts each late delivery about 8.7 times as much as an on-time one in the loss. At 0.5, it now catches 86 of 93 late pizzas (92% recall, against 61%). That looks like an improvement.

00.20.40.60.8100.20.40.60.81predicted probabilityshare really lateperfectly calibratedsays 93%, really 66%

reweighted modelplain model

reweighted model: 109 deliveries got a probability between 0.8 and 1.0. On average it said 93%; 66% were really late.

Marker size grows with the number of deliveries in the bin. Points on the diagonal mean the probabilities can be taken at face value.

Reliability diagram for the plain model (solid) and for the reweighted one (dashed, class_weight='balanced'). Each marker is a bin of deliveries; its size shows how many. Pick a model and a bin to read its numbers; the pink line marks that bin's gap from the diagonal.

Things to notice:

  • The plain model sits near the diagonal. Deliveries it gives about 70% are late 68% of the time; about 89%, late 90% of the time. You can read its probabilities at face value. (Logistic regression trained with cross-entropy tends to be well calibrated.)
  • The reweighted model's probabilities are far too high. Deliveries it gives 93% are late only 66% of the time. Those it gives 70% are late only 28% of the time.
  • Its ranking is as good as before. Its AUC is 0.968, the same as the plain model's. The reweighting moved every probability up, but kept almost the same order.

So a model can rank well and still give wrong probabilities. AUC checks the ranking; a reliability diagram checks the probabilities. And class_weight="balanced" gave nothing that moving the threshold couldn't. The plain model at a threshold of 0.15 makes a similar trade: 84 caught and 73 false alarms, against 86 and 81. The reweighting cost the calibration.

If you need probabilities from a badly calibrated model, you can repair them. scikit-learn's CalibratedClassifierCV fits a small extra model on held-out data. It maps the scores to probabilities. Wrapped this way, the reweighted model's top bin says 88% instead of 93%, and 86% of those deliveries are late.

Few deliveries per bin

Only 93 deliveries were late, and most predictions are near 0. So the bins above 0.2 hold only 29 to 109 deliveries each, and their dots wobble by several points from noise alone. With rare classes, use few bins (scikit-learn's default is 5), and don't read much into a single bin.

Scoring numbers: MAE, RMSE and R²

The same question, "how good is it?", comes up when the model predicts a number. Here the confusion matrix has no meaning, because there are no classes. Instead, look at the misses: actual time minus predicted time.

  • MAE (mean absolute error): the average size of a miss, in minutes.
  • RMSE (root mean squared error): the square root of the mean squared error. The square root puts it back into minutes. It's always at least the MAE, and it grows faster when a few misses are large.
  • R² (R-squared): how much better than always guessing the average time. It's 1−MSE/MSE of the average1 - \text{MSE} / \text{MSE of the average}. A model that always predicts the average scores 0; a perfect model scores 1. A model worse than the average scores below 0.

Worked example

Four deliveries

  1. Four deliveries took 20, 30, 40 and 50 minutes. A model predicted 22, 28, 44 and 50. The misses are 2, 2, 4 and 0 minutes.

Now the same scores on the 900 deliveries, for a linear regression on the same four features.

01020304050600102030405060predicted minutesactual minutesperfect
MAE
3.0 min
RMSE
3.7 min
R²
0.88

Each dot is a delivery. The closer the dots hug the diagonal, the better.

Actual against predicted delivery time for 900 deliveries (each predicted by a model that never saw it). Switch to the baseline that always predicts the average.

The model misses by 3.0 minutes on average (MAE), with an RMSE of 3.7 minutes and an R² of 0.88. The average-only baseline misses by 8.6 minutes, and its R² is 0. MAE and RMSE are in minutes, which the shop understands. R² has no units, so it's handy for comparing across problems, but it says nothing about whether a 3-minute miss is acceptable.

In scikit-learn

The probabilities come from cross_val_predict with method="predict_proba". It runs the folds and returns, for each row, the prediction from the fold model that didn't train on it:

Out-of-fold probabilities
# Every delivery gets a probability from a model that never saw it: 5-fold cross-validation.
folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)


def out_of_fold_proba(model) -> np.ndarray:
    """P(late) for each delivery, each from the fold model trained without it."""
    return cross_val_predict(model, x, y, cv=folds, method="predict_proba")[:, 1]


p_late = out_of_fold_proba(LogisticRegression())

StratifiedKFold keeps the share of late deliveries about the same in every fold. With rare classes that matters: a plain split could leave a fold with almost no late deliveries.

The confusion matrix and the scores at three thresholds:

Confusion matrix, precision, recall and F1
def report(threshold: float) -> None:
    pred = (p_late >= threshold).astype(int)
    tn, fp, fn, tp = confusion_matrix(y, pred).ravel()  # rows: actual 0, 1; columns: predicted 0, 1
    precision, recall, f1, _ = precision_recall_fscore_support(y, pred, average="binary", zero_division=0)
    print(f"threshold {threshold}: TP {tp:3}  FP {fp:3}  FN {fn:3}  TN {tn:3}  "
          f"precision {precision:.1%}  recall {recall:.1%}  F1 {f1:.2f}")


for threshold in [0.5, 0.3, 0.1]:
    report(threshold)
threshold 0.5: TP  57  FP  19  FN  36  TN 788  precision 75.0%  recall 61.3%  F1 0.67
threshold 0.3: TP  72  FP  38  FN  21  TN 769  precision 65.5%  recall 77.4%  F1 0.71
threshold 0.1: TP  88  FP 102  FN   5  TN 705  precision 46.3%  recall 94.6%  F1 0.62
  • confusion_matrix(y, pred) puts the actual class in rows and the prediction in columns, negative class first. So .ravel() gives TN, FP, FN, TP, in that order. The figures in this lesson put "late" first; scikit-learn puts it last.
  • precision_recall_fscore_support(..., average="binary") returns precision, recall and F1 for the positive class (label 1). There are also separate precision_score, recall_score and f1_score functions.
  • zero_division=0 says what to report for 0 divided by 0, as for the lazy model's precision.

The ROC curve, its area, and average precision:

ROC curve and AUC
fpr, tpr, thresholds = roc_curve(y, p_late)  # one point per threshold, from (0, 0) to (1, 1)
print(f"ROC curve: {len(fpr)} points, AUC {roc_auc_score(y, p_late):.3f}")
print(f"average precision (area under the PR curve): {average_precision_score(y, p_late):.3f}")
ROC curve: 288 points, AUC 0.968
average precision (area under the PR curve): 0.772
  • roc_curve takes the scores, not the 0/1 predictions, and returns the false-positive rates, true-positive rates and thresholds. By default it drops points that lie on a straight line between their neighbours; pass drop_intermediate=False to keep one per threshold.
  • To draw it, use RocCurveDisplay.from_predictions(y, p_late), or PrecisionRecallDisplay for the precision–recall curve. Older tutorials use plot_roc_curve, which was removed in scikit-learn 1.2.

The three worlds of the precision–recall figure use sample_weight, which every scorer accepts:

Same scores, rarer late deliveries
def late_share_weights(share: float) -> np.ndarray:
    """Weights that make late deliveries `share` of the total, by counting each on-time one w times."""
    w = (y.sum() / (len(y) - y.sum())) * (1 - share) / share
    return np.where(y == 1, 1.0, w)


for share in [0.5, y.mean(), 0.01]:  # half, the real 10.3%, and 1%
    w = late_share_weights(share)
    auc = roc_auc_score(y, p_late, sample_weight=w)
    ap = average_precision_score(y, p_late, sample_weight=w)
    print(f"late share {share:5.1%}:  ROC AUC {auc:.3f}  average precision {ap:.3f}")
late share 50.0%:  ROC AUC 0.968  average precision 0.961
late share 10.3%:  ROC AUC 0.968  average precision 0.772
late share  1.0%:  ROC AUC 0.968  average precision 0.343

Calibration, and the one-line repair:

Reliability bins and CalibratedClassifierCV
balanced = out_of_fold_proba(LogisticRegression(class_weight="balanced"))  # counts a late delivery 8.7x an on-time one
for name, p in [("logistic regression", p_late), ("class_weight='balanced'", balanced)]:
    observed, predicted = calibration_curve(y, p, n_bins=5)  # 5 equal-width bins
    print(f"{name}\n  says   {np.round(predicted, 2)}\n  really {np.round(observed, 2)}")

# One line repairs the probabilities: fit a sigmoid from the model's score to the true rate.
repaired = out_of_fold_proba(CalibratedClassifierCV(LogisticRegression(class_weight="balanced"), method="sigmoid"))
observed, predicted = calibration_curve(y, repaired, n_bins=5)
print(f"repaired\n  says   {np.round(predicted, 2)}\n  really {np.round(observed, 2)}")
logistic regression
  says   [0.02 0.29 0.5  0.7  0.89]
  really [0.02 0.37 0.5  0.68 0.9 ]
class_weight='balanced'
  says   [0.02 0.31 0.48 0.7  0.93]
  really [0.   0.04 0.14 0.28 0.66]
repaired
  says   [0.03 0.28 0.49 0.7  0.88]
  really [0.02 0.29 0.54 0.79 0.86]
  • calibration_curve returns the share that were positive first, then the average prediction, one per non-empty bin. n_bins=5 is the default.
  • CalibrationDisplay.from_predictions(y, p) draws the reliability diagram.
  • CalibratedClassifierCV(model, method="sigmoid") trains the model on part of the data and fits the repair on the rest, fold by fold. method="isotonic" fits a more flexible repair; it needs more data.

Regression scores:

MAE, RMSE and R²
predicted_minutes = cross_val_predict(LinearRegression(), x, minutes, cv=KFold(5, shuffle=True, random_state=0))
baseline = np.full_like(minutes, minutes.mean())  # always predict the average time
for name, pred in [("linear regression", predicted_minutes), ("always the average", baseline)]:
    mae = mean_absolute_error(minutes, pred)
    rmse = root_mean_squared_error(minutes, pred)
    print(f"{name:20}  MAE {mae:.2f}  RMSE {rmse:.2f}  R² {r2_score(minutes, pred):.3f}")
linear regression     MAE 2.96  RMSE 3.65  R² 0.878
always the average    MAE 8.59  RMSE 10.44  R² 0.000

root_mean_squared_error is its own function in current scikit-learn. (Older code passes squared=False to mean_squared_error; that option has been removed.)

Putting it together

Here's how the shop should judge its warning model.

  1. Compare with the lazy baseline. "Always on time" scores 89.7% accuracy. The model's 93.9% is only 4 points better, so accuracy says almost nothing here.
  2. Read the confusion matrix. At 0.5: 57 useful warnings, 19 false alarms, 36 missed late pizzas.
  3. Turn it into precision and recall. 75% of warnings are right; 61% of late pizzas get one.
  4. Pick the threshold from the costs. If a miss costs five times a false alarm, a threshold near 0.1 to 0.3 is cheaper than 0.5.
  5. Check the ranking with AUC, 0.968, and with average precision, 0.77, since late deliveries are rare.
  6. Check calibration before quoting probabilities to customers. The plain model is close to the diagonal; the reweighted one isn't.

All of these numbers come from deliveries the model didn't train on. Scores on training data would flatter the model, as in the lesson on train, validation and test sets.

Common misconceptions

"90% accuracy means a good model." With 10% late deliveries, a model that never predicts "late" scores 90%. Always compare with that baseline, and look at recall for the rare class.

"Precision and recall are the same thing." Both have true positives on top. Precision divides by the deliveries flagged; recall divides by the deliveries that were late. A model that flags everyone has 100% recall and 10% precision.

"The threshold is part of the model, fixed at 0.5." It's a choice you make after training. Moving it trades precision against recall, and the right place depends on what each mistake costs.

"A high AUC means the probabilities are right." AUC checks only the order of the scores. The reweighted model has the same AUC as the plain one, but its 93% predictions come true only 66% of the time.

"The ROC curve shows how a model will do when positives are rare." The ROC curve doesn't change when positives get rarer. Precision does. At 1% late, the same model's precision at 0.5 drops from 75% to 21%.

"Reweighting the rare class fixes class imbalance." It moves every probability, which mostly does what moving the threshold would do, and it breaks the calibration. Try a lower threshold first.

Recap

  • Accuracy is the share of right answers. With class imbalance, a model that ignores the rare class still scores high, so compare against "always the common class".
  • The confusion matrix counts true positives, false positives, false negatives and true negatives.
  • Precision is TP / (TP + FP): how often a flag is right. Recall is TP / (TP + FN): how many positives get flagged. F1 combines them.
  • The decision threshold trades precision against recall. Choose it from the cost of each kind of mistake.
  • The ROC curve plots the true-positive rate against the false-positive rate for every threshold. Its area, AUC, is the chance a random positive outranks a random negative.
  • When positives are rare, the precision–recall curve shows what the ROC curve hides.
  • A calibrated model's probabilities come true at the rate they say. Check with a reliability diagram; repair with CalibratedClassifierCV.
  • For numbers: MAE and RMSE are typical misses in the label's units; R² compares the model with always guessing the average.
  • scikit-learn names in this lesson: cross_val_predict, StratifiedKFold, confusion_matrix, precision_recall_fscore_support, roc_curve, roc_auc_score, average_precision_score, RocCurveDisplay, calibration_curve, CalibrationDisplay, CalibratedClassifierCV, mean_absolute_error, root_mean_squared_error and r2_score.