Databricks Certified Machine Learning Associate · Free Practice Question Medium
Question 14
A machine learning model has been trained and evaluated successfully using Databricks MLlib. The data scientist now needs to deploy the model for real-time predictions in a production environment.
What steps should they take?
-
A
Export the model as a serialized file and deploy it on a separate server.
-
B
Use MLflow to package the model and deploy it as a REST API endpoint.
-
C
Save the model to a Delta table and query it for predictions.
-
D
Schedule a Databricks Job to run the model periodically.
Reveal correct answer
Correct answer: B
Explanation
Correct Answer:
Use MLflow to package the model and deploy it as a REST API endpoint.
Explanation:
The most robust and scalable approach for deploying a Databricks MLlib model in production is to use MLflow to:
Package the Model:
Log the trained model using
mlflow.spark.log_model().MLflow automatically captures dependencies (e.g., PySpark, Python version).
Deploy as a REST API:
Use MLflow Model Serving or deploy to Azure ML/AWS SageMaker for real-time inference.
Example:
- import mlflow
- from pyspark.ml import PipelineModel
- # Log the model
- model = PipelineModel.load("path/to/model")
- mlflow.spark.log_model(model, "spark-model")
- # Deploy (e.g., via Databricks Model Serving UI)
This provides a scalable, low-latency endpoint for predictions.
Why Other Options Are Incorrect:
Export as a serialized file and deploy on a separate server:
Manual deployment is error-prone (dependency mismatches, scaling issues).
Lacks the monitoring and scalability of MLflow.
Save to a Delta table and query for predictions:
Delta tables are for data storage, not model serving.
Real-time predictions require low-latency APIs, not batch queries.
Schedule a Databricks Job for periodic runs:
Jobs are for batch processing, not real-time inference.
Key Benefits of MLflow Deployment:
✅ Dependency Management: Auto-captures Python/Spark versions.
✅ Scalability: Built-in load balancing (e.g., via Databricks Model Serving).
✅ Monitoring: Track latency, errors, and usage metrics.
Example Workflow:
Train → Log model with MLflow.
Deploy → Enable "Model Serving" in Databricks UI or export to cloud platforms.
Call API:
- import requests
- response = requests.post("https://<model-endpoint>/invocations", json=input_data)
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
