Databricks Machine Learning Associate Question 102
Select 4You are training a machine learning model using Databricks and want to use MLflow to manually track your experiment's performance. Which of the following steps should you take to log metrics, artifacts, and the trained model within an MLflow run?
- A
Use
mlflow.start_run()to initiate a run and log metrics usingmlflow.log_metric(). - B
Use
mlflow.log_param()to log hyperparameters used in the training process. - C
Save the trained model locally and manually upload it to the MLflow tracking server.
- D
Log artifacts such as confusion matrices or feature importance plots using
mlflow.log_artifacts(). - E
Log the model using
mlflow.log_model()to save it with the run for reproducibility.
Show answer and explanation
Correct answers: A, B, D, E
Explanation
To manually log metrics, parameters, artifacts, and models in MLflow, you must first start a run using mlflow.start_run(). Metrics are logged using mlflow.log_metric(), parameters with mlflow.log_param(), and artifacts with mlflow.log_artifacts(). The model should be logged using mlflow.log_model() to ensure it is associated with the run and available for later use. Saving the model locally without logging it with MLflow does not meet the requirement for manual tracking in MLflow.
- A. Correct.
Correct:
mlflow.start_run()initializes an MLflow run, andmlflow.log_metric()is used to log metrics such as accuracy or loss. - B. Correct.
Correct:
mlflow.log_param()is used to record hyperparameters, such as learning rates or batch sizes, which are crucial for experiment tracking. - C. Incorrect.
Incorrect: While you can save the model locally, it must be logged into MLflow using
mlflow.log_model()to properly associate it with the run. - D. Correct.
Correct:
mlflow.log_artifacts()is used to log artifacts like plots or datasets, which are valuable for model evaluation and debugging. - E. Correct.
Correct:
mlflow.log_model()allows you to log and save the trained model with the MLflow run, enabling versioning and deployment capabilities.