Fantastisk!
Completion rate forbedret til 8.33Sektion 1. Kapitel 4
single
Challenge: Compare Ridge and Lasso on Real Data
Stryg for at vise menuen
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 4
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat