Model Deployment
Until now, we have focused on building accurate machine learning models. We cleaned data, engineered features, tuned hyperparameters, and organized everything using pipelines.
However, a trained model has no real value unless it can be used by real users or systems.
This lesson explains Model Deployment — the process of making a trained model available for predictions in real-world applications.
What Is Model Deployment?
Model deployment means taking a trained machine learning model and integrating it into a production environment.
Once deployed, the model can receive new data, process it using the same pipeline, and return predictions automatically.
In simple words: deployment turns a model into a usable service.
Why Deployment Matters
In practice, companies do not run models in notebooks.
They deploy models to:
• Approve loans automatically • Detect fraud in real time • Recommend products to users • Predict customer behavior
Without deployment, machine learning remains only an experiment.
Deployment Flow Using Our Dataset
We continue using the same dataset (Dataplexa ML Housing & Customer Dataset) to maintain consistency.
The deployment flow looks like this:
1. Train pipeline 2. Save trained model 3. Load model later 4. Accept new input data 5. Return predictions
Saving the Trained Model
The first step in deployment is saving the trained pipeline to disk.
We use joblib
because it is fast and reliable for large models.
import joblib
joblib.dump(pipeline, "loan_approval_model.pkl")
This file now contains:
• Feature scaling logic • Model parameters • Learned weights
Loading the Model for Predictions
Once deployed, the model is loaded whenever predictions are required.
model = joblib.load("loan_approval_model.pkl")
This step ensures that the exact same model is used across all environments.
Making Predictions on New Data
Now we simulate a real-world scenario.
A new customer applies for a loan. We collect their information and pass it to the model.
import pandas as pd
new_customer = pd.DataFrame([{
"age": 35,
"income": 62000,
"credit_score": 720,
"loan_amount": 18000,
"employment_years": 6
}])
prediction = model.predict(new_customer)
prediction
Output:
1 → Loan Approved
0 → Loan Rejected
Real-World Deployment Example
In a banking system, this model would run behind an API.
When a user submits a loan application:
• Data is validated • Pipeline processes the data • Model predicts approval • Decision is returned instantly
All of this happens in milliseconds.
Common Deployment Mistakes
Many ML projects fail after deployment due to simple mistakes.
Common issues include:
• Using different preprocessing steps • Changing feature order • Not saving pipelines correctly • Manual data transformations
Pipelines prevent most of these problems.
Mini Practice
Try changing the customer income and observe how the prediction changes.
This helps you understand how sensitive the model is to input features.
Exercises
Exercise 1:
Why should pipelines be saved instead of only models?
Exercise 2:
What happens if feature order changes during deployment?
Quick Quiz
Q1. Can a deployed model work without retraining?
In the next lesson, we learn how to track deployed models and detect performance issues using Model Monitoring.