Article · 2024-01-01

A Deep Dive into Regression Evaluation Metrics: From MAE to R², Choosing the Right Tool for the Job

Metric Formula Scale Range Interpretation & Focus
MAE (Mean Absolute Error) $\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} y_i - \hat{y}_i $ Same as target
MSE (Mean Squared Error) $\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$ Squared scale $[0, \infty)$ Penalizes larger errors more heavily. Sensitive to outliers; convenient for gradient-based optimization.
RMSE (Root Mean Squared Error) $\sqrt{\text{MSE}}$ Same as target $[0, \infty)$ Balances MSE's sensitivity with MAE's interpretability. One of the most widely used metrics.
MedAE (Median Absolute Error) $\text{MedAE} = \text{median}( y_1 - \hat{y}_1 , \dots, y_n - \hat{y}_n
(Coefficient of Determination) $1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}$ Unitless $(-\infty, 1]$ The percentage of variance in the data explained by the model. Closer to 1 is better, but it can be negative.
Adjusted R² Adjusted R² Unitless $(-\infty, 1]$ An adjusted version of R² that penalizes for the number of features, making it more suitable for comparing models with different features.

2. Other Common Metrics

Beyond the core metrics, the following are extremely useful in specific scenarios.

Metric Formula & Characteristics Use Case Notes
MAPE (Mean Absolute Percentage Error) $\frac{100}{n}\sum \frac{y_i - \hat{y}_i}{y_i} %$
SMAPE (Symmetric MAPE) $\frac{100}{n}\sum\frac{ y_i - \hat{y}_i }{(
RMSLE (Root Mean Squared Log Error) $\sqrt{\frac{1}{n}\sum (\ln(y_i+1)-\ln(\hat{y}_i+1))^2}$ Predicting positive, long-tailed data (e.g., house prices, web traffic). Focuses on relative error; less penalty for large value deviations. Requires $y > -1$.
Explained Variance $1 - \frac{\text{Var}(y - \hat{y})}{\text{Var}(y)}$ Similar to R², but focuses on variance rather than systematic bias. Measures the correlation between the fluctuations of predicted and true values.
Max Error $\max_i y_i - \hat{y}_i $

3. Quick Calculation with Python

scikit-learn provides convenient tools to calculate most of these metrics. Here is a template you can quickly adapt for your projects.

import numpy as np
from sklearn.metrics import (mean_absolute_error, mean_squared_error,
                             median_absolute_error, r2_score,
                             mean_absolute_percentage_error,
                             explained_variance_score, max_error)

# Assuming y_true and y_pred are your ground truth and predictions
rng = np.random.RandomState(42)
y_true = rng.uniform(50, 150, size=30)
noise  = rng.normal(0, 10, size=30)
y_pred = y_true + noise

# Calculate multiple metrics at once
metrics = {
    "MAE": mean_absolute_error(y_true, y_pred),
    "MSE": mean_squared_error(y_true, y_pred),
    "RMSE": mean_squared_error(y_true, y_pred, squared=False), # or np.sqrt(mse)
    "MedAE": median_absolute_error(y_true, y_pred),
    "MAPE(%)": mean_absolute_percentage_error(y_true, y_pred) * 100,
    "R2": r2_score(y_true, y_pred),
    "ExplainedVar": explained_variance_score(y_true, y_pred),
    "MaxError": max_error(y_true, y_pred)
}

print("--- Regression Metrics ---")
for k, v in metrics.items():
    print(f"{k:<12}: {v:.4f}")

Example Output (may vary slightly with each run):

--- Regression Metrics ---
MAE         : 8.7285
MSE         : 105.1905
RMSE        : 10.2554
MedAE       : 7.6170
MAPE(%)     : 7.8522
R2          : 0.8925
ExplainedVar: 0.8949
MaxError    : 28.1245

4. How Do Outliers Affect Metrics? A Small Experiment

To intuitively understand the sensitivity of different metrics to outliers, let's conduct a simple experiment.

import numpy as np
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score

# 1) Create a clean dataset
y_true_clean = np.linspace(10, 20, 50)
y_pred_clean = y_true_clean + np.random.normal(0, 0.8, size=len(y_true_clean))

def report(title, y_true, y_pred):
    mse = mean_squared_error(y_true, y_pred)
    mae = mean_absolute_error(y_true, y_pred)
    r2 = r2_score(y_true, y_pred)
    print(f"{title:18s}  MSE={mse:6.3f}  MAE={mae:5.3f}  R2={r2:5.3f}")

report("Without Outlier", y_true_clean, y_pred_clean)

# 2) Inject one extreme outlier (true value 100, predicted 50)
y_true_outlier = np.append(y_true_clean, 100)
y_pred_outlier = np.append(y_pred_clean, 50)

report("With Outlier", y_true_outlier, y_pred_outlier)

Typical Output:

Without Outlier     MSE= 0.631  MAE=0.642  R2=0.985
With Outlier        MSE=82.641  MAE=1.624  R2=-0.250

Interpreting the Experiment:

This experiment shows that when your business cannot tolerate large errors, MSE/RMSE serves as a more sensitive sentinel. However, if you want to assess overall model performance without being skewed by a few anomalies, MAE/MedAE is a more robust choice.

5. How to Choose the Right Metric for Your Project: A Scenario-Based Guide

Choosing the right metric begins with understanding your business needs and data characteristics. Here, we provide a scenario-based guide by directly answering the key questions posed earlier.

Scenario 1: Are we more afraid of being "off by 1° on average" or "off by 5° occasionally"?

This question gets to the heart of your model's error tolerance, especially its sensitivity to large errors.

Scenario 2: Does management care about "relative percentages" or "absolute values"?

This question is about the metric's audience and its ease of communication.

Scenario 3: What are the characteristics of my data distribution?

The nature of your data is a critical technical prerequisite for selecting a metric.

Summary: A Decision-Making Flowchart

  1. Qualitative Analysis (Business Dialogue): Start by talking to stakeholders to clarify error tolerance and reporting habits, addressing Scenarios 1 and 2.
  2. Quantitative Analysis (Data Exploration): Plot a histogram of your data to check for long tails, outliers, or zero values, addressing Scenario 3.
  3. Monitor Multiple Metrics (Model Iteration): During training and validation, track 2-3 key metrics simultaneously (e.g., a robust metric like MAE, a sensitive one like RMSE, and a business-friendly one like MAPE) to gain a comprehensive understanding of your model's behavior.
  4. Final Selection (Deployment): Based on the analysis, choose 1-2 of the most critical metrics to serve as the final standard for model selection and online monitoring.

Conclusion

There is no single "best" metric—only the "most appropriate" one for your specific context. A deep understanding of the mathematical principles and business intuition behind each metric is the bridge that connects your model to real-world value. We hope this guide helps you choose and interpret evaluation metrics with more confidence in your future regression projects.

© 2026 Yuxu Ge ·