Back to Blog
Machine Learning June 25, 2026 6 min read

Indispensable Metrics in Machine Learning

Learn about Accuracy, Precision, Recall, F1-Score, and ROC-AUC, and when to use each for model evaluation.

Why One Metric Isn't Enough: The Accuracy Trap

Evaluating a machine learning model is not just about computing a single score and calling it a day. In the real world, a model with 99% accuracy can be completely useless.

Consider a fraud detection system where only 1% of transactions are fraudulent. A naive model that classifies every transaction as "not fraud" will instantly achieve 99% accuracy, yet it is completely blind to actual fraud. This is the Accuracy Trap. To build robust systems, we must choose metrics aligned with our data distribution and business goals.


1. Classification Metrics

Classification tasks require analyzing correct and incorrect predictions across different classes. The foundation of these metrics is the Confusion Matrix, which breaks down predictions into:

  • True Positives (TP): Correctly predicted positive instances.
  • True Negatives (TN): Correctly predicted negative instances.
  • False Positives (FP): Negative instances wrongly predicted as positive (Type I Error).
  • False Negatives (FN): Positive instances wrongly predicted as negative (Type II Error).

Accuracy

Accuracy measures the ratio of correct predictions to total predictions:

$$\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}$$

  • When to use: Balanced datasets where both classes are of equal importance.
  • When to avoid: Imbalanced datasets.

Precision (Positive Predictive Value)

Precision answers the question: Out of all instances the model predicted as positive, how many were actually positive?

$$\text{Precision} = \frac{TP}{TP + FP}$$

  • Focus: Minimizing False Positives (FP).
  • Example: Spam detection. You want high precision because a False Positive means a legitimate, potentially urgent email goes to the spam folder.

Recall (Sensitivity / True Positive Rate)

Recall answers the question: Out of all actual positive instances, how many did the model correctly identify?

$$\text{Recall} = \frac{TP}{TP + FN}$$

  • Focus: Minimizing False Negatives (FN).
  • Example: Medical diagnostics (e.g., cancer detection). A False Negative means letting a sick patient go untreated, which is far worse than a False Positive (which can be resolved via secondary screening).

F1-Score

The F1-Score is the harmonic mean of Precision and Recall. Unlike the arithmetic mean, it penalizes extreme values (e.g., if Recall is 0, F1-Score is 0).

$$\text{F1-Score} = 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}$$

  • When to use: When you need a balance between Precision and Recall, especially on imbalanced datasets.

ROC-AUC (Receiver Operating Characteristic - Area Under Curve)

The ROC curve plots the True Positive Rate (Recall) against the False Positive Rate ($FPR = \frac{FP}{TN + FP}$) at various threshold settings.

  • AUC (Area Under the Curve) ranges from 0.0 to 1.0. An AUC of 0.5 means random guessing, while 1.0 represents a perfect classifier.
  • When to use: When you want to evaluate the model's performance across all thresholds, independent of class imbalance.

2. Regression Metrics

Unlike classification, regression models predict continuous numeric values. Therefore, metrics must measure the distance between predictions and actual values.

Mean Absolute Error (MAE)

MAE is the average of absolute differences between predicted and actual values:

$$\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|$$

  • Key characteristic: Linear penalty. MAE treats all errors equally and is highly robust to outliers.

Mean Squared Error (MSE)

MSE is the average of squared differences:

$$\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$$

  • Key characteristic: Exponential penalty. Squaring the errors penalizes large deviations much more heavily than small ones.

Root Mean Squared Error (RMSE)

RMSE is the square root of MSE:

$$\text{RMSE} = \sqrt{\text{MSE}}$$

  • Key characteristic: It brings the error metric back to the same unit of measurement as the target variable ($y$), making it highly interpretable.

Coefficient of Determination ($R^2$)

$R^2$ measures the proportion of variance in the dependent variable that is predictable from the independent variables:

$$R^2 = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}$$

  • Scale: Typically ranges from 0 to 1. An $R^2$ of 0.0 means the model performs no better than predicting the mean, while 1.0 means perfect predictions.

3. Metric Selection Guide

Use the following framework to match your metrics with the task and objectives:

Task / Data ScenarioRecommended MetricPrimary Focus
Imbalanced Classification (e.g. Fraud)Recall or F1-ScoreMinimize missed positive cases
Spam / Content FilteringPrecisionMinimize false alarms (False Positives)
Probabilistic Outputs CalibrationLog LossEvaluate exact class probability accuracy
Regression with OutliersMAERobust average error unaffected by outliers
Regression (Large errors are critical)RMSEPenalize large errors heavily in original units
AccuracyRecallF1Metrics
Z

Zakaria Kassemi

Data Scientist & AI Engineer — Morocco