topskill.dev
CoursesTracks
All courses/Machine Learning FundamentalsThe confusion matrix
Understanding prediction errors
4 / 7
← Machine Learning Fundamentals
○What machine learning learns○Features and labels○Training and inference○Regression or classification○The machine learning process○Data quality and coverage○Representing data✦Module Quiz
○Linear regression○Try a tiny linear model○Logistic regression○Nearest neighbors○Decision trees○Random forests○Boosting○Naive Bayes○Support vector machines✦Module Quiz
○Clustering○K-means○Choosing and interpreting clusters○Principal component analysis○Neural networks and deep learning○Self-supervised learning○Transfer learning○Reinforcement learning✦Module Quiz
○Generalization and overfitting○Holding out evaluation data○Data leakage○Baselines○Bias and variance intuition○Reading learning curves✦Module Quiz
○Prediction errors and residuals○Measuring regression error○Squared error and large misses●The confusion matrix○Precision and recall○Try a held-out classifier✦Module Quiz
○Bias and limits○Monitoring and drift○Comparing models for a decision✦Module Quiz
Understanding prediction errors

The confusion matrix

For a late-trip classifier, call "late" the positive class. Positive names the class of interest; it does not mean good. A confusion matrix counts predictions against observed answers.

A true positive is a late trip correctly flagged. A false positive is an on-time trip incorrectly flagged, or a false alarm. A false negative is a late trip the model misses. A true negative is an on-time trip correctly left unflagged.

accuracy=correct predictionsall predictions=6+920=0.75\begin{aligned} \text{accuracy}&=\frac{\text{correct predictions}}{\text{all predictions}}\\ &=\frac{6+9}{20}=0.75 \end{aligned}accuracy​=all predictionscorrect predictions​=206+9​=0.75​

Accuracy is the fraction of all predictions that are correct. In this invented set it is 0.75, or 75%. The numerator counts both kinds of correct decision; the denominator counts every trip once.

Always read the axis labels. Some tools put actual classes in rows and others in columns. Our figure uses actual classes in rows. The four counts tell us more than accuracy alone: there are three unnecessary warnings and two missed delays, which may have different costs.

The circles isolate the two error groups from the matrix. The remaining 15 predictions are correct. Each circle counts one example; its position does not measure how many minutes late it was.

False positives and false negatives are classification outcomes, not positive and negative numerical residuals. In the matrix, a missed late delivery is a false negative regardless of how many minutes late it was. A separate regression target would be needed to measure the size of the delay.

Check your understanding

In this figure, what is a false negative?

Answer: One of the two trips that was actually late but was predicted on time.

Fact 1
1 / 1
FACT 1

One of the two trips that was actually late but was predicted on time.