Databricks Machine Learning Professional Question 144
Single answerYou have trained a machine learning model for predicting customer churn and registered the model in the MLflow Model Registry under the name 'churn_model'. You now want to load the latest version of this model into your Databricks workspace for batch inference. Which of the following code snippets correctly loads the registered model?
- A
model = mlflow.pyfunc.load_model('models:/churn_model/latest')
- B
model = mlflow.pyfunc.load_model('models:/churn_model/production')
- C
model = mlflow.sklearn.load_model('models:/churn_model/latest')
- D
model = mlflow.models.load_model('models:/churn_model/1')
Show answer and explanation
Correct answer: A
Explanation
When working with MLflow's Model Registry, the 'mlflow.pyfunc.load_model' function is used to load registered models in a format-agnostic way. To load the latest version of a registered model, the correct syntax is 'models:/<model_name>/latest'. This ensures that the most recently registered version of the model is retrieved for use.
- A. Correct.
This is the correct way to load the latest version of a registered model using MLflow's pyfunc interface, which is designed for loading models in a format-agnostic way.
- B. Incorrect.
This is incorrect because 'production' is not a valid stage identifier for loading models. The correct syntax for loading a model from a specific stage is 'models:/<model_name>/
'. - C. Incorrect.
This is incorrect because while the sklearn module can load scikit-learn models, it is not used for loading models registered in the MLflow Model Registry.
- D. Incorrect.
This is incorrect because 'models:/<model_name>/
' refers to a specific version of a registered model, not the latest version. To load the latest version, you must use 'latest' instead of a numerical version.