Explore Library
Code Quiz

Regularization Strength and Overfitting

Spot the mistake in tuning Ridge regularization to fix an overfitting model.

Codepython
from sklearn.linear_model import Ridge

# The linear model is overfitting: near-perfect on train,
# poor on validation (high variance).
# Goal: add regularization to reduce variance.
model = Ridge(alpha=0.0001)
model.fit(X_train, y_train)

print('Train R2:', model.score(X_train, y_train))
print('Val   R2:', model.score(X_val, y_val))

The model keeps overfitting even after this change. What is the bug?