Databricks Machine Learning Associate Question 123
Single answerYou have trained a machine learning model in Databricks and logged its artifacts using MLflow. Now, you want to register this model to the MLflow Model Registry programmatically using the MLflow Client API. Which of the following code snippets correctly demonstrates how to register the model?
- A
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'runs:/
/model' client.create_registered_model(name='my_model', source=model_uri) - B
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'runs:/
/model' client.register_model(model_uri, 'my_model') - C
from mlflow import mlflow_client client = mlflow_client() model_uri = 'runs:/
/model' client.create_registered_model(model_uri, 'my_model') - D
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'models:/
/ ' client.register_model(model_uri, 'my_model')
Show answer and explanation
Correct answer: B
Explanation
The correct way to programmatically register a model using the MLflow Client API is by using the register_model method of the MlflowClient class. This method takes the model artifact URI (e.g., 'runs:/
- A. Incorrect.
This code is incorrect because the
create_registered_modelfunction is used to create a new registered model name, but it does not register a specific model version or artifact. - B. Correct.
This is the correct code snippet. The
register_modelfunction ofMlflowClientis used to register a model artifact (specified by its URI) under a given model name in the MLflow Model Registry. - C. Incorrect.
This code is incorrect because the
mlflow_client()function does not exist. The correct function to use isMlflowClient()from themlflow.trackingmodule. - D. Incorrect.
This code is incorrect because the
register_modelfunction expects a model artifact URI (e.g., 'runs://model') and a model name, not a URI from the Model Registry (e.g., 'models:/ / ').