Linear Regression model অনেক features ব্যবহার করলে বা features strongly correlated হলে coefficients অনেক বড় হয়ে যেতে পারে।

এতে model training data-এর noise-এর সাথে অতিরিক্ত fit হয়ে overfit করতে পারে।

এই complexity control করার জন্য Regularization ব্যবহার করা হয়।

Core Idea

Normal model objective:

Minimize Prediction Error

Regularization যোগ করলে:

Prediction Loss
+
Complexity Penalty

অর্থাৎ শুধু ভালো fit হলেই হবে না।

Model-কে unnecessary large coefficients-এর জন্য penalty-ও দেওয়া হবে।

Ridge Regression — L2 Regularization

Ridge regression-এর objective:

$$\text{ Loss } = \text{ SSE } + \lambda\sum_{j}\beta_{j}^{2}$$

এখানে:

SSE   → Prediction error
β     → Model coefficients
λ     → Regularization strength

Ridge বড় coefficients-কে penalize করে।

ফলে coefficients সাধারণত shrink হয়ে ছোট হয়।

Ridge-এর গুরুত্বপূর্ণ বৈশিষ্ট্য

Ridge সাধারণত coefficients:

Smaller করে

কিন্তু:

Exactly zero করে না

তাই Ridge feature selection করার চেয়ে coefficient stabilization-এর জন্য বেশি useful।

Lasso Regression — L1 Regularization

Lasso-এর objective:

$$\text{ Loss } = \text{ SSE } + \lambda\sum_{j}|\beta_{j}|$$

এখানে coefficients-এর absolute value penalty হিসেবে ব্যবহার করা হয়।

Lasso-এর গুরুত্বপূর্ণ বৈশিষ্ট্য হলো কিছু coefficient:

Exactly 0

হয়ে যেতে পারে।

অর্থাৎ Lasso implicit feature selection করতে পারে।

Example

ধরুন model-এর coefficients:

Feature A → 4.2
Feature B → 0.0
Feature C → 1.7
Feature D → 0.0

তাহলে B ও D effectively model থেকে বাদ গেছে।

Elastic Net

Elastic Net হলো:

L1 + L2

regularization-এর combination।

এটি useful হতে পারে যখন:

অনেক features আছে correlated predictors আছে কিছু sparsity চাই coefficient stability-ও চাই

Lambda — λ

$$\lambda$$

regularization strength control করে।

যদি:

λ = 0

তাহলে essentially regularization নেই।

λ বাড়ালে penalty বাড়ে।

Small λ
→ Weak regularization

Large λ
→ Strong regularization

কিন্তু λ খুব বড় হলে coefficients অতিরিক্ত shrink হয়ে:

Underfitting

হতে পারে।

Ridge vs Lasso

Ridge
→ L2 penalty
→ Shrinks coefficients
→ Usually not exactly zero

Lasso
→ L1 penalty
→ Can make coefficients zero
→ Feature selection effect

Interview-ready Explanation

Regularization helps reduce overfitting by adding a penalty
for model complexity.

Ridge regression uses an L2 penalty, which shrinks large
coefficients but usually does not make them exactly zero.

Lasso uses an L1 penalty and can force some coefficients
to exactly zero, so it can also perform feature selection.

Elastic Net combines both L1 and L2 regularization.