CertLumen

Databricks Machine Learning Associate · Section 3 · 31% of the exam

Parallelize single node models for hyperparameter tuning

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.choice results are indexes (use space_eval); hp.loguniform bounds are logs; hp.quniform returns 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?

  1. ASwitch algo from tpe.suggest to rand.suggest
  2. BIncrease max_evals so that TPE has more trials to learn from
  3. CPass direction='maximize' to fmin so that it maximizes the returned value
  4. DReturn the negative accuracy as the loss, because fmin minimizes
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

← Previous objective · All 48 objectives · Next objective →