Home / Machine Learning

Evaluation Metrics for Regression

Interact with the line and data points to see how MAE, MSE, RMSE, and $R^2$ quantify model performance in real-time.

2.5
30
Interactive Plot
Regression Line
$y_{pred} =$ 1.20$x$ + 2.00

Mean Absolute Error

MAE
0.000
Average of absolute differences. Treats all errors equally.

Mean Squared Error

MSE
0.000
Average of squared differences. Heavily punishes large errors (outliers).

Root Mean Sq. Error

RMSE
0.000
Square root of MSE. Returns error metric to original units.

R-Squared Score

$R^2$ (Coeff. of Det.)
0.000
Proportion of variance explained by the model. 1.0 is perfect, <0 is worse than mean.

Understanding Regression Metrics

In regression, our goal is to predict a continuous value, like a price or a temperature. But how do we know if our model's predictions are any good? Evaluation metrics are the tools we use to measure a model's performance and quantify its error. This lab visualizes four of the most common regression metrics, allowing you to see how they respond to changes in data and model fit in real-time.

The Four Key Metrics

Each metric tells a slightly different story about your model's errors. The interactive plot above shows the true data points (green dots), the model's prediction line (orange), and the errors, or residuals (dashed red lines), which are the distances between each true point and the line.

1. Mean Absolute Error (MAE)

What it is: The average of the absolute differences between the true values and the predicted values.
Formula: $ \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i| $
Interpretation: It tells you, on average, how far off your predictions are. It's easy to understand because it's in the same units as the target variable. It treats all errors equally, big or small.

2. Mean Squared Error (MSE)

What it is: The average of the squared differences between the true and predicted values.
Formula: $ \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $
Interpretation: By squaring the errors, MSE penalizes larger errors much more heavily than smaller ones. This makes it sensitive to outliers. Its units are squared, which can make it hard to interpret directly.

3. Root Mean Squared Error (RMSE)

What it is: The square root of the MSE.
Formula: $ \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2} $
Interpretation: RMSE is the most popular metric. Like MSE, it punishes large errors, but by taking the square root, it returns the error metric to the original units of the target variable, making it more interpretable than MSE.

4. R-Squared ($R^2$)

What it is: The proportion of the variance in the dependent variable that is predictable from the independent variable(s).
Formula: $ 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2} $
Interpretation: $R^2$ ranges from 0 to 1. A score of 1.0 means the model perfectly explains the data's variance. A score of 0.0 means the model is no better than just predicting the mean of the target variable. A negative score means the model is even worse than that!

Guided Experiments

Use the controls and the interactive plot to build a strong intuition for these metrics.

  1. The Impact of a Single Outlier: Start with the "Good Linear Fit" dataset. Drag one of the green data points far away from the prediction line. Watch the metrics change. You'll notice that MSE and RMSE increase dramatically compared to MAE. This is because they square the error, heavily penalizing this large deviation (outlier).
  2. Good Fit vs. Poor Fit: Use the "Initial Dataset" dropdown. Switch between "Good Linear Fit" and "Poor Fit (High Bias)". Observe how all error metrics (MAE, MSE, RMSE) are much higher for the poor fit. Now look at the $R^2$ score. For the good fit, it should be high (e.g., > 0.8), while for the poor fit, it will be very low, possibly even negative, indicating the model is useless.
  3. Manually Improving the Fit: Select the "Poor Fit" dataset. The orange line will be far from the data. Now, click and drag the handles on the ends of the orange line to move it closer to the green data points. As you manually improve the fit, watch all the error metrics decrease and the $R^2$ score increase towards 1.0.
  4. The Effect of Noise: Select the "Good Linear Fit" and use the "Noise Level" slider. As you increase the noise, the data points become more scattered. Notice that even with the best possible line, the error metrics will rise, and the maximum achievable $R^2$ score will fall. This shows that the inherent randomness in data puts a limit on how well any model can perform.

Which Metric Should You Use?

  • Use MAE when you want a simple, interpretable metric that is not sensitive to outliers. For example, forecasting sales where a few large errors are acceptable.
  • Use RMSE when large errors are particularly undesirable and you want to penalize them more. It's the most common metric for regression tasks. For example, predicting house prices where a large error could be very costly.
  • Use $R^2$ when you want to understand the proportion of variance your model explains. It's great for communicating the overall "goodness of fit" of your model to a non-technical audience.
Cheat sheet

Evaluation Metrics for Regression

In regression, our goal is to predict a continuous value, like a price or a temperature. But how do we know if our model's predictions are any good? Evaluation metrics are the tools we use to measure a model's performance and quantify its error. This lab visualizes four of the most common regression metrics, allowing you to see how they respond to changes in data and model fit in real-time.

MACHINE LEARNING · vizlearn.in/machine_learning/evaluation_metrics_for_regression.html