Databricks Machine Learning Associate Question 455
Single answerYou are working on a machine learning project and have logged multiple runs in MLflow. Each run includes metrics for accuracy, precision, and recall. You want to programmatically identify the best run based on the highest accuracy using the MLflow Client API. Which of the following code snippets correctly identifies the best run?
- A
best_run = max(client.search_runs(experiment_ids=['1']), key=lambda run: run.data.metrics['accuracy'])
- B
best_run = max(client.list_run_infos(experiment_ids=['1']), key=lambda run: run.data.metrics['accuracy'])
- C
best_run = min(client.search_runs(experiment_ids=['1']), key=lambda run: run.data.metrics['accuracy'])
- D
best_run = client.get_run(run_id='1')
Show answer and explanation
Correct answer: A
Explanation
To identify the best run programmatically using the MLflow Client API, the search_runs method is used to retrieve all runs for a given experiment. The max function is then applied with a key function that extracts the accuracy metric from each run, allowing you to find the run with the highest accuracy.
- A. Correct.
This is correct. The
search_runsmethod fetches all runs from the specified experiment, and themaxfunction is used to find the run with the highest accuracy metric. - B. Incorrect.
This is incorrect because
list_run_infosonly retrieves metadata about runs and does not include metric data, so you cannot accessrun.data.metrics. - C. Incorrect.
This is incorrect because
minwould return the run with the lowest accuracy, which does not satisfy the requirement to find the best run based on the highest accuracy. - D. Incorrect.
This is incorrect because
get_runretrieves a specific run by ID and does not help in programmatically identifying the best run among multiple runs.