LASSO and Ridge Regression


馃Regularization

Regularization modifies the learning objective to:

Minimize: Loss + Penalty\text{Minimize: Loss + Penalty}

馃憠 Purpose:

  • Control model complexity
  • Prevent overfitting
  • Improve generalization

馃敺 Ridge Regression (L2 Regularization)


馃搻 Objective Function

minw(i=1n(yiwTxi)2+j=1dwj2)\min_{w} \left( \sum_{i=1}^{n} (y_i - w^T x_i)^2 + \lambda \sum_{j=1}^{d} w_j^2 \right)


馃攳 Key Idea

  • Penalizes square of coefficients
  • Larger weights → heavily penalized

馃幆 Effects

  • Shrinks coefficients toward zero
  • No coefficient becomes exactly zero
  • Keeps all features

馃З Properties

  • Produces smooth models
  • Handles multicollinearity well
  • Reduces model variance

馃搳 Intuition

Think of it as:

“Discouraging large weights, but not eliminating features”


馃敹 LASSO Regression (L1 Regularization)

Least Absolute Shrinkage and Selection Operator


馃搻 Objective Function

minw(i=1n(yiwTxi)2+j=1dwj)


馃攳 Key Idea

  • Penalizes absolute value of coefficients

馃幆 Effects

  • Some coefficients become exactly zero
  • Performs automatic feature selection

✂️ Sparsity

馃憠 Key property:

  • Produces sparse models
  • Removes irrelevant features

馃搳 Intuition

Think of it as:

“Forcing the model to keep only the most important features”


⚖️ Core Differences (Geometric Insight)


AspectRidge (L2)LASSO (L1)
Constraint shape    Circle    Diamond
Boundary    Smooth    Sharp corners
Result    Shrink weights    Zero out weights

馃憠 Sharp corners in LASSO → sparsity





馃搳 Behavior Comparison


馃敼 Coefficient Shrinkage

Feature    Ridge    LASSO
x₁    2.2    2.1
x₂    1.6        1.5
x₃    0.8    0
x₄    0.6    0

馃敼 Key Observations

  • Ridge → all features retained
  • LASSO → some features removed

⚖️Detailed Comparison Table

CriterionRidge (L2)LASSO (L1)
Penalty                        |w2w^2|    |w|
Sparsity    No    Yes
Feature selectionNo        Yes
StabilityHigh    Lower
Correlated featuresShares weights    Picks one feature
ComputationClosed form    Iterative

馃Bias–Variance Perspective

ModelBias    Variance
Ridge    Moderate    Low
LASSO    Higher    Low

馃攳 Effect of Regularization Parameter (位)


馃敼 Small 位

  • Both behave like ordinary regression

馃敼 Medium 位

  • Ridge → shrink coefficients
  • LASSO → shrink + remove some

馃敼 Large 位

  • Ridge → all weights very small
  • LASSO → most weights = 0

馃И Practical Considerations


馃敼 Feature Scaling (Important!)

  • Required for both methods

馃敼 Model Selection

  • Choose 位 using:
    • Validation set
    • Cross-validation

馃Intuitive Analogies


Ridge:

“Keep all features, but reduce their influence”


LASSO:

“Select only the most important features”


馃煟When to Use Which?


馃敺 Use Ridge when:

  • Many correlated features
  • All features are important
  • Need stable model

馃敹 Use LASSO when:

  • Many irrelevant features
  • Need feature selection
  • Want interpretable model

馃敆 Connection: Elastic Net

Combines both:

1w+2w2\lambda_1 \sum |w| + \lambda_2 \sum w^2

馃憠 Useful when:

  • Features are correlated
  • Need both sparsity and stability

馃幆Key Takeaways

  • Both methods reduce overfitting
  • Ridge → smooth shrinkage
  • LASSO → sparse solutions

Use Case    Preferred Method
Many correlated features          Ridge
Feature selection needed          LASSO
Balanced approach          Elastic Net

Comments

Popular posts from this blog

Machine Learning PCCST503 Semester5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Machine Learning (ML)

Distinguishing Machine Learning from Traditional Programming