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.
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Awesome!
Completion rate improved to 8.33
Challenge: Compare Ridge and Lasso on Real Data
Glissez pour afficher le 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.
Solution
Merci pour vos commentaires !
single