Hyperparameter tuning with GridSearchCV
Now you have seen how to perform grid search hyperparameter tuning, you are going to build a lasso regression model with optimal hyperparameters to predict blood glucose levels using the features in the diabetes_df dataset.
X_train, X_test, y_train, and y_test have been preloaded for you. A KFold() object has been created and stored for you as kf, along with a lasso regression model as lasso.
Questo esercizio fa parte del corso
Supervised Learning with scikit-learn
Istruzioni dell'esercizio
- Import
GridSearchCV. - Set up a parameter grid for
"alpha", usingnp.linspace()to create 20 evenly spaced values ranging from0.00001to1. - Call
GridSearchCV(), passinglasso, the parameter grid, and settingcvequal tokf. - Fit the grid search object to the training data to perform a cross-validated grid search.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Import GridSearchCV
____
# Set up the parameter grid
param_grid = {"____": np.linspace(____, ____, ____)}
# Instantiate lasso_cv
lasso_cv = ____(____, ____, cv=____)
# Fit to the training data
____
print("Tuned lasso paramaters: {}".format(lasso_cv.best_params_))
print("Tuned lasso score: {}".format(lasso_cv.best_score_))