Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Compare Ridge and Lasso on Real Data | Regularization Fundamentals
Feature Selection and Regularization Techniques

bookChallenge: Compare Ridge and Lasso on Real Data

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:

  1. Load the dataset and split it into training and testing sets (70% / 30%).
  2. Fit two models:
    • A Ridge regression model with alpha=1.0
    • A Lasso regression model with alpha=0.1
  3. Evaluate both models using R² score and Mean Squared Error (MSE) on the test set.
  4. Compare their coefficients to observe how Lasso drives some coefficients toward zero (feature selection effect).
  5. Print the metrics and model coefficients for each model.

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 4
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

Awesome!

Completion rate improved to 8.33

bookChallenge: 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:

  1. Load the dataset and split it into training and testing sets (70% / 30%).
  2. Fit two models:
    • A Ridge regression model with alpha=1.0
    • A Lasso regression model with alpha=0.1
  3. Evaluate both models using R² score and Mean Squared Error (MSE) on the test set.
  4. Compare their coefficients to observe how Lasso drives some coefficients toward zero (feature selection effect).
  5. Print the metrics and model coefficients for each model.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 4
single

single

some-alt