Databricks Machine Learning Associate Question 457
Select 3You are training a machine learning model in Databricks and want to manually log the model's accuracy, confusion matrix image, and the trained model itself using MLflow. Which of the following steps should you take within an active MLflow run?
- A
Use
mlflow.log_metric()to log the model's accuracy as a numeric value. - B
Use
mlflow.log_artifact()to log the confusion matrix image file. - C
Use
mlflow.log_model()to log the trained model to the MLflow tracking server. - D
Use
mlflow.start_run()within themlflow.log_metric()function to start a new run. - E
Use
mlflow.get_artifact()to retrieve the confusion matrix image file for logging.
Show answer and explanation
Correct answers: A, B, C
Explanation
To manually log metrics, artifacts, and models in an MLflow run, you need to use the appropriate MLflow functions: mlflow.log_metric() for numeric metrics, mlflow.log_artifact() for files, and mlflow.log_model() for saving and logging models. Ensure that an MLflow run is active by using mlflow.start_run() beforehand. Incorrect usage of functions or non-existent functions, like mlflow.get_artifact(), will cause errors.
- A. Correct.
mlflow.log_metric()is the correct function to log scalar values like accuracy. It allows you to track numeric performance metrics for the model. - B. Correct.
mlflow.log_artifact()is the correct function to log files like the confusion matrix image or any other local artifacts to the MLflow tracking server. - C. Correct.
mlflow.log_model()is the correct function to save and log the trained model, making it available for further use or deployment through MLflow. - D. Incorrect.
mlflow.start_run()is used to start an MLflow run, but it cannot be used directly withinmlflow.log_metric()or any logging function. The run must already be active for logging to work. - E. Incorrect.
mlflow.get_artifact()does not exist in MLflow. To retrieve artifacts, you would use functions likemlflow.artifacts.download_artifacts(), but this is unrelated to logging artifacts.