Databricks Machine Learning Associate Question 454
Single answerYou are using the MLflow Client API to identify the best run from an experiment based on the highest accuracy metric. Which of the following code snippets correctly retrieves the best run?
- A
best_run = client.search_runs(experiment_ids=['1'], order_by=['metrics.accuracy DESC'], max_results=1)[0]
- B
best_run = client.get_run(client.search_runs(experiment_ids=['1'], order_by=['metrics.accuracy ASC'], max_results=1)[0].info.run_id)
- C
best_run = client.search_runs(experiment_ids=['1'], filter_string='metrics.accuracy > 0.9', order_by=['metrics.accuracy DESC'], max_results=1)
- D
best_run = client.get_experiment_by_name('experiment_name').get_best_run(order_by=['metrics.accuracy DESC'])
Show answer and explanation
Correct answer: A
Explanation
The MLflow Client API provides the search_runs method to query runs and sort them based on specific metrics. By ordering runs in descending order of the accuracy metric and limiting results to 1, you can identify the best run efficiently. The other options either misuse the API or misrepresent available methods.
- A. Correct.
This option is correct because it uses the
search_runsmethod of the MLflow Client API with the correct parameters to sort the runs by accuracy in descending order and retrieve the best run. - B. Incorrect.
This option is incorrect because it unnecessarily calls
get_runaftersearch_runs, and the ordering used (ASCfor ascending) would not return the best run based on the highest accuracy. - C. Incorrect.
This option is incorrect because while it uses a filter string to filter runs with accuracy greater than 0.9, it does not guarantee that the best run is returned without additional sorting logic.
- D. Incorrect.
This option is incorrect because the method
get_best_runis not available for experiments in the MLflow Client API. The correct approach is to usesearch_runs.