GNGiseldo Neo and Alana NeoBooks
Linear Regression with Python8 / 19

Evaluation Metrics

Evaluating the performance of a linear regression model is crucial for ensuring its effectiveness in making predictions. Evaluation metrics allow us to quantify the model’s accuracy and identify areas for improvement. This chapter details the main metrics used to evaluate regression models.

7.1 Coefficient of Determination (R2R^2)

The Coefficient of Determination, R2R^2, is a metric that indicates the proportion of variability in the dependent variable that is explained by the independent variables in the model.

Calculation

R2R^2 is calculated as:

R2=1−Sum of Squared Residuals (SSR)Total Sum of Squares (SST)R^2 = 1 - \frac{\textit{Sum of Squared Residuals (SSR)}}{\textit{Total Sum of Squares (SST)}}

Where:

  • SSR is the sum of the squared differences between the observed and predicted values.

  • SST is the sum of the squared differences between the observed values and the mean of the observed values.

Interpretation

An R2R^2 of 1 indicates a perfect fit, whereas an R2R^2 of 0 indicates that the model explains none of the variability in the data. However, a high R2R^2 does not always indicate a good model, especially in multiple regression models, where overfitting may occur.

7.2 Mean Squared Error (MSE)

Mean Squared Error (MSE) is a metric that computes the average of the squared errors, or differences, between the observed and predicted values.

Calculation

MSE is given by:

MSE=1n∑i=1n(yi−y^i)2MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2

Where yiy_i are the observed values and y^i\hat{y}_i are the predicted values.

Interpretation

A lower MSE indicates that the model fits the data better. However, MSE is sensitive to outliers because the errors are squared.

7.3 Root Mean Squared Error (RMSE)

Root Mean Squared Error (RMSE) is the square root of MSE and provides a measure of the magnitude of prediction errors.

Calculation

RMSE is calculated as:

RMSE=1n∑i=1n(yi−y^i)2RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2}

Interpretation

RMSE is expressed in the same units as the dependent variable, making it easier to interpret. Like MSE, RMSE is sensitive to outliers, but it is often preferred due to its direct interpretability.

7.4 Mean Absolute Error (MAE)

Mean Absolute Error (MAE) is the average of the absolute differences between the observed and predicted values, providing a clear measure of the model’s average error.

Calculation

MAE is given by:

MAE=1n∑i=1n∣yi−y^i∣MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|

Interpretation

MAE is less sensitive to outliers than MSE or RMSE because it does not square the errors. It is useful for understanding the average error in the units of the predicted value.

7.5 Choosing a Metric

The choice of evaluation metric depends on the context and characteristics of the dataset. In scenarios where outliers are common, MAE may be more appropriate, whereas RMSE may be preferred when large errors are particularly undesirable.

7.6 Model Comparison

Using multiple metrics together can provide a more complete view of model performance. This helps strike a balance between fitting the data (bias) and model complexity (variance).