Databricks Machine Learning Associate exam dumps

Databricks Machine Learning Associate practice question 98 of 656

Databricks Certified Machine Learning Associate. Associate level, Databricks. Free question with the correct answer and a full explanation.

Databricks Machine Learning Associate Question 98

Single answer

You are working on a machine learning project in Databricks and have trained multiple models with different hyperparameters, logging each run to MLflow. You want to programmatically identify the best run based on the highest validation accuracy using the MLflow Client API. Which of the following code snippets correctly identifies the best run?

  1. A

    best_run = client.search_runs(experiment_ids=['1'], order_by=['metrics.validation_accuracy DESC'])[0]

  2. B

    best_run = max(client.search_runs(experiment_ids=['1']), key=lambda run: run.data.metrics['validation_accuracy'])

  3. C

    best_run = client.list_run_infos(experiment_id='1')[0]

  4. D

    best_run = client.get_run(run_id='best_val_accuracy')

Show answer and explanation

Correct answer: B

Explanation

To identify the best run using the MLflow Client API, you need to compare the desired metric ('validation_accuracy') across all runs. The search_runs method fetches all runs for a given experiment, and the max function with a lambda function on the metric ensures you identify the run with the highest 'validation_accuracy'. This is a common approach for programmatically selecting the best-performing model.

  • A. Incorrect.

    This code snippet sorts runs by 'validation_accuracy' in descending order using the 'order_by' parameter. However, sorting is only valid with 'search_runs', and the first result would indeed have the highest value. Despite this, the code assumes the experiment ID is '1' without variable context, and it doesn't handle cases where the metric might be missing.

  • B. Correct.

    This is the correct answer. It uses the max function with a lambda to extract the run with the highest 'validation_accuracy' from the list of runs returned by search_runs. This approach is robust and correctly handles the filtering logic.

  • C. Incorrect.

    This code retrieves only metadata about runs using list_run_infos, which does not include metric values like 'validation_accuracy'. Therefore, it cannot be used to identify the best run.

  • D. Incorrect.

    This code snippet assumes there is a run ID named 'best_val_accuracy', but such an ID would not exist unless explicitly created. Additionally, this does not programmatically identify the best run based on the metric.

Timed practice exam

Take a Databricks Machine Learning Associate practice test under exam conditions

48 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam