0
0
ML Pythonprogramming~20 mins

Hyperparameter tuning (GridSearchCV) in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GridSearchCV Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding GridSearchCV's purpose

What is the main goal of using GridSearchCV in machine learning?

ATo visualize the training data in multiple dimensions.
BTo reduce the size of the training dataset automatically.
CTo find the best combination of hyperparameters by exhaustively searching a specified parameter grid using cross-validation.
DTo train a model faster by skipping validation steps.
Attempts:
2 left
Predict Output
intermediate
2:00remaining
Output of GridSearchCV best parameters

What will be the output of print(grid_search.best_params_) after running the following code?

ML Python
from sklearn.datasets import load_iris
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV

iris = load_iris()
X, y = iris.data, iris.target

param_grid = {'C': [0.1, 1], 'kernel': ['linear', 'rbf']}
svc = SVC()
grid_search = GridSearchCV(svc, param_grid, cv=3)
grid_search.fit(X, y)
print(grid_search.best_params_)
A{'C': 1, 'kernel': 'rbf'}
B{'C': 0.1, 'kernel': 'rbf'}
C{'C': 1, 'kernel': 'linear'}
D{'C': 0.1, 'kernel': 'linear'}
Attempts:
2 left
Hyperparameter
advanced
2:00remaining
Choosing hyperparameters for GridSearchCV

Which set of hyperparameters is most appropriate to tune for a Random Forest classifier using GridSearchCV to improve model performance?

A{'learning_rate': [0.01, 0.1], 'activation': ['relu', 'tanh']}
B{'n_estimators': [10, 50, 100], 'max_depth': [None, 10, 20], 'min_samples_split': [2, 5]}
C{'kernel': ['linear', 'poly'], 'C': [0.1, 1]}
D{'alpha': [0.0001, 0.001], 'max_iter': [1000, 2000]}
Attempts:
2 left
Metrics
advanced
1:30remaining
Evaluating GridSearchCV results

After running GridSearchCV, which attribute provides the mean test scores for each parameter combination tested?

Agrid_search.best_score_
Bgrid_search.score(X_test, y_test)
Cgrid_search.best_params_
Dgrid_search.cv_results_['mean_test_score']
Attempts:
2 left
🔧 Debug
expert
2:00remaining
Identifying error in GridSearchCV usage

What error will the following code raise when executed?

from sklearn.datasets import load_iris
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV

iris = load_iris()
X, y = iris.data, iris.target

param_grid = {'C': [1, 10], 'kernel': ['linear', 'rbf']}
svc = SVC()
grid_search = GridSearchCV(svc, param_grid, cv=3)
grid_search.fit(X, y)
print(grid_search.best_params_)
print(grid_search.best_estimator_)
print(grid_search.predict(X))
ANameError because 'grid_search' is not defined
BTypeError because 'param_grid' has invalid types
CValueError because 'cv' parameter is invalid
DNo error, code runs successfully
Attempts:
2 left