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

bookChallenge: Compare Ridge and Lasso on Real Data

Uppgift

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 allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 4
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you explain that in more detail?

What are the main benefits or drawbacks?

Can you provide an example?

close

Awesome!

Completion rate improved to 8.33

bookChallenge: Compare Ridge and Lasso on Real Data

Svep för att visa menyn

Uppgift

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 desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 4
single

single

some-alt