Lesson 13 of 18 · 2 min
Model Evaluation Metrics
WHY evaluate? Building a model is easy. Knowing if it's GOOD is the hard part. These metrics measure how wrong your predictions are.
MAE — Mean Absolute Error
Average of |actual - predicted| values. Ignores direction (over/under). Easy to interpret.
Formula: MAE = (1/n) × Σ|actual - predicted|
Example:
- Predicted: 250,000 | Actual: 300,000 → error = 50,000
- Predicted: 280,000 | Actual: 260,000 → error = 20,000
- MAE = (50,000 + 20,000) / 2 = 35,000
Interpretation: "On average, predictions are off by 35,000"
MSE — Mean Squared Error
Average of (actual - predicted)² values. Squares errors — penalizes large errors much more.
Formula: MSE = (1/n) × Σ(actual - predicted)²
Problem: units are squared (dollars² not dollars) — hard to interpret directly.
Use: detecting if model makes occasional huge errors (outlier predictions).
RMSE — Root Mean Squared Error
Square root of MSE. Brings units back to original scale. Most commonly used metric.
Formula: RMSE = √MSE
Interpretation: same unit as target (dollars, degrees, etc.)
Rule of thumb: RMSE < 10% of target's mean range = good model.
import numpy as np
# Calculate all three metrics
mae = mean_absolute_error(y_test, y_pred)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
print(f"MAE: {mae:.4f}") # average error in $100k units
# Output: MAE: 0.5310
print(f"MSE: {mse:.4f}") # squared error
# Output: MSE: 0.4821
print(f"RMSE: {rmse:.4f}") # most useful — same unit as price
# Output: RMSE: 0.6943
# Convert to actual dollars (prices are in $100,000s)
print(f"\nMAE in dollars: ${mae * 100000:,.0f}")
print(f"RMSE in dollars: ${rmse * 100000:,.0f}")
# R² score — % of variance explained by model (1.0 = perfect)
from sklearn.metrics import r2_score
r2 = r2_score(y_test, y_pred)
print(f"R² Score: {r2:.4f}") # e.g. 0.62 = model explains 62% of variance
# Output: R²: 0.8532 Adjusted R²: 0.8489
