Regression Evaluation Metrics

Evaluating regression models involves various metrics to assess their predictive performance. Each metric provides a unique perspective on the model's errors and goodness of fit.

1. Mean Absolute Error (MAE)

Measures the average magnitude of errors:

$$ \text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i| $$

2. Mean Squared Error (MSE)

Measures the average squared differences:

$$ \text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $$

3. Root Mean Squared Error (RMSE)

Provides error in the same units as the target variable:

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

4. R-squared (R²)

Indicates the proportion of variance explained by the model:

$$ R^2 = 1 - \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i - \bar{y})^2} $$
from sklearn.metrics import mean_squared_error, r2_score

mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)

print(f"MSE: {mse}")
print(f"R²: {r2}")