Machine Learning Model Deployment
Training a machine learning model is only one part of building a practical data science solution. The model must also process new observations reliably and remain useful as data and operating conditions change.
For example, an e-commerce churn model may need to generate predictions every morning, while a fraud detection model may need to process transaction information with low latency.
Machine learning deployment is the process of integrating a trained model into a system where it can generate predictions on new data. Model monitoring evaluates its predictive and operational behaviour after deployment.
What Is Model Deployment?
Deployment makes a trained model available for use outside its original training environment.
Common deployment approaches include:
| Deployment Type | Description | Example |
|---|---|---|
| Batch Inference | Generates predictions for groups of records | Daily churn scoring |
| Real-Time Inference | Generates predictions when requests arrive | Fraud risk scoring |
| Streaming Inference | Processes continuous event flows | Sensor monitoring |
| Edge Deployment | Runs models near the data source | On-device image recognition |
The deployment method depends on prediction frequency, infrastructure requirements, and acceptable latency.
What Is the Difference Between Training and Inference?
Training adjusts model parameters using historical data.
Inference uses those learned parameters to generate predictions for new inputs.
During normal inference, a model does not automatically update its learned weights.
Model updates require a separate training or online-learning procedure.
How Do You Save a Machine Learning Model?
Scikit-learn pipelines can be saved using joblib.
import joblibjoblib.dump( model, "churn_model.joblib")The file contains the fitted pipeline, including preprocessing steps.
It can be loaded later.
loaded_model = joblib.load( "churn_model.joblib")Only load model files from trusted sources. Python model serialisation formats such as pickle and joblib can execute code during loading.
Model files should also be versioned and stored with information about the training environment.
How Do You Generate Predictions From a Saved Model?
new_customer = pd.DataFrame({ "feature_1": [0.5], "feature_2": [-1.2], "feature_3": [0.8], "feature_4": [1.1]})prediction = loaded_model.predict(new_customer)probability = loaded_model.predict_proba( new_customer)[:, 1]print("Prediction:", prediction[0])print("Probability:", probability[0])The supplied feature names must match those used during training.
The new observation must also follow the expected data types and input schema.
What Is a Machine Learning API?
An Application Programming Interface (API) allows applications to request predictions from a deployed model.
A typical inference request follows this sequence:
Client Request → Input Validation → Preprocessing → Model Prediction → API Response
For example, a customer management application may send customer features to an API and receive a churn probability.
Basic Model API Using FastAPI
from fastapi import FastAPIfrom pydantic import BaseModelimport pandas as pdimport joblibapp = FastAPI()model = joblib.load("churn_model.joblib")class CustomerInput(BaseModel): feature_1: float feature_2: float feature_3: float feature_4: [email protected]("/predict")def predict(customer: CustomerInput): data = pd.DataFrame( [customer.model_dump()] ) probability = model.predict_proba(data)[0, 1] return { "churn_probability": float(probability) }The /predict endpoint accepts numerical inputs and returns a probability.
This is an instructional example. A production service also requires appropriate authentication, access controls, dependency management, logging, and operational safeguards.
What Is Model Monitoring?
Model monitoring checks whether a deployed model continues to operate reliably.
Common monitoring categories include:
Data Drift
Data drift occurs when the distribution of input features changes.
For example, a retail model may be trained using spending patterns from one year, but subsequent customer behaviour may change.
Concept Drift
Concept drift occurs when the relationship between input features and the target changes.
For example, payment-failure history may become less predictive of customer churn after a company introduces a new billing system.
Prediction Drift
Prediction drift refers to changes in the distribution of model outputs.
A model may suddenly assign higher churn probabilities to a larger proportion of customers.
This requires investigation but does not automatically indicate model failure.
Performance Monitoring
Performance monitoring measures predictive quality using actual outcomes when they become available.
For classification, metrics may include precision, recall, F1-score, and ROC-AUC.
For regression, metrics may include MAE and RMSE.
What Operational Metrics Should Be Monitored?
| Metric | Purpose |
|---|---|
| Prediction Latency | Measures response time |
| Error Rate | Tracks unsuccessful requests |
| Throughput | Measures processed requests |
| Feature Missingness | Detects incomplete inputs |
| Input Drift | Identifies distribution changes |
| Prediction Distribution | Detects unusual output patterns |
| Model Accuracy or Error | Measures predictive quality when labels arrive |
A deployed model may require retraining, recalibration, or replacement when its performance becomes unacceptable.
What Is MLOps?
MLOps stands for Machine Learning Operations.
It applies software engineering and operational practices to machine learning development.
Common MLOps activities include model versioning, automated testing, reproducible training, deployment pipelines, and monitoring.
MLOps helps organisations manage the complete lifecycle of machine learning systems.
Common Model Deployment Mistakes
- Deploying a model without its preprocessing pipeline.
- Ignoring incoming data schema changes.
- Loading untrusted model files.
- Monitoring system uptime but not predictive performance.
- Retraining automatically without validating the updated model.
- Failing to maintain model and dataset versions.
Data Science Tutorial for Beginners
Vaishali Ardhana








