Skip to content

Lesson 7 of 9 · 25m

Metrics That Match the Decision

Choose classification and regression metrics based on cost, ranking, calibration, and action thresholds rather than default leaderboard habits.

Accuracy is the most socially acceptable bad metric in machine learning. It sounds intuitive, summarizes nothing about asymmetric cost, and collapses completely on imbalanced problems. Metrics are not scoring decorations. They are mathematical statements about which mistakes matter. If you choose the wrong one, you optimize the wrong product.

Start with the decision and the cost

A fraud model blocking users, a churn model ranking outreach, and a demand forecast ordering inventory have different failure costs:

false positive cost    user friction, analyst time, lost inventory efficiency
false negative cost    fraud loss, missed churn, stockout
ranking requirement    top-k precision, recall at capacity
probability use        thresholding, expected value, calibration

Write these down before opening a notebook. If nobody can explain the operational cost, the project is not ready for metric selection.

Confusion matrix is the floor

For binary classification, inspect the full matrix at the intended threshold:

from sklearn.metrics import confusion_matrix

pred = (prob >= 0.35).astype(int)
tn, fp, fn, tp = confusion_matrix(y_test, pred).ravel()
print({'tn': tn, 'fp': fp, 'fn': fn, 'tp': tp})

Precision answers: of the items we flagged, how many were correct? Recall answers: of the truly positive items, how many did we catch? Neither is universally better. They are tradeoffs under capacity constraints.

Ranking metrics ignore arbitrary thresholds

When the model ranks cases for review, threshold-independent metrics are useful:

from sklearn.metrics import average_precision_score, roc_auc_score

print('PR AUC:', average_precision_score(y_test, prob))
print('ROC AUC:', roc_auc_score(y_test, prob))

For imbalanced data, precision-recall curves are usually more informative than ROC curves. ROC can look healthy while precision at operational volume is miserable.

Calibration matters when probabilities feed decisions

A ranking model can order cases well while producing meaningless probabilities. If 0.8 does not correspond to roughly an 80% empirical outcome rate, expected-value logic breaks:

from sklearn.calibration import calibration_curve

frac_pos, mean_pred = calibration_curve(y_test, prob, n_bins=10)

Calibration depends on population mix. A model calibrated in one region or season may drift when acquisition channels change. Calibration is a production property, not a one-time badge.

Regression errors are not interchangeable

MAE measures typical absolute miss. RMSE penalizes large misses more strongly. MAPE fails near zero and is asymmetric in ways business stakeholders often misunderstand. Choose based on operational harm:

from sklearn.metrics import mean_absolute_error, mean_squared_error

mae = mean_absolute_error(y_test, pred)
rmse = mean_squared_error(y_test, pred) ** 0.5

Also inspect residual distributions. Aggregate metrics hide systematic underprediction for high-value segments.

Segment metrics before celebrating

A global number can hide harm or uselessness in the exact population that matters. Evaluate by country, device, account age, customer tier, or other operationally meaningful cohorts. Do not use segmentation as a post-hoc fishing expedition; define cohorts that map to decisions.

Field notes

  • Never compare models using different thresholds without stating the threshold policy.
  • PR AUC depends on class prevalence; compare within the same evaluation set.
  • Accuracy may still be useful when classes are balanced and costs are symmetric, but that is rare.
  • A confidence interval matters. A 0.002 metric improvement on a small test set is noise until proven otherwise.
  • Metric dashboards should show data volume next to scores; tiny segments produce theatrical variance.

Was this lesson helpful?

Sign in to rate