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

bookChallenge: Compare Ridge and Lasso on Real Data

Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

Awesome!

Completion rate improved to 8.33

bookChallenge: Compare Ridge and Lasso on Real Data

Scorri per mostrare il menu

Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
single

single

some-alt