← capítulo

Beyond accuracy

A model that predicts "no diabetes" for everyone scores 65% on our test set — and learns nothing.

Accuracy is the first number everyone quotes and the first one that lies.

The scores, not the labels

A classifier hands you a probability, not a verdict. You choose where to cut.

The two classes overlap — and that overlap is every metric in this chapter.

Four counts, everything from them

TP=#{y^=1, y=1},FP=#{y^=1, y=0},FN=#{y^=0, y=1},TN=#{y^=0, y=0}\text{TP} = \#\{\hat{y}=1,\ y=1\}, \quad \text{FP} = \#\{\hat{y}=1,\ y=0\}, \quad \text{FN} = \#\{\hat{y}=0,\ y=1\}, \quad \text{TN} = \#\{\hat{y}=0,\ y=0\}

All unitless, all in [0, 1].

Watch the trade-off happen

Sweep the threshold 0 → 1. Confusion matrix, four metrics, and the ROC point move together.

Low threshold → recall 1, precision at the base rate. High threshold → the reverse.

No frame has every bar high. Where you stop is a decision about which mistake you'd rather make.

The curves

ROC bows above chance to AUC 0.83 — a random diabetic outranks a random healthy patient 83% of the time.

Scratch == library

Our NumPy metrics land on sklearn's to the last decimal — asserted every run.

Accuracy 0.77 — but recall 0.61 means it misses 31 of 80 diabetics. Same model, opposite story.

Takeaways