DATABRICKS-MACHINE-LEARNING-ASSOCIATE practice question 6 of 15

A data scientist is attempting to tune a logistic regression model logistic using scikit-learn. They want to specify a search space for two hyperparameters and let the tuning process randomly select values for each evaluation. They attempt to run the following code block, but it does not accomplish the desired task: Which of the following changes can the data scientist make to accomplish the task?

Full set: 74 questions
Answer options
A: Replace the GridSearchCV operation with RandomizedSearchCV Correct answer
B: Replace the GridSearchCV operation with cross_validate
C: Replace the GridSearchCV operation with ParameterGrid
D: Replace the random_state=0 argument with random_state=1
E: Replace the penalty= ['12', '11'] argument with penalty=uniform ('12', '11')
Correct Answer:
A. Replace the GridSearchCV operation with RandomizedSearchCV
Explanation

The user's objective is to perform hyperparameter tuning by randomly selecting values from a specified search space. The GridSearchCV operation performs an exhaustive search, evaluating every possible combination of the provided hyperparameter values. This does not meet the requirement for random selection. The correct tool in the scikit-learn library for this task is RandomizedSearchCV, which samples a fixed number of parameter settings from the specified distributions. Replacing GridSearchCV with RandomizedSearchCV directly accomplishes the desired random tuning process.

Why Incorrect

B. crossvalidate is a function used to evaluate a model's performance with cross-validation but does not perform hyperparameter tuning over a search space.
C. ParameterGrid is a helper class that generates combinations of parameters but does not perform the actual model fitting or cross-validated search.
D. Changing the randomstate argument affects reproducibility but does not change the fundamental search algorithm from an exhaustive grid search to a random search.
E. GridSearchCV requires a list of discrete values for its parameters, not a statistical distribution. This change would cause an error and not alter the search method.

References

1. Official Databricks Documentation: In the "Hyperparameter tuning with scikit-learn and MLflow" guide

Databricks explains the two main approaches: "GridSearchCV...tries all possible combinations" and "RandomizedSearchCV...tries a fixed number of random combinations." This directly supports using RandomizedSearchCV for random selection.

Source: Databricks Documentation > Machine Learning > Model training > Hyperparameter tuning > scikit-learn and MLflow > Section: "Tune hyperparameters".

2. Official scikit-learn Documentation: The user guide explicitly contrasts the two methods. It states

"While GridSearchCV is a good method for finding parameters in a grid

RandomizedSearchCV can be preferred... It samples a given number of candidates from a parameter space with a specified distribution."

Source: scikit-learn User Guide > 3.2. Tuning the hyper-parameters of an estimator > Section 3.2.3. "Randomized search".

3. University Courseware: Stanford University's CS229 (Machine Learning) course materials often discuss hyperparameter tuning strategies

explaining that Grid Search can be computationally expensive and that Randomized Search is often a more efficient alternative for exploring a large parameter space.

Source: Stanford University

CS229: Machine Learning

Lecture Notes

"Advice for Applying Machine Learning

" Section on "Model Selection and Hyperparameter Tuning." (Illustrates the conceptual difference between grid and random search).

Scroll to Top