Evaluating Regression Models

May 24, 2024 10:17 AM

Evaluating regression models involves different metrics compared to classification models. These metrics help understand the model's performance in predicting continuous values. Here are some common regression evaluation metrics along with simple explanations and visual examples using Mermaid diagrams.

Evaluation Metrics

Mean Absolute Error (MAE)

MAE measures the average absolute differences between the predicted and actual values. It is calculated as:

MAE=1ni=1n|yiyi^|

Example:

MAE=|32.5|+|0.50.0|+|22|+|78|4=0.5+0.5+0+14=0.5

Mermaid Diagram:

Number of Instances: 4
Actual Values: 3, -0.5, 2, 7
Predicted Values: 2.5, 0.0, 2, 8
Absolute Errors: 0.5, 0.5, 0, 1
MAE: 0.5

Mean Squared Error (MSE)

MSE measures the average squared differences between the predicted and actual values. It is calculated as:

MSE=1ni=1n(yiyi^)2

Example:

MSE=(32.5)2+(0.50.0)2+(22)2+(78)24=0.25+0.25+0+14=0.375

Mermaid Diagram:

Number of Instances: 4
Actual Values: 3, -0.5, 2, 7
Predicted Values: 2.5, 0.0, 2, 8
Squared Errors: 0.25, 0.25, 0, 1
MSE: 0.375

Root Mean Squared Error (RMSE)

RMSE is the square root of the average squared differences between the predicted and actual values. It is calculated as:

RMSE=1ni=1n(yiyi^)2

Example:

RMSE=(32.5)2+(0.50.0)2+(22)2+(78)24=0.3750.612

Mermaid Diagram:

Number of Instances: 4
Actual Values: 3, -0.5, 2, 7
Predicted Values: 2.5, 0.0, 2, 8
Squared Errors: 0.25, 0.25, 0, 1
MSE: 0.375
RMSE: 0.612

Root Mean Squared Error (RMSE):

R-squared (R²)

R-squared measures the proportion of the variance in the dependent variable that is predictable from the independent variables. It is calculated as:

R2=1i=1n(yiyi^)2i=1n(yiy¯)2

Where y¯​ is the mean of the actual values.

Example:

R2=1(32.5)2+(0.50.0)2+(22)2+(78)2(33)2+(0.53)2+(23)2+(73)2=10.25+0.25+0+10+12.25+1+16=11.529.250.949

Mermaid Diagram:

Number of Instances: 4
Actual Values: 3, -0.5, 2, 7
Predicted Values: 2.5, 0.0, 2, 8
Mean of Actual Values: 3
Sum of Squared Errors: 1.5
Total Sum of Squares: 29.25
R-squared: 0.949

Here's a markdown table with a range of values for R-squared and Root Mean Squared Error (RMSE) and how they are typically interpreted for machine learning models:

R-squared Interpretation RMSE Interpretation
0.0 - 0.3 Very poor fit High values Poor model performance
0.3 - 0.5 Poor fit Moderate values Moderate model performance
0.5 - 0.7 Moderate fit Low values Good model performance
0.7 - 0.9 Good fit Very low values Excellent model performance
0.9 - 1.0 Excellent fit ~ 0 Perfect model performance (rare)

Adjusted R-squared

Adjusted R-squared is a statistical metric that adjusts the R-squared value to account for the number of predictors in a regression model. It is particularly useful when comparing models with different numbers of predictors or when evaluating the impact of adding or removing predictors from a model.

In simple terms, Adjusted R-squared helps in understanding whether adding more predictors to the model improves its predictive power significantly or not, considering the risk of overfitting.

Let's revisit the previous example and explain why Adjusted R-squared is required:

Suppose we have a regression model with the following data:

The standard R-squared (R2) measures the proportion of the variance in the dependent variable (actual values) that is explained by the independent variables (predicted values). In our example, let's say we calculated (R20.949), indicating that around 94.9% of the variance in the actual values is explained by the model.

However, R-squared has a limitation. It tends to increase with the addition of more predictors, regardless of whether those predictors actually improve the model's predictive power. This can lead to overestimation of the model's performance, especially when including irrelevant variables.

Adjusted R-squared addresses this limitation by penalizing the addition of unnecessary predictors. It takes into account both the goodness of fit (captured by (R2)) and the number of predictors in the model (k). The formula for Adjusted R-squared is:

Adjusted R2=1(1R2)(n1)nk1

Here's why Adjusted R-squared is required:

  1. Controls for Model Complexity: Adjusted R-squared penalizes the inclusion of more predictors, ensuring that the model's improvement in predictive power justifies the added complexity.
  2. Prevents Overfitting: By penalizing unnecessary predictors, Adjusted R-squared helps prevent overfitting, where the model performs well on training data but poorly on new, unseen data.
  3. Facilitates Model Comparison: When comparing models with different numbers of predictors, Adjusted R-squared provides a fair comparison by considering both goodness of fit and model simplicity.

Iour example, let's say we calculated Adjusted R-squared Adjusted R20.898. This value is slightly lower than the standard R-squared, indicating that although the model explains a significant portion of the variance, the addition of predictors might not have provided a substantial improvement in predictive power considering the model's complexity.

Mean Absolute Percentage Error (MAPE)

MAPE measures the average absolute percentage error between the predicted and actual values. It is calculated as:

MAPE=100ni=1n|yiyi^yi|

Example:

MAPE=1004(|32.53|+|0.50.00.5|+|222|+|787|)=1004(0.167+1+0+0.143)=1004(1.31)=32.75

Mermaid Diagram:

Number of Instances: 4
Actual Values: 3, -0.5, 2, 7
Predicted Values: 2.5, 0.0, 2, 8
Percentage Errors: 0.167, 1, 0, 0.143
Sum of Percentage Errors: 1.31
MAPE: 32.75

When to Use Each Metric

These metrics help evaluate the performance of regression models from different perspectives, ensuring a comprehensive understanding of their strengths and weaknesses.


Resources

R Squared

Adjust R Squared

Watch from 8:15