0
0
ML Pythonprogramming~20 mins

RandomizedSearchCV in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RandomizedSearchCV Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding RandomizedSearchCV Sampling

Which statement best describes how RandomizedSearchCV selects hyperparameter combinations during tuning?

AIt tries every possible combination of hyperparameters exhaustively.
BIt randomly samples a fixed number of hyperparameter combinations from the specified distributions.
CIt selects hyperparameters based on a gradient descent optimization.
DIt uses a genetic algorithm to evolve hyperparameter sets over iterations.
Attempts:
2 left
Predict Output
intermediate
2:00remaining
Output of RandomizedSearchCV Best Parameters

What will be the output of the following code snippet?

ML Python
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV
import numpy as np

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

param_dist = {'n_estimators': [10, 50], 'max_depth': [2, 4]}
clf = RandomForestClassifier(random_state=42)

search = RandomizedSearchCV(clf, param_distributions=param_dist, n_iter=2, random_state=42)
search.fit(X, y)
print(search.best_params_)
A{'n_estimators': 10, 'max_depth': 2}
B{'n_estimators': 50, 'max_depth': 4}
C{'n_estimators': 10, 'max_depth': 4}
D{'n_estimators': 50, 'max_depth': 2}
Attempts:
2 left
Hyperparameter
advanced
2:00remaining
Choosing n_iter in RandomizedSearchCV

What is the effect of increasing the n_iter parameter in RandomizedSearchCV?

AIt increases the number of hyperparameter combinations tested, potentially improving model performance but increasing computation time.
BIt sets the maximum depth of the decision trees in the model.
CIt decreases the number of cross-validation folds used during evaluation.
DIt controls the learning rate of the model during training.
Attempts:
2 left
Metrics
advanced
2:00remaining
Evaluating RandomizedSearchCV Results

After running RandomizedSearchCV, which attribute gives the mean test score for each parameter combination tested?

Asearch.best_score_
Bsearch.score(X_test, y_test)
Csearch.cv_results_['mean_test_score']
Dsearch.best_params_
Attempts:
2 left
🔧 Debug
expert
2:00remaining
Debugging RandomizedSearchCV with Incorrect Parameter Distribution

What error will the following code raise?

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV

iris = load_iris()
X_train, y_train = iris.data, iris.target

param_dist = {'n_estimators': 100, 'max_depth': [3, 5, 7]}
clf = RandomForestClassifier()
search = RandomizedSearchCV(clf, param_distributions=param_dist, n_iter=2)
search.fit(X_train, y_train)
AValueError: Parameter distribution for 'n_estimators' must be a list or distribution
BNo error, runs successfully
CAttributeError: 'RandomForestClassifier' object has no attribute 'fit'
DTypeError: 'int' object is not iterable
Attempts:
2 left