Blog

Understanding Error Metrics in LSTM Models

A practical guide to MAE, MSE/RMSE, and R² - what they measure, how they're computed, and how to interpret them in the context of forecasting.

Test MAE (Mean Absolute Error)

MAE measures the average size of the errors between your model’s predictions and the actual temperature values, without considering their direction.

  • How it’s calculated It’s the average of the absolute differences between the true values (yiy_i) and the predicted values (y^i\hat{y}_i).
MAE=1n∑i=1n∣yi−y^i∣MAE = \frac{1}{n} \sum_{i=1}^{n} \left| y_i - \hat{y}_i \right|

Where:

  • nn is the number of data points in the test set
  • yiy_i is the actual temperature at a given time
  • y^i\hat{y}_i is the temperature your model predicted for that same time
  • How to interpret it The MAE is in the same unit as your target variable (temperature). For example, in the best-performing model (stride=84), the Test MAE was 0.9604. This means, on average, the model’s temperature prediction was off by about 0.96 degrees. It’s a straightforward, easy-to-understand measure of average prediction error. A lower MAE is better.

Test MSE (Mean Squared Error)

MSE also measures the average prediction error, but it penalizes larger errors more significantly than smaller ones.

  • How it’s calculated It’s the average of the squared differences between the true values (yiy_i) and predicted values (y^i\hat{y}_i).
MSE=1n∑i=1n(yi−y^i)2MSE = \frac{1}{n} \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2
  • How to interpret it Because the errors are squared, a single large error has a much greater impact on the MSE than on the MAE. This is useful when you want to heavily penalize your model for being wildly wrong. The main drawback is that the units are squared (e.g., degrees²), which isn’t intuitive. For instance, the Test MSE for the stride=84 model was 1.6726. Often, people will take the square root of the MSE to get the Root Mean Squared Error (RMSE), which returns the error metric to the original units (degrees):
RMSE=MSE=1n∑i=1n(yi−y^i)2RMSE = \sqrt{MSE} = \sqrt{\frac{1}{n} \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2}

In this case, the RMSE would be 1.6726≈1.29\sqrt{1.6726} \approx 1.29 degrees. Like MAE, a lower MSE is better.

Test R² (R-squared or Coefficient of Determination)

R² is different; it doesn’t measure error in the original units. Instead, it tells you what proportion of the variance in the actual temperatures your model is able to explain.

  • How it’s calculated It compares your model’s performance to a simple baseline model that just predicts the average temperature for all time points.
R2=1−SSRTSS=1−∑i=1n(yi−y^i)2∑i=1n(yi−yˉ)2R^2 = 1 - \frac{\text{SSR}}{\text{TSS}} = 1 - \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i - \bar{y})^2}

Where:

  • SSR\text{SSR} = Sum of Squared Residuals (your model’s errors)

  • TSS\text{TSS} = Total Sum of Squares (baseline model’s errors)

  • yˉ\bar{y} = mean of all actual temperatures in the test set How to interpret it R2R^2 is a score between (theoretically) −∞-\infty and 11.

    • R2=1R^2 = 1: Your model perfectly explains all the variability in the data. Its predictions are perfect.
    • R2=0R^2 = 0: Your model is no better than the baseline model that just predicts the average temperature every time.
    • R2>0R^2 > 0: Your model is better than the baseline. An R2R^2 of 0.9389 for the best model (stride=84) is excellent. It means the model explains about 93.9% of the temperature fluctuations.
    • R2<0R^2 < 0: Your model is worse than the simple average baseline. For example, a Ridge baseline with R2=−4.8650R^2 = -4.8650 indicates very poor performance.

In short, a higher R2R^2 is better, with 11 being a perfect score.