Databricks Machine Learning Professional Question 21
Select 3You are building a machine learning model to predict house prices using Databricks, and you wish to track the training process using MLflow. You decide to manually log the model's parameters, metrics, and the trained model itself to the MLflow tracking server. Which of the following steps should you perform to ensure proper logging?
- A
Use
mlflow.start_run()to begin an MLflow run before logging any parameters, metrics, or models. - B
Log the hyperparameters (e.g., learning rate, number of layers) using
mlflow.log_param(). - C
Log the evaluation metrics (e.g., RMSE, R2 score) using
mlflow.log_metric(). - D
Save the trained model to a local file system and skip logging it to MLflow.
- E
Use
mlflow.log_artifact()to log the trained model file to the MLflow tracking server.
Show answer and explanation
Correct answers: A, B, C
Explanation
To manually log parameters, metrics, and models in MLflow, it is essential to first start an MLflow run using mlflow.start_run(). Then, parameters and metrics can be logged using mlflow.log_param() and mlflow.log_metric(), respectively. The trained model should be logged using mlflow.log_model() rather than saving it locally or treating it as an unrelated artifact. This ensures that all relevant information about the experiment is tracked and reproducible.
- A. Correct.
Correct: MLflow requires an active run to log information. Without starting a run using
mlflow.start_run(), logging parameters, metrics, or models will fail. - B. Correct.
Correct: MLflow provides
mlflow.log_param()to log model hyperparameters, ensuring they are tracked in the MLflow run. - C. Correct.
Correct: Metrics such as RMSE or accuracy should be logged using
mlflow.log_metric()to track the model's performance during training. - D. Incorrect.
Incorrect: While saving models locally can be useful, MLflow provides specific methods to log models directly for better reproducibility and tracking. Skipping this step would not utilize MLflow's full capabilities.
- E. Incorrect.
Incorrect: The trained model should be logged using
mlflow.log_model()rather thanmlflow.log_artifact(), which is designed for unrelated files or supplementary artifacts.