Comparison of Linear, Ridge, and Lasso Regression with Model Evaluation
Experiment
Comparison of Linear, Ridge, and Lasso Regression with Model Evaluation
馃幆 Aim
To compare Ordinary Linear Regression, Ridge Regression, and Lasso Regression using evaluation metrics (MSE and R²) and visualize their performance.
Objectives
- Generate sample dataset
- Apply polynomial transformation
- Train Linear, Ridge, and Lasso models
- Evaluate using MSE and R²
- Compare coefficients
- Visualize model behavior
馃洜️ Tools Required
- Python
- NumPy
- Matplotlib
- Scikit-learn
馃摉 Theory
In Machine Learning, Linear Regression may perform poorly when:
- the dataset has many features,
- features are highly correlated,
- the model overfits training data.
To overcome this problem, Regularization techniques are used.
Two important regularization methods are:
- Ridge Regression (L2 Regularization)
- Lasso Regression (L1 Regularization)
These techniques reduce overfitting by adding a penalty term to the cost function.
馃敼 Regularization
✅ reduce model complexity
✅ prevent overfitting
✅ improve generalization
It works by penalizing large coefficient values.
Regularization prevents overfitting by adding a penalty term:
馃數 Ridge Regression (L2 Regularization)
Ridge Regression adds the squared magnitude of coefficients as penalty.
馃搶 Ridge Cost Function
馃搶 Penalty Term
This is called:
馃搶 Meaning of 位 (Lambda)
controls regularization strength.
| 位 Value | Effect |
|---|---|
| Small 位 | behaves like normal regression |
| Large 位 | stronger regularization |
馃搶 Effect of Ridge Regression
- Shrinks coefficients toward zero
- Reduces variance
- Keeps all features
- Handles multicollinearity well
馃搶 Geometric Interpretation
Ridge creates a circular constraint region.
馃搶 Advantages of Ridge Regression
✅ Reduces overfitting
✅ Works well with correlated features
✅ Stable model coefficients
馃煝 Lasso Regression (L1 Regularization)
馃搶 Definition
Lasso Regression adds the absolute value of coefficients as penalty.
馃搶 Lasso Cost Function
馃搶 Penalty Term
This is called:
馃搶 Effect of Lasso Regression
- Shrinks coefficients
- Some coefficients become exactly zero
- Performs feature selection automatically
馃搶 Geometric Interpretation
Lasso creates a diamond-shaped constraint.
Corners increase chance of coefficients becoming zero.
馃搶 Advantages of Lasso
✅ Performs feature selection
✅ Reduces overfitting
✅ Produces sparse models
- Ridge (L2) → shrinks coefficients
- Lasso (L1) → shrinks + eliminates coefficients
馃敼 Evaluation Metrics
Mean Squared Error (MSE)
R-squared (R²)
馃搵 Procedure
- Generate noisy dataset
- Apply high-degree polynomial features
- Split into train and test sets
-
Train:
- Linear Regression
- Ridge Regression
- Lasso Regression
- Evaluate using MSE and R²
- Plot regression curves
- Compare coefficients
馃捇 Program
馃搳 Sample Output
馃搱 Interpretation
-
Linear Regression
- May overfit (high variance)
- Higher MSE
-
Ridge Regression
- Best balance
- Lower MSE, higher R²
-
Lasso Regression
- Slightly higher error than Ridge
- Simpler model (fewer features)
馃搳 Observations
| Model | MSE | R² | Behavior |
|---|---|---|---|
| Linear | High | Lower | Overfitting |
| Ridge | Lowest | Highest | Best generalization |
| Lasso | Moderate | Good | Feature selection |
Result
Ridge and Lasso regression improved model performance compared to ordinary linear regression by reducing overfitting and improving generalization.
- Regularization improves model efficiency
- Ridge is better when all features are important
- Lasso is useful for feature selection
- Evaluation metrics help choose the best model

Comments
Post a Comment