Databricks Machine Learning Associate Question 456
Single answerYou are working on a machine learning project and have tracked multiple runs in an MLflow experiment. You want to programmatically identify the best run based on the lowest validation loss using the MLflow Client API. Which code snippet achieves this goal?
- A
Use
mlflow.search_runs()to retrieve all runs, sort them by themetrics.validation_losscolumn in ascending order, and select the first run. - B
Use
mlflow.get_run()to retrieve all runs and compare theirmetrics.validation_lossvalues to find the run with the lowest value. - C
Use
mlflow.client.MlflowClient().list_run_infos()to retrieve run metadata and manually search for the run with the lowestmetrics.validation_loss. - D
Use
mlflow.client.MlflowClient().search_runs()with an order_by parameter to sort runs bymetrics.validation_lossin ascending order and select the first run.
Show answer and explanation
Correct answer: D
Explanation
The MLflow Client API provides a search_runs() method with an order_by parameter, allowing you to efficiently query and sort runs based on specific metrics, such as validation_loss. This method enables you to identify the best run programmatically without additional manual steps. Other options either lack the required functionality or involve significant inefficiencies.
- A. Incorrect.
mlflow.search_runs()can retrieve all runs and sort them by a metric, but it is not part of the MLflow Client API and does not directly support programmatic sorting with theorder_byparameter. - B. Incorrect.
mlflow.get_run()retrieves a single run by its run ID. It cannot be used to compare all runs in an experiment. - C. Incorrect.
mlflow.client.MlflowClient().list_run_infos()retrieves only metadata about runs (such as run IDs and statuses) but does not include metrics likevalidation_lossfor comparisons. - D. Correct.
mlflow.client.MlflowClient().search_runs()with theorder_byparameter allows direct sorting bymetrics.validation_lossin ascending order, making it the most efficient and accurate way to programmatically identify the best run.