Regression Metrics, the game
MAE, MSE, RMSE, max error, R² and adjusted R²: drag a bad prediction around and watch every metric react. Then compute them all in a few lines of Python.
Measuring errors
Every error metric starts from the same residuals (actual − predicted), then summarizes them differently:
Max error is simply the single worst miss. For all four, lower is better and 0 is perfect.
Actual values are 3, 5, 2 and predictions are 2, 5, 4. What is the MAE?
Outlier lab
Ten house prices (₹ lakh) and a model’s predictions. Drag the prediction for house 10 away from its true price of 70 and watch which metrics explode. Then change the number of features to see adjusted R² react.
These are example numbers chosen to show how the metrics behave.
- ✓Create a miss of 30 or more and compare MAE with RMSE+30 XP
- ✓Make house 10’s prediction perfect+20 XP
- ✓Raise the feature count until adjusted R² falls well below R²+30 XP
R² and adjusted R²
R² is the share of the target’s variance the model explains: 1 is perfect, 0 is no better than predicting the mean, and it can even go negative on test data.
Adjusted R² only rises if a new feature improves the model more than chance would.
Code it in Python
The article’s workflow on the California housing data (the text says “Boston”, but the code loads California housing).
Step 1Train a model
import numpy as np
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error, mean_squared_error, max_error, r2_score
X, y = fetch_california_housing(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
y_pred = LinearRegression().fit(X_train, y_train).predict(X_test)Step 2Compute every metric
mae = mean_absolute_error(y_test, y_pred)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
max_err = max_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
n, p = X_test.shape
adj_r2 = 1 - (1 - r2) * (n - 1) / (n - p - 1)
print(f"MAE {mae:.2f} | MSE {mse:.2f} | RMSE {rmse:.2f} | Max {max_err:.2f} | R² {r2:.2f} | Adj R² {adj_r2:.2f}")scikit-learn has no built-in adjusted R². What do you need to compute it?
Defeat the Metrics Boss 🐲
Seven questions, three hearts.
You’re a Metrics Master!
Keep levelling up
You learned what MAE, MSE, RMSE, max error, R² and adjusted R² measure, how outliers affect each one, and how to compute them all with scikit-learn.