Databricks-ML-Pro Model Development Practice Question
A machine learning engineer is using Hyperopt with SparkTrials to tune a scikit-learn model on a Databricks cluster. They set max_evals=100 and parallelism=4. After the run, they notice that some trials report a loss of NaN and that the best model selected by Hyperopt has poor performance. What is the most likely reason for the NaN losses?
⚠ Common exam trap
The trap here is assuming that Hyperopt automatically discards trials with NaN losses, when in fact NaN can silently break the optimization logic.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The objective function returns a NaN when the model fails to converge, and Hyperopt treats NaN as a valid loss, potentially selecting a failed trial as best.
Hyperopt's fmin function minimizes the loss returned by the objective. If the objective returns NaN, Hyperopt may not handle it gracefully; NaN comparisons are always false, so the best loss may not update correctly, and a failed trial could be inadvertently selected. The correct approach is to ensure the objective returns a finite value, such as a large number, when the model fails to train. This prevents NaN from polluting the search.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
SparkTrials distributes trials across workers, and the NaN is caused by a serialization error when returning the loss from the worker to the driver.
Why it's wrong here
Serialization errors would raise exceptions and cause the trial to fail, not produce a NaN loss. SparkTrials uses Spark to parallelize trials, but the loss value is a simple float that serializes fine. If there were a serialization issue, the entire trial would be marked as failed and Hyperopt would not include it in the results. NaN losses typically originate from the objective function itself, not from the distribution mechanism.
- ✗
The parallelism parameter is set too high, causing race conditions in the shared search space that corrupt the loss values.
Why it's wrong here
Hyperopt's SparkTrials handles parallelism safely by using a centralized search algorithm (TPE or random) on the driver and distributing trials to workers. There are no race conditions that would corrupt loss values; each trial is independent. Setting parallelism too high might slow down the search or cause resource contention, but it would not produce NaN losses. The NaN issue is almost always due to the objective function's return value.
- ✓
The objective function returns a NaN when the model fails to converge, and Hyperopt treats NaN as a valid loss, potentially selecting a failed trial as best.
Why this is correct
Hyperopt does not automatically filter out NaN losses; it compares them numerically, and NaN comparisons can lead to unpredictable selection. If the objective function returns NaN due to convergence failure or invalid parameters, those trials can be incorrectly considered as having a low loss (since NaN comparisons are false, it may not update the best, but in some cases it can cause issues). The best practice is to return a large finite value or use a try-except to handle failures. This directly explains the poor best model.
- ✗
The model's hyperparameters include a regularization parameter that, when set too high, causes the coefficients to become NaN, and Hyperopt does not handle this.
Why it's wrong here
While extreme regularization can cause numerical issues, scikit-learn typically raises a warning or error rather than producing NaN coefficients. Moreover, Hyperopt would still receive a finite loss if the model trains successfully. The scenario describes NaN losses, which are more commonly caused by the objective function returning NaN, for example due to a division by zero in a custom metric or an invalid parameter combination that causes the model to fail silently.
About these practice questions
This Databricks-ML-Pro question is part of Courseiva's 300-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Databricks exam blueprint
This Databricks-ML-Pro practice question is part of Courseiva's free Databricks certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the Databricks-ML-Pro exam.