Challenge: Compare Ridge and Lasso on Real Data
Swipe to start coding
In this challenge, you will compare Ridge and Lasso regression on a real dataset to see how regularization strength affects model performance and coefficient magnitudes.
You will use the Diabetes dataset from scikit-learn, which is a standard regression dataset with 10 input features and a continuous target variable.
Your goals are:
- Load the dataset and split it into training and testing sets (70% / 30%).
- Fit two models:
- A Ridge regression model with
alpha=1.0 - A Lasso regression model with
alpha=0.1
- A Ridge regression model with
- Evaluate both models using R² score and Mean Squared Error (MSE) on the test set.
- Compare their coefficients to observe how Lasso drives some coefficients toward zero (feature selection effect).
- Print the metrics and model coefficients for each model.
Soluzione
Grazie per i tuoi commenti!
single
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Can you explain that in more detail?
What are the main benefits or drawbacks?
Can you provide an example?
Awesome!
Completion rate improved to 8.33
Challenge: Compare Ridge and Lasso on Real Data
Scorri per mostrare il menu
Swipe to start coding
In this challenge, you will compare Ridge and Lasso regression on a real dataset to see how regularization strength affects model performance and coefficient magnitudes.
You will use the Diabetes dataset from scikit-learn, which is a standard regression dataset with 10 input features and a continuous target variable.
Your goals are:
- Load the dataset and split it into training and testing sets (70% / 30%).
- Fit two models:
- A Ridge regression model with
alpha=1.0 - A Lasso regression model with
alpha=0.1
- A Ridge regression model with
- Evaluate both models using R² score and Mean Squared Error (MSE) on the test set.
- Compare their coefficients to observe how Lasso drives some coefficients toward zero (feature selection effect).
- Print the metrics and model coefficients for each model.
Soluzione
Grazie per i tuoi commenti!
single