0
0
ML Pythonprogramming~10 mins

Hyperparameter tuning (GridSearchCV) in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the GridSearchCV class from scikit-learn.

ML Python
from sklearn.model_selection import [1]
Drag options to blanks, or click blank then click option'
AGridSearchCV
Bcross_val_score
Ctrain_test_split
DRandomizedSearchCV
Attempts:
3 left
2fill in blank
medium

Complete the code to create a parameter grid for tuning the 'max_depth' of a decision tree.

ML Python
param_grid = {'max_depth': [1]
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4, 5]
B(1, 2, 3, 4, 5)
C{1, 2, 3, 4, 5}
D'1, 2, 3, 4, 5'
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to create a GridSearchCV object with a decision tree classifier and the parameter grid.

ML Python
grid_search = GridSearchCV(estimator=[1], param_grid=param_grid, cv=5)
Drag options to blanks, or click blank then click option'
ADecisionTreeClassifier
BDecisionTree()
CDecisionTreeClassifier()
DDecisionTree
Attempts:
3 left
4fill in blank
hard

Fill both blanks to fit the GridSearchCV model on training data and get the best parameters.

ML Python
grid_search.[1](X_train, y_train)
best_params = grid_search.[2]
Drag options to blanks, or click blank then click option'
Afit
Bbest_params_
Cpredict
Dscore
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to print the best score and make predictions on test data using the best estimator.

ML Python
print(f"Best score: {grid_search.[1]:.3f}")
predictions = grid_search.[2].[3](X_test)
Drag options to blanks, or click blank then click option'
Abest_score_
Bbest_estimator_
Cpredict
Dscore
Attempts:
3 left