Baseline Models and Dummy Classifiers
The second model is the opposite.
When Accuracy Hides the Failure
Accuracy asks one question: across all samples, how often was the prediction right? It is a useful starting point, but it can hide what matters most in a binary classification problem. A model can look reasonable on accuracy while still failing on the rare class you actually care about.
Throughout this article, the working example is a 'nine vs. rest' dataset. The goal is to recognize the digit nine among all other digits. The nine samples are the minority class. That imbalance is what makes accuracy a poor guide here, and it is what makes precision, recall, and F1 useful.
What do you think happens?
Suppose 10 percent of the test samples are nines and 90 percent are other digits. A model that always answers 'not nine' is trained on nothing and looks at nothing. What accuracy does it get?
Reveal answer
About 90 percent
A model that always predicts the majority class is right on every majority sample and wrong on every minority sample. Its accuracy therefore equals the majority share. Yet it has found zero nines, so its recall for the nine class is 0.
This kind of model is called a dummy classifier. It is a trivial baseline: it ignores the input features and follows a fixed rule, such as always predicting the most frequent class. Its purpose is not to be good. Its purpose is to set a floor that any real model must clear, and to expose what a headline number like accuracy can conceal.
The Confusion Counts Behind Every Metric
The confusion matrix breaks predictions into four counts: true positives, false positives, true negatives, and false negatives. Precision and recall are two of the most common ways to summarize those four counts, and both are built from the same pieces. A true positive is a positive sample the model correctly called positive. A false positive is a negative sample the model wrongly called positive. A false negative is a positive sample the model missed by calling it negative. A true negative is a negative sample correctly called negative.
Keep the positive class explicit. Every metric in this article is defined relative to one chosen positive class. Change which class is positive and every number changes.
What Precision Measures
Precision measures how many predicted positives are truly positive. It limits false positives: the mistakes where the model cries positive when the answer is negative.
- 1The numerator TP is the count of true positives, the samples that were predicted positive and really are positive.
- 2The denominator TP + FP is every sample the model labeled positive, both right and wrong.
- 3Precision therefore ignores the negatives the model got right, and it ignores positives the model missed. It only looks at what the model said was positive.
The source illustrates precision with a model that predicts whether a new drug will be effective in clinical trials. Clinical trials are expensive, so a pharmaceutical company only wants to run an experiment when it is very sure the drug works. The model therefore must not produce many false positives, which means it needs high precision. A model with high precision has few false positives.
What Recall Measures
Recall answers the opposite question. Instead of asking how many predicted positives are real, it asks how many of the real positive samples the model captured with its positive predictions. It limits false negatives: the mistakes where the model misses a positive sample.
- 1The numerator is again the true positives, which precision also uses.
- 2The denominator now contains the false negatives, the positive samples the model missed.
- 3Precision's denominator contains false positives, the negatives wrongly called positive. The two metrics share the true positives in their numerators, but they punish different mistakes.
The source's example is a cancer diagnosis model. Here it is important to find all people who are sick, even if that means including some healthy patients among the positive predictions. A model with high recall has few false negatives. Recall also goes by other names: sensitivity, hit rate, or true positive rate (TPR).
Mapping Each Metric to Its Error
The clearest way to remember the two metrics is to place each error on the predicted-versus-actual grid. False positives sit in the column of samples predicted positive, and precision is the metric that is limited by them. False negatives sit among the actual positives the model missed, and recall is the metric that is limited by them. True positives are the shared piece that both metrics count in their numerators.
Trace the Two Extreme Models
The clearest evidence for the trade-off comes from two extreme models. Trace each one's behavior, then check the comparison below. The first model predicts every sample as positive. It cannot miss a positive, so it has no false negatives and its recall is perfect. But every negative becomes a false positive, and it has no true negatives, so its precision is very low.
The second model is the opposite. It predicts only the single data point it is most confident about as positive and labels everything else negative. If that one point really is positive, precision is perfect. But nearly all the positive samples are missed, so recall is very bad.
Optimizing precision and optimizing recall pull in opposite directions. A model that pushes one toward its maximum usually sacrifices the other. Both trivial extremes expose this trade-off.
Combining Them with the F1-Score
Because each metric shows only part of the picture, the source suggests summarizing them together. The F-score, also called the F-measure, is the harmonic mean of precision and recall. The variant most often used is the F1-score, which weights precision and recall equally.
The harmonic mean matters. Because it is not a plain average, the F1-score is pulled toward the smaller of the two values. A model cannot earn a high F1-score by excelling at only one of precision or recall. This is exactly the failure the extreme models exposed.
Strong Precision, Weak Recall
A generated model has precision 1.0 and recall 0.1. Compare its F1-score with the simple average of the two numbers.
- 1Simple average
The plain average is $(1.0 + 0.1) / 2 = 0.55$. Taken alone, this looks moderately good.
- 2Harmonic mean
Compute $2 \cdot (1.0 \cdot 0.1) / (1.0 + 0.1) = 0.2 / 1.1 \approx 0.18$.
- 3Interpretation
The F1-score sits close to the weaker recall, not halfway between the two values. The model's strength on precision does not rescue its weak recall.
The F1-score is about 0.18, far below the simple average of 0.55.
Why F1 Reveals What Accuracy Hid
The source computes the F1-score for four models on the nine vs. rest test set. Before looking at any output, form your own expectation of how the four scores will compare. Then check the reasoning: the dummy classifier and the decision tree are separated clearly by F1, a gap that was not obvious when looking at accuracy alone. F1 captures what makes a good model in this case far better than accuracy does.
Common mistake Trusting a high accuracy on an imbalanced dataset without checking the minority class
What it looks likeA model that always predicts 'not nine' on a 10 percent nine dataset scores about 90 percent accuracy.
Why it failsAccuracy is dominated by the majority class, so it can stay high while the rare class is never found.
Do this insteadCheck precision, recall, and F1 for the minority class before judging the model.
Why an F1 Score of Zero Appears
The most frequent-class model in the source gets an F1-score of 0.00, and the source reports an error message for it. The reason is that this model never predicts the positive class. Precision's denominator counts the samples predicted positive, and with no positive predictions that denominator is zero. The F-score's denominator therefore becomes zero too. Trying to divide by zero is the failure point, which is why the output is an error or a degenerate value rather than a meaningful score.
Reading a Classification Report
If you want a more complete summary, the classification_report function computes precision, recall, and F1-score together and prints them in a readable layout. The source uses this call for the most frequent model, with class names supplied for readability. The sample call below is a generated illustration of that pattern; variable names will match your own workflow.
y_testholds the true labels from the test set.y_predholds the model's predictions for the same samples.target_namessupplies readable labels for each class.
Each class row reports precision, recall, and F-score with that class treated as the positive class. Support, the last numeric column, is the count of samples in that class according to the ground truth. The final row gives a weighted average of the per-class numbers, where each class is weighted by its sample count.
Tracing a Row That Looks Wrong
- 1Confirm which class the row describes. The row label names the positive class for that row, and the numbers change completely if you switch classes.
- 2Check the support column. A tiny support value means the score rests on very few samples and may swing widely.
- 3Ask which error the low number reflects. Low precision points to false positives. Low recall points to false negatives.
- 4Compare the row against the accuracy figure. A high accuracy alongside a collapsed minority-class row is the signature of a majority-class shortcut.
- 5If the F1-score is 0.00 or an error appears, check whether the model made any positive predictions at all.
A generated model on a nine vs. rest task has precision 0.80 and recall 0.20 for the nine row. Without computing anything else, which error is the model making more often, and what should you change first if your goal is to find most of the nines?
Hints
- Low recall is tied to false negatives, the nines the model missed.
- A goal of finding most nines means the target is recall, not precision.
Key Takeaways
- Precision measures how many predicted positives are truly positive, so it limits false positives. Recall measures how many real positives are found, so it limits false negatives.
- Optimizing precision and optimizing recall pull in opposite directions. The two extreme models, which predict everything positive or only the most confident point, make this trade-off visible.
- The F1-score is the harmonic mean of precision and recall. Because it is pulled toward the smaller value, it cannot be high unless both metrics are reasonably strong, which makes it more informative than accuracy on imbalanced binary data.
- A classification report gives per-class precision, recall, F1, and support. Always state the positive class, and trace any surprising row back to its support and to the error it reflects.