Databricks Machine Learning Associate Question 120
Single answerYou are working on a machine learning project in Databricks and have successfully trained a model. You now want to register this model in the MLflow Model Registry using the MLflow Client API. Which of the following code snippets correctly registers the model?
- A
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'runs:/12345abcde/my_model' client.create_registered_model('my_model', model_uri)
- B
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'runs:/12345abcde/my_model' client.create_model_version('my_model', model_uri, 'my_experiment')
- C
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'runs:/12345abcde/my_model' client.create_model_version(name='my_model', source=model_uri, run_id='12345abcde')
- D
from mlflow.tracking import MlflowClient client = MlflowClient() model_uri = 'runs:/12345abcde/my_model' client.register_model('my_model', model_uri)
Show answer and explanation
Correct answer: C
Explanation
To register a model using the MLflow Client API, you must use the create_model_version method. This method requires the model name (name), the model URI (source), and the run ID (run_id) associated with the model. Other methods like create_registered_model or register_model do not exist in the MLflow Client API and will result in errors.
- A. Incorrect.
Incorrect: The
create_registered_modelmethod does not exist in the MLflow Client API. You cannot use this to register a model. - B. Incorrect.
Incorrect: The
create_model_versionmethod requires therun_idparameter, and 'my_experiment' is not a valid input for that parameter. - C. Correct.
Correct: This is the correct way to register a model using the
create_model_versionmethod. Thenameparameter specifies the model name,sourcespecifies the model URI, andrun_idspecifies the ID of the run associated with the model. - D. Incorrect.
Incorrect: The
register_modelmethod does not exist in the MLflow Client API. You cannot use this to register a model.