Databricks Machine Learning Professional Question 27
Select 2You are using MLflow to manage your machine learning experiments. You want to programmatically access the best-performing model's artifacts (e.g., the model file) from the experiment with the name 'Sales_Prediction_Experiment' in order to deploy it. Which of the following steps should you take to correctly retrieve the model artifacts?
- A
Use the
mlflow.search_experiments()method to retrieve the experiment ID for 'Sales_Prediction_Experiment'. - B
Query the MLflow tracking server using
mlflow.search_runs()to filter the runs of the experiment and find the run with the highest metric value. - C
Use
mlflow.get_artifact_uri()with the run ID of the best-performing run to get the URI of the model artifacts. - D
Invoke
mlflow.load_model()directly with the experiment name to retrieve the best model from the experiment. - E
Use
mlflow.register_model()with the run ID to register the model and retrieve its artifacts.
Show answer and explanation
Correct answers: B, C
Explanation
To programmatically access a model's artifacts from an MLflow experiment, you need to first identify the experiment's runs and find the one with the highest performance metric (e.g., accuracy). This can be done using mlflow.search_runs(). Once the best run is identified, you can retrieve the artifacts' URI using mlflow.get_artifact_uri() with the run ID. This workflow ensures you are programmatically retrieving the correct model for deployment.
- A. Incorrect.
Incorrect. The
mlflow.search_experiments()method does not exist. Instead, you can usemlflow.get_experiment_by_name()or similar methods to get an experiment's details, including its ID. - B. Correct.
Correct. The
mlflow.search_runs()method allows you to query all runs for the specified experiment (using its ID) and filter them based on metrics to determine the best-performing run. - C. Correct.
Correct. Once you identify the best-performing run (using its run ID), you can use
mlflow.get_artifact_uri()to programmatically get the URI to the model artifacts stored for that run. - D. Incorrect.
Incorrect. The
mlflow.load_model()function does not take an experiment name as input. It requires the specific model URI or run path to load the model. - E. Incorrect.
Incorrect. While
mlflow.register_model()allows you to register a model to the MLflow Model Registry, it does not help in directly retrieving the artifacts for deployment.