Evaluating Regression Models
How do we know if our regression model is any good? For numbers, we can't just measure "accuracy" (it's almost impossible to predict exactly $312,456.78). Instead, we measure how far off our predictions are from the true values.
Calculate MSE and R² score for these predictions using scikit-learn.
from sklearn.metrics import mean_squared_error, r2_score
# Actual house prices and our model's predictions (in thousands)
y_actual = [300, 450, 200, 600, 350]
y_pred = [310, 440, 210, 580, 360]
# TODO: Calculate MSE
# mse = ???
# TODO: Calculate R2 Score
# r2 = ???
# print(f"MSE: {mse}")
# print(f"R² Score: {r2}")These metrics help us compare different models and choose the one that makes the smallest errors on our test set.