AI Foundations for Developers COURSE·LESSON 10 OF 410 completed

Metrics and Decision Thresholds

Count the kinds of mistakes

For a binary classifier, a true positive is a correctly detected positive example; a false positive is an ordinary example incorrectly flagged. False negatives miss real positives, and true negatives correctly reject ordinary examples. Choose the positive class explicitly before calculating metrics.

Suppose Acorn's urgent-ticket detector yields 18 true positives, 6 false positives, 2 false negatives, and 74 true negatives in 100 tickets.

  • Accuracy: (18+74)/100 = 92%.
  • Precision: 18/(18+6) = 75%. Of flagged tickets, how many were actually urgent?
  • Recall: 18/(18+2) = 90%. Of truly urgent tickets, how many were found?
  • F1: 2×precision×recall/(precision+recall) ≈ 81.8%.
python
tp, fp, fn, tn = 18, 6, 2, 74
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1 = 2 * precision * recall / (precision + recall)
print(round(precision, 3), round(recall, 3), round(f1, 3))
# 0.75 0.9 0.818

Run it in the Python compiler. Production code must define what happens when a denominator is zero.

Thresholds are operational decisions

Lowering a positive threshold generally increases recall while admitting more false positives. Raising it generally improves selectivity while missing more positives. Select a threshold using validation data and the cost of errors, then evaluate it on test data.

A three-way policy is often useful: automatically accept high-confidence cases, send uncertain cases for review, and reject clear negatives. Measure review volume as well as accuracy.

ROC curves compare true-positive and false-positive rates across thresholds. Precision-recall curves are especially informative when positives are rare. AUC summarizes a curve; it does not choose a deployment threshold or prove calibration.

Regression and subgroup reporting

For numeric predictions, MAE measures average absolute error in the target's units. RMSE emphasizes large errors. Report performance on important slices: language, account type, input length, and accessibility needs. Macro averaging weights classes equally; micro averaging pools individual decisions and can be dominated by common classes.

Checkpoint with answers

Can two systems with the same accuracy behave differently? Yes. One may miss urgent tickets while another generates too many false alarms.

Exercise: You flag 50 tickets, 10 correctly. What is precision? Answer: 20%. Recall cannot be calculated without knowing the total number of real positives.

Should you tune a threshold using test data? No. Use validation data; keep test data for the final measurement.

Learn at your own pace0 / 41 lessons complete