Skip to main content
Albero Academy

Regularization

Ridge and Lasso — prevent overfitting by shrinking coefficients.

Regression9 min

A plain linear model can overfit — chasing noise with large coefficients. Regularization adds a penalty on coefficient size, shrinking them toward zero for a simpler, more generalisable model.

Ridge vs Lasso

ModelPenaltyEffect
RidgeL2 (sum of squares)Shrinks all coefficients smoothly
LassoL1 (sum of absolutes)Drives some coefficients to exactly 0 (feature selection)
ElasticNetL1 + L2A blend of both
alpha controls the strength
from sklearn.linear_model import Ridge, Lasso
Ridge(alpha=1.0).fit(X_train, y_train) # larger alpha → more shrinkage
Lasso(alpha=0.1).fit(X_train, y_train) # some coefficients become exactly 0

Key takeaways

  1. 01Regularization penalises large coefficients to reduce overfitting.
  2. 02Ridge (L2) shrinks all coefficients; Lasso (L1) zeroes some out (feature selection).
  3. 03alpha controls strength — tune it with cross-validation.
  4. 04Always scale features before regularised regression.

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.