
Answer-first summary for fast verification
Answer: mlflow.start_run()mlflow.spark.log_model(trained_model, “model“)mlflow.end_run()
The correct code snippet for saving the trained model to the Databricks MLflow tracking server is option D. Here's why: 1. `mlflow.start_run()`: Initiates a new run in the MLflow tracking server, allowing the model to be associated with a specific experiment for lineage tracking. 2. `mlflow.spark.log_model(trained_model, “model“)`: Logs the trained Spark MLlib model as an artifact named “model“ within the current run, making it easily accessible and identifiable later. 3. `mlflow.end_run()`: Marks the end of the run, capturing all logged metrics, parameters, and artifacts for future reference. Other options have issues: - **A**: Logs the model but doesn't associate it with a specific run, complicating tracking. - **B**: Saves the model locally within the Databricks workspace, not logging it to the MLflow tracking server. - **C**: Contains a typo (`logModel` instead of `log_model`) and won't execute. Option D ensures the model is properly logged to the MLflow tracking server within a specific run, facilitating future access and analysis. Remember to replace placeholders with actual model objects and desired artifact names.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
A data scientist is training a machine learning model using Spark MLlib in a Databricks notebook. They aim to save the trained model to the Databricks MLflow tracking server for future use. Which of the following code snippets should they use?
A
mlflow.log_model(trained_model, “model“)
B
mlflow.spark.save_model(trained_model, “model“)
C
mlflow.spark.logModel(trained_model, “model“)
D
mlflow.start_run()mlflow.spark.log_model(trained_model, “model“)mlflow.end_run()
No comments yet.