Concepts / Model Selection and Comparison

Model Selection and Comparison

A high accuracy score is rarely the real goal of a machine learning task; the metric should stand in for how the model will actually be used.

  • Programming

A 99 Percent Score That Should Worry You

Suppose you train a classifier and report that it is 99 percent accurate. That sounds like a success. Before you celebrate, you need to ask a harder question: accurate at doing what, and does that accuracy matter for the job the model is supposed to do? Choosing an evaluation metric is a decision about what counts as a good model, and that decision should come from how the model will actually be used.

This article follows one idea through a short sequence. First you will trace what happens to a model that scores very well on paper but does nothing useful. Then you will look at why unbalanced classes cause this, why the two kinds of error differ in their consequences, and how those consequences guide the choice of metric.

Tracing a Model That Always Says Negative

Imagine a screening dataset of 1000 patients. Ten of them have a serious illness (the positive class) and 990 are healthy (the negative class). Now imagine a model that ignores the patient entirely and always predicts negative. Follow what it does with the whole dataset.

Worked example

Scoring a model that always predicts negative

A dataset has 990 negative and 10 positive samples. A model predicts negative for every sample. What accuracy does it report, and how many positives does it catch?

  1. 1
    Count the correct predictions

    Every healthy patient is predicted negative, which is correct, so all 990 negatives are right. The 10 sick patients are also predicted negative, which is wrong for each of them.

  2. 2
    Compute the overall accuracy

    The model gets 990 of 1000 predictions right, so its accuracy is 99 percent. That is the same headline number as the one that sounded like a success.

  3. 3
    Check the rare class

    The model predicted positive for zero of the ten sick patients. It catches none of the cases that the screening was built to find.

Result

The model earns 99 percent accuracy while catching zero positives. The overall score is high, but the model fails on the one class that matters most.

Accuracy 99%990 of 1000 correctNegatives correct990 of 990Positives caught0 of 10
The always-negative model looks strong on the overall score and fails completely on the rare positive class.

What do you think happens?

A fraud detector sees 1 fraudulent transaction in every 200. A model that never flags anything is scored only on accuracy. What accuracy does it report?

Reveal answer
Answer:

99.5 percent, because it is correct on 199 of every 200 transactions.

The model is right on every legitimate transaction and wrong on the single fraud case in each group of 200. Its headline score is high, yet it detects no fraud at all.

Why Unbalanced Classes Mislead

Classification problems rarely have balanced classes. In many real datasets, one outcome is far more common than another. Fraud is rare compared with ordinary transactions, serious diseases are rare compared with healthy patients, and defective items are rare compared with good ones.

When one class dominates, a model can earn a high overall score by performing well on the common class while failing on the rare class that you actually care about. The overall number averages over both groups, so a large, easy group can hide a total failure on a small, important one. That is why an overall score can look strong while the model fails where it matters most.

Two Kinds of Wrong Answers

In a binary classification problem, each prediction can be right or wrong, and each wrong prediction is one of two kinds. A false positive happens when the model predicts the positive class but the true label is negative. A false negative happens when the model predicts the negative class but the true label is positive.

The key point is that these two errors often have very different consequences, so treating them as interchangeable is a mistake. Both are errors in the confusion between predicted and true labels, but they do not hurt the same way.

Healthy patientflaggedpredicted positive, trulynegativeSick patient missedpredicted negative, trulypositiveUnneeded follow-uptesttime, money, worryTreatment delayedcan cause serious harmCleared by the testusually recoverableHarm hard to undofar more seriousleads tousually clearedleads tomay become
The same model can make either error. The false positive costs a follow-up test; the false negative can delay treatment for a sick patient.

In a screening tool that flags patients who may have a serious illness for a follow-up test, a false positive sends a healthy patient to a test they did not need. That costs time, money, and some worry, but the patient can usually be cleared. A false negative lets a sick patient go home without the follow-up. That error can delay treatment, and the harm may be far more serious and harder to undo. Here the two errors are not similar in weight at all.

Reversing the Costs in a Spam Filter

Now reverse the situation. In a spam filter, a false positive sends an important email to the spam folder, and a false negative lets a spam message reach the inbox. The costs look different again. A missed important email can matter a great deal to the user, while a single spam message in the inbox is a smaller nuisance.

Working Through the Metric Decision

The source closes its point with a direct instruction: understand what the consequences of each error are, and then pick an evaluation metric accordingly. In practice this is a short sequence of questions. What decision does the model feed into? Which kind of error would cause more harm there? Does the dataset have a rare class that matters most? Your answers should determine which score you treat as the main measure of success.

Use case anddecisionwhat the model feeds intoAccuracy may be areasonable startclasses roughly balanced,errors similar in costMissed positives costmorefalse negatives dominateRecalloptimize to catch positivesRare class mattersmost?Which error costsmore?False alarms costmorefalse positives dominatePrecisionoptimize to keep flagstrustworthyBoth errors matterneither can be neglectedF1balances the two kinds oferrornoyesfalse negativesfalse positivessimilar
Answering the decision questions in order leads to a candidate metric. The mapping from error cost to metric is a reasoned starting point, not a fixed rule.
MEDIUM

A model flags transactions as possible fraud. Fraud is rare, and each missed fraud case can lead to a large loss, while a false alarm only means a short check by a human reviewer. Using the decision questions, which error should you weigh more heavily, and which kind of score would you treat as the main measure of success? Justify your answer using the consequences of each error.

Hints
  • Start by asking what decision the model feeds into: flagging a transaction for review.
  • Compare what a missed fraud costs with what a false alarm costs in this scenario.
  • Then check the flowchart: which branch does the cost comparison send you down?

Mistakes Beginners Make With Accuracy

  • Common mistake

    Treating a high accuracy score as proof that the model works

    What it looks like

    A model that always predicts the common outcome reports 99 percent accuracy on a 99-to-1 dataset.

    Why it fails

    Accuracy averages over both classes, so a large common class can hide a total failure on the rare one.

    Do this instead

    Check how the model performs on the class that matters for the decision before trusting the headline number.

  • Common mistake

    Treating false positives and false negatives as equally costly

    What it looks like

    Weighting a missed serious illness the same as an unneeded follow-up test.

    Why it fails

    The two errors often have very different consequences, and the harm can be far more serious for one of them.

    Do this instead

    Describe what each error costs in the specific application before choosing how to weigh them.

  • Common mistake

    Assuming one error type is always worse

    What it looks like

    Assuming a missed fraud is always worse than a false alarm, then applying the same rule to a spam filter.

    Why it fails

    The right priority depends on the specific problem, and the costs can point in opposite directions in different applications.

    Do this instead

    Answer the decision questions for each problem separately.

  • Common mistake

    Choosing a metric before asking what decision the model supports

Key Takeaways for Choosing a Metric

A machine learning task usually exists to support some decision or action in the real world. A score is a stand-in for that real objective, and it only works as a stand-in when it tracks what the model will really be used for.

At a glance

  • A high accuracy score is rarely the real goal; the metric should stand in for how the model will actually be used.
  • Unbalanced classes let a model earn a high overall score while failing on the rare class that matters most.
  • False positives and false negatives often have very different consequences, so they should not be treated as interchangeable.
  • Understand the consequences of each error in the specific application first, then choose the evaluation metric that reflects them.

Related concepts

More concepts starting with M