Data Science — Deployment
Deployment options
- REST API: Flask/FastAPI
- Serverless: Lambda/Cloud Functions
- Containers: Docker/Kubernetes
- ML platforms: SageMaker/AI Platform
Flask deployment
from flask import Flask, request, jsonify
import pickle
import numpy as np
app = Flask(__name__)
model = pickle.load(open("model.pkl", "rb"))
@app.route("/predict", methods=["POST"])
def predict():
data = request.get_json()
features = np.array(data["features"]).reshape(1, -1)
prediction = model.predict(features)[0]
return jsonify({"prediction": prediction.tolist()})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
FastAPI deployment
from fastapi import FastAPI
from pydantic import BaseModel
import pickle
app = FastAPI()
model = pickle.load(open("model.pkl", "rb"))
class PredictionRequest(BaseModel):
features: list
@app.post("/predict")
def predict(request: PredictionRequest):
prediction = model.predict([request.features])
return {"prediction": prediction.tolist()}
Docker
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
Best practices
- Use versioning
- Implement monitoring
- Add health checks
- Load testing
Mini Practice
- Deploy with Flask
- Create FastAPI endpoint
- Containerize with Docker
- Test deployment
Up Next
Continue with AutoML - Automated machine learning.
Related Topics
Frequently Asked Questions about Deployment
What is Deployment in Data Science?
Deployment is a fundamental concept in Data Science. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Deployment?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Deployment.
Why is Deployment important in Data Science?
Deployment is essential for Data Science development. Understanding this concept will help you write better code and solve real-world problems more effectively.