Databricks Machine Learning Associate Question 100
Select 4You are training a machine learning model and want to manually log metrics, artifacts, and the model itself in an MLflow Run. Which of the following steps should you take to correctly achieve this?
- A
Use the
mlflow.start_run()context manager to initiate a run before logging metrics, artifacts, or models. - B
Log metrics like accuracy or loss using
mlflow.log_metric()after the training process. - C
Log the trained model using
mlflow.log_artifact(). - D
Log artifacts such as training plots or files using
mlflow.log_artifact(). - E
End the MLflow Run explicitly using
mlflow.end_run()if you are not using a context manager.
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 initiate a run using mlflow.start_run() or explicitly call mlflow.start_run() and mlflow.end_run() if not using a context manager. Metrics can be logged with mlflow.log_metric(), artifacts can be logged with mlflow.log_artifact(), and models should be logged with dedicated model logging functions like mlflow.log_model(). Properly managing the lifecycle of an MLflow Run ensures that all logs and artifacts are correctly recorded.
- A. Correct.
Correct: The
mlflow.start_run()context manager is required to initiate an MLflow Run. Without this, no metrics, artifacts, or models can be logged. - B. Correct.
Correct: Metrics like accuracy, loss, or other evaluation metrics should be logged using
mlflow.log_metric(). - C. Incorrect.
Incorrect: The
mlflow.log_artifact()function is used to log files or artifacts, not models. To log a model, you should usemlflow.log_model(). - D. Correct.
Correct: Artifacts such as training plots, configuration files, or other relevant files should be logged using
mlflow.log_artifact(). - E. Correct.
Correct: If you are not using the
mlflow.start_run()context manager, you must explicitly callmlflow.end_run()to terminate the MLflow Run.