Databricks Machine Learning Associate Question 458
Select 4You are training a machine learning model in Databricks and want to manually log the model's accuracy, a sample confusion matrix image, and the trained model itself using MLflow. Which of the following are correct steps to achieve this within an MLflow run?
- A
Use
mlflow.log_metric()to log the model's accuracy. - B
Use
mlflow.log_artifact()to log the confusion matrix image as an artifact. - C
Use
mlflow.log_param()to log the trained model. - D
Use
mlflow.sklearn.log_model()to log the trained model. - E
Ensure the MLflow run is started with
mlflow.start_run()before logging any metrics, artifacts, or models.
Show answer and explanation
Correct answers: A, B, D, E
Explanation
To manually log metrics, artifacts, and models in an MLflow run, you must first start a run using mlflow.start_run(). Metrics such as accuracy can be logged using mlflow.log_metric(). Files, such as a confusion matrix image, can be logged as artifacts using mlflow.log_artifact(). The trained model should be logged using a framework-specific method like mlflow.sklearn.log_model() for scikit-learn models. The mlflow.log_param() function is not suitable for logging models but is used for logging input parameters.
- A. Correct.
Correct:
mlflow.log_metric()is the appropriate method for logging scalar metrics like accuracy. - B. Correct.
Correct:
mlflow.log_artifact()is used to log files such as images, which includes the confusion matrix image in this case. - C. Incorrect.
Incorrect:
mlflow.log_param()is used to log parameters (e.g., hyperparameters) and cannot be used to log models. - D. Correct.
Correct:
mlflow.sklearn.log_model()is the correct method to log a trained model when using scikit-learn. - E. Correct.
Correct: MLflow requires the use of
mlflow.start_run()to begin a run before any logging can occur.