Databricks Machine Learning Associate Question 459
Select 4You are training a machine learning model in Databricks and need to manually log the model’s performance metrics and the trained model itself using MLflow. Which of the following steps should you include to ensure proper logging within an MLflow run?
- A
Use
mlflow.start_run()to start an MLflow run before logging any metrics or artifacts. - B
Log metrics like accuracy or loss using the
mlflow.log_metric()function. - C
Use
mlflow.log_artifact()to log your trained model directly as an artifact. - D
Save the trained model locally and use
mlflow.log_model()to log it as a model artifact. - E
End the MLflow run with
mlflow.end_run()only after all logging operations are complete.
Show answer and explanation
Correct answers: A, B, D, E
Explanation
To manually log metrics, artifacts, and models in MLflow, you need to start an MLflow run with mlflow.start_run(), log metrics using mlflow.log_metric(), log the trained model using mlflow.log_model() (after saving it locally), and then end the run with mlflow.end_run(). While mlflow.log_artifact() is used to log files, it is not intended for logging trained models directly.
- A. Correct.
Correct: Starting an MLflow run using
mlflow.start_run()is required before logging any metrics, artifacts, or models. - B. Correct.
Correct: Metrics such as accuracy or loss are logged using the
mlflow.log_metric()function within an active MLflow run. - C. Incorrect.
Incorrect: The
mlflow.log_artifact()function is used to log files like datasets or configuration files, not trained models. - D. Correct.
Correct: To log a trained model as an artifact, save it locally and then use the
mlflow.log_model()function. - E. Correct.
Correct: Ending the MLflow run with
mlflow.end_run()ensures that all logging operations are finalized and the run is properly recorded.