Databricks Machine Learning Associate Question 460
Select 4A data scientist is training a machine learning model in a Databricks notebook and wants to manually log metrics such as accuracy, save the model, and store a performance plot as an artifact using MLflow. Which of the following steps are required to accomplish this?
- A
Start an MLflow run using mlflow.start_run()
- B
Use mlflow.log_metric() to log accuracy
- C
Save the model to MLflow using mlflow.save_model()
- D
Log a performance plot as an artifact using mlflow.log_artifact()
- E
End the MLflow run using mlflow.end_run()
Show answer and explanation
Correct answers: A, B, D, E
Explanation
To manually log metrics, artifacts, and models in MLflow, it is important to start an MLflow run with mlflow.start_run(), log metrics using mlflow.log_metric(), and log artifacts using mlflow.log_artifact(). Once all desired information is logged, the MLflow run must be ended with mlflow.end_run(). However, logging models requires mlflow.log_model(), not mlflow.save_model().
- A. Correct.
Correct: An MLflow run must be started using mlflow.start_run() to log metrics and artifacts.
- B. Correct.
Correct: mlflow.log_metric() is used to log metrics such as accuracy to the MLflow run.
- C. Incorrect.
Incorrect: mlflow.save_model() is not a valid MLflow function for saving a model. Instead, mlflow.log_model() should be used to log models.
- D. Correct.
Correct: Artifacts like performance plots can be logged using mlflow.log_artifact().
- E. Correct.
Correct: The MLflow run must be ended using mlflow.end_run() to ensure all logs and artifacts are finalized.