Related Data Science Links
Learn Deployment Data Science Tutorial, validate concepts with Deployment Data Science MCQ Questions, and prepare interviews through Deployment Data Science Interview Questions and Answers.
Deployment
Production
Real-World
APIs
Model Deployment Basics
Learn how to move a trained model from your notebook into a simple web API that real applications can call.
Deployment Concepts
- Batch predictions: run model on large data periodically.
- Online predictions: real-time API for single requests.
- Monitoring: track latency, errors, data drift.
Simple Flask API Example
Serve a Scikit-Learn Model with Flask
# pip install flask joblib scikit-learn
from flask import Flask, request, jsonify
import joblib
import numpy as np
app = Flask(__name__)
# Load trained model (previously saved with joblib.dump)
model = joblib.load("model.pkl")
@app.route("/predict", methods=["POST"])
def predict():
data = request.get_json()
# Expecting JSON like: {"features": [5.1, 3.5, 1.4, 0.2]}
features = np.array(data["features"]).reshape(1, -1)
pred = model.predict(features)[0]
return jsonify({"prediction": int(pred)})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)