Databricks Machine Learning Professional Question 145
Single answerYou are working on a Databricks project where a model has been registered in the Model Registry under the name 'customer_churn_model'. You want to load the latest version of this model in your notebook for batch inference using the MLflow load_model API. Which of the following code snippets correctly achieves this?
- A
model = mlflow.pyfunc.load_model('models:/customer_churn_model/latest')
- B
model = mlflow.sklearn.load_model('runs:/customer_churn_model/latest')
- C
model = mlflow.pyfunc.load_model('runs:/customer_churn_model/latest')
- D
model = mlflow.pyfunc.load_model('models:/customer_churn_model/1')
Show answer and explanation
Correct answer: A
Explanation
To load a registered model from the MLflow Model Registry, the correct URI format is 'models:/<model_name>/<version_or_stage>'. The stage 'latest' dynamically fetches the most recently registered version of the model. The mlflow.pyfunc.load_model API enables loading models in a generic way for inference, regardless of the specific library used during training.
- A. Correct.
Correct: This is the correct syntax to load the latest version of a registered model from the Model Registry using MLflow's
load_modelAPI. - B. Incorrect.
Incorrect: The 'runs:/' URI is used to fetch models directly from a specific MLflow run, not from the Model Registry. Additionally, this syntax is invalid for specifying a registered model.
- C. Incorrect.
Incorrect: Similar to the second option, 'runs:/' points to a specific run's artifact and not a registered model. The URI is incorrect for this scenario.
- D. Incorrect.
Incorrect: While this syntax correctly refers to a specific version of a registered model (version 1 in this case), it does not dynamically load the latest version as required by the question.