Databricks Machine Learning Associate · Section 3 · 31% of the exam
Perform random or grid search or Bayesian search as a method for tuning hyperparameters.
One of the objectives of the Databricks Certified Machine Learning Associate exam, in the section “Model Development”. Here is what it covers, the points to remember and a question to try.
What it covers
Hyperparameters are set before training and tuned by searching a space of candidates: exhaustively (grid), by sampling (random) or adaptively from past results (Bayesian, for example TPE). The exam tests Hyperopt's fmin and SparkTrials; Hyperopt is no longer maintained, so Databricks now recommends Optuna (and Ray Tune for distributed tuning). Independent trials of single-node models can run in parallel on Spark workers.
Points to remember
- Grid search tries every combination; random search samples a fixed budget; Bayesian search (TPE) uses past results to pick the next trial and usually needs fewer trials.
fmin(fn, space, algo, max_evals, trials)minimizes; the objective returns a loss or{'loss': ..., 'status': STATUS_OK}.- Algorithms:
tpe.suggest(Bayesian TPE),rand.suggest(random),atpe.suggest(adaptive TPE). Hyperopt has no grid algorithm. - Negate metrics where higher is better;
hp.choiceresults are indexes (usespace_eval);hp.loguniformbounds are logs;hp.quniformreturns floats. SparkTrials(parallelism, timeout)runs single-node trials on workers (default parallelism: the executors available; max 128) and logs each trial as an MLflow child run.
Try a question
A data scientist's Hyperopt objective function returns the validation accuracy of each model, and fmin keeps converging on the worst-performing hyperparameters. What is the fix?
- ASwitch
algofromtpe.suggesttorand.suggest - BIncrease
max_evalsso that TPE has more trials to learn from - CPass
direction='maximize'tofminso that it maximizes the returned value - DReturn the negative accuracy as the loss, because
fminminimizes
Show the answer
D. Hyperopt's fmin always minimizes the value returned by the objective. Metrics where higher is better, such as accuracy, AUC, F1 or R-squared, must be negated; error metrics such as RMSE or log loss can be returned as they are.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson Hyperparameter Tuning: Grid, Random and Bayesian Search with Hyperopt and Optuna teaches this objective (about 45 minutes), and 18 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.
More in this section
- Use ML foundations to select the appropriate algorithm for a given model scenario
- Identify methods to mitigate data imbalance in training data
- Compare estimators and transformers
- Develop a training pipeline
- Use Hyperopt's fmin operation to tune a model's hyperparameters
- Parallelize single node models for hyperparameter tuning
- Describe the benefits and downsides of using cross-validation over a train-validation split.
- Perform cross-validation as a part of model fitting.
- Identify the number of models being trained in conjunction with a grid-search and cross-validation process.
- Use common classification metrics: F1, Log Loss, ROC/AUC, etc
- Use common regression metrics: RMSE, MAE, R-squared, etc.
- Choose the most appropriate metric for a given scenario objective