← AI Practitioner study path

AI and ML basics · 10 min

ML model metrics and business metrics

In this lesson you will learn to read a confusion matrix, what accuracy, precision, recall and F1 measure, when each one matters and which business metrics the exam guide asks for.

A metric is a number that measures something. The metrics of an ML model tell you how well it gets things right, and business metrics tell you whether the model is worth what it costs. Objective 1.3.6 of the AIF-C01 exam guide asks you for both types: accuracy, precision, recall and F1 for the model, and cost and return for the business. For example, a bank that uses a model to detect fraudulent purchases wants to know how many frauds the model finds and also whether the money it saves on fraud is greater than what the model costs it.

What is the confusion matrix?

Confusion matrix of a fraud model: in the rows what really happened and in the columns what the model said, with true positives, false negatives, false positives and true negatives; on the right, the formulas for accuracy, precision, recall and F1

When a model classifies into two categories, such as fraud and not fraud, all of its metrics come from a table called the confusion matrix. The matrix crosses what really happened with what the model said, so it has four cells. In these cells, positive is the category the model is looking for, here fraud, and negative is the other one, and neither word means good or bad:

  • The true positive (TP), where the model said fraud and it was fraud.
  • The false positive (FP), where the model said fraud and it wasn't.
  • The false negative (FN), where the model said it wasn't fraud and it was.
  • The true negative (TN), where the model said it wasn't fraud and it wasn't.

Each cell is a case that happens to a real person. For example, if the bank blocks the card of a customer who was just paying for dinner, that is a false positive, and if it lets through a purchase made with a stolen card, that is a false negative.

From those cells, the SageMaker AI documentation defines the model metrics, which give a value from 0 to 1 and combine the cells in a different way:

  • Accuracy, which measures how many the model got right out of all of them: (TP + TN) divided by the total.
  • Precision, which measures how many were fraud out of the ones the model flagged as fraud: TP / (TP + FP). For example, if the model flagged ten purchases as fraud and eight were, it was right on eight out of every ten of its alarms.
  • Recall, which measures how many of the existing frauds the model found: TP / (TP + FN). For example, if there were ten frauds and the model found five, half of them slipped past it.
  • F1, which is the of precision and recall, and which balances the two in a single number.

Why can accuracy be misleading?

Accuracy seems like the most natural metric, but it fails when one of the categories is very rare. For example, if 10 out of 1,000 transactions are fraud, a model that always says "not fraud" is right on 990 out of 1,000, which means it has 99% accuracy. However, that model didn't find a single fraud, so its recall is 0.

That is why, when one of the categories is very rare, such as fraud, a disease or , accuracy says little and you look at precision and recall. AWS uses the example of a mailbox where only 1% is spam.

True or false?

0 of 3
  1. A model with 99% accuracy is always good at detecting fraud.

  2. Precision measures, out of the real cases, how many the model found.

  3. F1 combines precision and recall in a single number.

Precision or recall?

Precision and recall usually move in opposite directions: when one goes up, the other usually goes down. If the model almost never flags a case as positive, precision goes up and recall goes down. At the other extreme, if the model flags everything as positive, recall reaches 1 even though the model is wrong about all the other cases, and AWS warns about that result.

To decide which of the two matters, look at which error costs more in the case, because each error points to a metric:

  • The costly false positive, which calls for prioritizing precision. The AWS example is assuming an aircraft's safety system is safe when it isn't.
  • The costly false negative, which calls for prioritizing recall. The AWS example is a cancer test, where you want to find all the real cases.
  • Both errors equally costly, which calls for using F1.

With the same model, the error that costs the most depends on the business. For example, if every unfair block makes the customer switch banks, the false positive is costly and the bank watches precision, while if every fraud that gets through costs it a lot of money, the false negative is costly and it watches recall.

Which metric do you prioritize?

0 of 4

Tap the column of the metric that matters most in each case.

  1. A spam filter that must not send work emails to the trash

  2. A test that detects a serious disease

  3. A system that blocks cards, where every unfair block makes the customer leave

  4. Detecting faulty parts before they leave the factory

cloud path tip: in older practice questions you may find the AUC metric, which measures how well the model separates the two categories at any , where 1 is perfect and 0.5 is the same as guessing at random. The current guide no longer names it.

Business metrics

The four business metrics in the guide: cost per user, development costs, customer feedback and return on investment, each with what it measures

Model metrics don't tell you whether the model is worth it, because a model with an F1 of 0.95 can be bad business if it costs more than it brings in. That is why the guide names four business metrics:

  • Cost per user, which is what it costs to serve each customer's predictions.
  • Development costs, which include the data, the training, the people and the time.
  • Customer feedback, which is measured with satisfaction, complaints or surveys.
  • Return on investment (ROI), which compares what the business earns or saves against what the model cost. For example, if the fraud model saves the bank more money than it cost to build and maintain, the return is positive.

The AWS Machine Learning Lens says that business value is measured against concrete goals, defined in the first phase of the lifecycle, and that you have to count the cost of getting the data, of training, of running and of the model being wrong. Its example metrics are new customer acquisition, that is, how many new customers arrive, the rate of fraud detected and customer satisfaction. These metrics are defined before touching any data and are reviewed again once the model is .

Model metric or business metric?

0 of 4

Tap the correct column for each metric.

  1. Recall of 0.92 in fraud detection

  2. Each prediction costs 0.002 USD on the computers that run the model

  3. Customer satisfaction went up after the change

  4. F1 score of 0.88

On the exam

In a metrics question, look in the scenario for the serious error. These phrases point to each answer:

  • The phrases "can't let any case slip through" or "detect every patient", which point to recall.
  • The phrases "false alarms are expensive" or "not bother legitimate customers", which point to precision.
  • The phrase "balance between the two", which points to F1.
  • The words "money", "customers" or "investment", which point to a business metric.

For example, if a question says that a hospital uses a model that "can't let any case slip through" of a disease, that phrase points to recall.

cloud path tip: if one of the categories is rare and an option boasts a high accuracy, be suspicious of that option.

Review question

A bank trains a model that flags transactions as possible fraud, and each flagged transaction is blocked. The bank found that the blocks on legitimate customers are making it lose customers. Which metric should it improve?

Next

  • Metrics and validation, the SageMaker AI page with the formulas and the aircraft and cancer examples.
  • Take a practice exam at /examenes and review your result in domain 1.