Creating a LASSO regressor
You'll be working on the numeric ANSUR body measurements dataset to predict a persons Body Mass Index (BMI) using the pre-imported Lasso()
regressor. BMI is a metric derived from body height and weight but those two features have been removed from the dataset to give the model a challenge.
You'll standardize the data first using the StandardScaler()
that has been instantiated for you as scaler
to make sure all coefficients face a comparable regularizing force trying to bring them down.
All necessary functions and classes plus the input datasets X
and y
have been pre-loaded.
This exercise is part of the course
Dimensionality Reduction in Python
Exercise instructions
- Set the test size to 30% to get a 70-30% train test split.
- Fit the scaler on the training features and transform these in one go.
- Create the Lasso model.
- Fit it to the scaled training data.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Set the test size to 30% to get a 70-30% train test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=____, random_state=0)
# Fit the scaler on the training features and transform these in one go
X_train_std = scaler.____
# Create the Lasso model
la = ____()
# Fit it to the standardized training data
la.____