Databricks Machine Learning Professional Question 147
Single answerYou are working on a machine learning project in Databricks and have registered a trained model named 'churn_model' in the Model Registry. You now want to load this registered model for batch inference in Python. Which of the following code snippets correctly loads the registered model?
- A
from mlflow import load_model; model = load_model('models:/churn_model/latest')
- B
from mlflow import load_model; model = load_model('models:/churn_model/1')
- C
from mlflow.pyfunc import load_model; model = load_model('models:/churn_model/latest')
- D
from mlflow.pyfunc import load_model; model = load_model('models:/churn_model/1')
Show answer and explanation
Correct answer: C
Explanation
In Databricks, to load a registered model for inference, you use the 'mlflow.pyfunc.load_model' function along with the Model Registry URI ('models:/<model_name>/<version_or_stage>'). Using 'latest' as the stage in the URI ensures the latest version of the model is loaded. The other answers either use incorrect modules or fail to refer to the latest version of the model.
- A. Incorrect.
Incorrect: The 'mlflow' package itself does not have a 'load_model' function. You must use the 'mlflow.pyfunc' module to load registered models.
- B. Incorrect.
Incorrect: The 'mlflow' package itself does not have a 'load_model' function. You must use the 'mlflow.pyfunc' module to load registered models.
- C. Correct.
Correct: The 'mlflow.pyfunc.load_model' function is the correct method to load registered models. The 'models:/churn_model/latest' URI specifies that the latest version of the registered model should be loaded.
- D. Incorrect.
Incorrect: While 'mlflow.pyfunc.load_model' is correct, specifying the model version as '1' directly (e.g., 'models:/churn_model/1') would load a specific version instead of the latest version. However, the question asks for batch inference using the latest version.