Evaluation Metrics#
To evaluate regression models, we use several metrics:
Mean Squared Error (MSE)#
Penalizes large errors more
Commonly used in optimization
Why Mean Squared Error (MSE)?#
MSE is widely used because:
It strongly penalizes large mistakes
It leads to a smooth optimization surface
It has a closed-form solution (OLS)
It works well with gradient-based optimization
Alternative Error Measures (Brief Insight)#
Although MSE is standard, other options exist:
MAE (Mean Absolute Error) → treats all errors equally
RMSE → same unit as target variable
Each metric emphasizes different aspects of model performance.
Mean Absolute Error (MAE)#
Easy to interpret
Treats all errors equally
Root Mean Squared Error (RMSE)#
Same unit as the target variable
Easier to interpret than MSE
R-squared (R²)#
Measures how well the model explains variance
Value ranges from 0 to 1
1 → perfect fit
0 → no explanatory power (Model explains nothing (same as predicting the mean))
Understanding the Components#
Total Sum of Squares ((SS_{tot}))
$\(
SS_{tot} = \sum (y_i - \bar{y})^2
\)$
Captures the total variation in the data
Measures how far actual values are from the mean
Represents the baseline (no model)
Residual Sum of Squares ((SS_{res}))
$\(
SS_{res} = \sum (y_i - \hat{y}_i)^2
\)$
Captures the unexplained variation
Measures how far predictions are from actual values
Represents model error
Intuition#
(SS_{tot}): Total variability in data
(SS_{res}): Remaining error after modeling
Remember:
Smaller \(SS_{res}\) → better fit → higher \(R^2\)
If \(SS_{res} = 0\), then \(R^2 = 1\) (perfect model)
Simple Takeaway#
R² tells us what fraction of the data’s variability (spread) is explained by the model.
# Evaluating the Model
from sklearn.metrics import mean_squared_error, r2_score
mse = mean_squared_error(y_test, predictions)
r2 = r2_score(y_test, predictions)
print("MSE:", mse)
print("R2 Score:", r2