TATECHATLAS
◎ English
Math & models / Guide

Understanding and Converting Regression Error Metrics: MAE and RMSE

Learn how to interpret relative errors and the relationship between MAE and RMSE. Understand why direct conversion is not possible but how their properties relate.

On this page

While a direct mathematical conversion of a single Mean Absolute Error (MAE) value to a Root Mean Squared Error (RMSE) value is not possible without making assumptions about the underlying error distribution, understanding their relationship is crucial for interpreting forecast performance. RMSE is generally larger than MAE because the squaring of errors in RMSE disproportionately amplifies larger errors compared to the absolute value operation in MAE. For example, if your errors are [10, 10, 10], both MAE and RMSE are 10. However, if your errors are [5, 15], the MAE is 10, but the RMSE is approximately 11.18 (calculated as sqrt(((5^2) + (15^2))/2)). This difference highlights RMSE's greater sensitivity to outliers. The denominator, representing the number of samples, is preserved in both MAE and RMSE calculations as they are both averages over the dataset. The square root operation is fundamental to RMSE's definition, ensuring it returns to the original units of the target variable, while MAE inherently uses absolute differences. In multi-output scenarios, scikit-learn's multioutput parameter in functions like mean_absolute_error and root_mean_squared_error allows for handling multiple target variables. Options like 'raw_values' return errors per output, preserving the sample count and core calculation for each. 'uniform_average' or a custom array of weights provides an aggregated score, where the denominator (number of samples) is still implicitly handled in the averaging process for each output before aggregation.

Understanding Relative Error and MAE to RMSE Conversion

Relative error in forecasting measures the magnitude of a forecast error in relation to the actual value, often expressed as a percentage. This provides context, especially when dealing with data of varying scales. Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE) are both common metrics for evaluating regression models, but they quantify errors differently. MAE calculates the average of the absolute differences between predicted and actual values, while RMSE calculates the square root of the average of squared differences. A direct conversion from a single MAE value to an RMSE value is not feasible without knowing the specific distribution of errors. However, their relationship is understood through their mathematical definitions and how they are affected by error magnitudes.

The core idea is that both metrics average errors over the number of samples (preserving the denominator). RMSE, by squaring errors before averaging and then taking the square root, gives more weight to larger errors. This makes RMSE typically larger than MAE for the same set of errors, unless all errors are identical.

When comparing MAE and RMSE, remember that RMSE will always be greater than or equal to MAE. If RMSE is significantly larger than MAE, it indicates the presence of large errors in your predictions that are heavily influencing the metric. Consider the business impact of different error magnitudes when choosing between MAE and RMSE.

The Nature of Mean Absolute Error (MAE)

Mean Absolute Error (MAE) is a metric that quantifies the average magnitude of errors in a set of predictions, without considering their direction. It is calculated as the average of the absolute differences between the true values (y_true) and the predicted values (y_pred). The formula is: MAE = (1/n) * sum(|y_true_i - y_pred_i|) for i from 1 to n, where n is the number of samples. MAE is less sensitive to outliers than RMSE because it does not square the errors. This makes it a robust metric when large errors are not disproportionately penalized. The best possible MAE score is 0.0, indicating perfect predictions.

from sklearn.metrics import mean_absolute_error

y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mae = mean_absolute_error(y_true, y_pred)
print(f"MAE: {mae}")

The Nature of Root Mean Squared Error (RMSE)

Root Mean Squared Error (RMSE) is another common metric for regression tasks. It measures the average magnitude of the errors, but it squares the errors before averaging them and then takes the square root of the result. The formula is: RMSE = sqrt((1/n) * sum((y_true_i - y_pred_i)^2)) for i from 1 to n. Because of the squaring of errors, RMSE penalizes larger errors more heavily than MAE. This means that if a model has a few very large errors, the RMSE will be significantly higher than the MAE. The best possible RMSE score is 0.0, indicating perfect predictions. RMSE is widely used because it is differentiable, which is beneficial for optimization algorithms, and it returns the error in the same units as the target variable.

from sklearn.metrics import root_mean_squared_error

y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
rmse = root_mean_squared_error(y_true, y_pred)
print(f"RMSE: {rmse}")

Converting MAE to RMSE: The Mathematical Relationship

A direct, universal conversion from a single MAE value to a single RMSE value is not possible because these metrics capture different aspects of error distribution. MAE represents the average absolute deviation, while RMSE represents the standard deviation of the residuals (errors) if the residuals were normally distributed with a mean of zero. The relationship between MAE and RMSE depends entirely on the specific errors made by the model. If all errors are identical, MAE and RMSE will be equal. If there is a range of errors, RMSE will be greater than MAE. The key difference lies in how they treat larger errors: RMSE's squaring amplifies them, while MAE treats them linearly. Therefore, one cannot simply apply a conversion factor without knowing the error distribution.

The scikit-learn documentation notes that for regression, the choice of scoring function depends on the ultimate goal and application of the prediction. MAE is aligned with measuring the distance between predictions and the true target functional using the absolute error loss. RMSE is related to the expected value of the squared error or l2-norm loss. While both are consistent scoring functions, they are optimized for different error characteristics.

Preserving the Denominator and Square Root

When calculating both MAE and RMSE, the denominator, which is the number of samples (n_samples), is preserved. Both metrics are derived from averaging errors across the entire dataset. For MAE, it's the mean of absolute errors: \(\frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}}-1} \left| y_i - \hat{y}_i \right|\). For RMSE, it's the square root of the mean of squared errors: \(\sqrt{\frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}}-1} \left( y_i - \hat{y}_i \right)^2}\). The square root operation is intrinsic to RMSE's definition. It is applied after calculating the mean of the squared errors. This step is crucial for bringing the RMSE back into the same units as the original target variable, making it directly interpretable alongside the data. MAE, by contrast, does not involve a square root operation, as the absolute value operation already keeps the error in the original units.

Practical Implications and Use Cases

The choice between MAE and RMSE often depends on the specific problem and the tolerance for different types of errors. MAE is useful when you want a straightforward measure of average error magnitude and are less concerned about outliers. For instance, if predicting customer demand, a few unusually high demand days might not warrant a drastic change in inventory strategy, making MAE a suitable metric. RMSE, on the other hand, is preferred when larger errors are significantly more costly or problematic than smaller ones. In financial forecasting, a large error in predicting stock prices could lead to substantial losses, making RMSE a more appropriate metric to penalize such significant deviations. The scikit-learn documentation highlights that consistent scoring functions, like MAE and RMSE, can be used for both model training (as loss functions) and model evaluation, ensuring alignment between optimization and assessment.

When comparing models, if one model has a significantly higher RMSE than MAE relative to its MAE, it suggests that model is more susceptible to large errors. This insight can guide model selection and refinement.

Handling Multi-Output Scenarios

For regression tasks with multiple target variables (multi-output), scikit-learn's mean_absolute_error and root_mean_squared_error functions offer a multioutput parameter to handle the aggregation of errors. The options are: 'raw_values': Returns an array of MAE or RMSE values, one for each output. This preserves the individual error calculations for each target variable, maintaining the denominator (number of samples) and the core calculation for each. 'uniform_average': Calculates the MAE or RMSE for each output and then averages these scores with equal weights. This provides a single, aggregated score. An array-like value can also be provided to specify custom weights for averaging the errors across outputs. In all these cases, the fundamental calculation of MAE or RMSE is applied to each output individually before any aggregation, ensuring that the denominator (number of samples) and the respective operations (absolute difference or squared difference followed by square root) are correctly applied per output.

from sklearn.metrics import mean_absolute_error

y_true_multi = [[0.5, 1], [-1, 1], [7, -6]]
y_pred_multi = [[0, 2], [-1, 2], [8, -5]]

# Raw values for each output
mae_raw = mean_absolute_error(y_true_multi, y_pred_multi, multioutput='raw_values')
print(f"MAE (raw_values): {mae_raw}")

# Uniform average across outputs
mae_uniform = mean_absolute_error(y_true_multi, y_pred_multi, multioutput='uniform_average')
print(f"MAE (uniform_average): {mae_uniform}")

# Weighted average across outputs
mae_weighted = mean_absolute_error(y_true_multi, y_pred_multi, multioutput=[0.3, 0.7])
print(f"MAE (weighted [0.3, 0.7]): {mae_weighted}")

Choosing the Right Metric: MAE vs. RMSE

The decision between using MAE or RMSE hinges on the specific goals of the prediction and the nature of the errors that are most critical to minimize. MAE provides a linear measure of error, meaning each error contributes proportionally to the total error. It is robust to outliers and gives a clear understanding of the average error magnitude. If outliers are not a major concern or if you want a metric that is easy to interpret directly as the average error, MAE is a good choice.

RMSE, by penalizing larger errors more severely due to squaring, is more sensitive to outliers. If large errors have a disproportionately high cost or impact in your application (e.g., in safety-critical systems or financial risk assessment), RMSE is often preferred. It effectively highlights models that perform poorly on extreme cases. The scikit-learn documentation suggests that if a scoring function is given (e.g., in a competition or business context), use that one. If free to choose, consider the ultimate goal and application of the prediction. For predicting a quantile, a specific scoring function like pinball loss might be more appropriate than MAE or RMSE.

Things to check

  • MAE calculation preserves the number of samples in the denominator.
  • RMSE calculation preserves the number of samples in the denominator.
  • RMSE calculation involves a square root operation.
  • MAE calculation involves absolute differences.
  • RMSE is generally greater than or equal to MAE for the same error set.
  • Multi-output MAE/RMSE with 'raw_values' returns an array of errors per output.
  • Multi-output MAE/RMSE with 'uniform_average' returns a single aggregated error.
  • The choice between MAE and RMSE depends on outlier sensitivity requirements.

A direct numerical conversion from a single MAE value to a single RMSE value is not possible without making specific assumptions about the distribution of the errors. The relationship is dependent on the actual error values, not just their average absolute magnitude.

Sources

  1. scikit-learn: model evaluation ↗
  2. scikit-learn: mean_absolute_error ↗
  3. scikit-learn: root_mean_squared_error ↗
Back to top ↑