</>
Skip to content
Data Science lessons (41/42)

Data Science — Deployment

Deployment options

  1. REST API: Flask/FastAPI
  2. Serverless: Lambda/Cloud Functions
  3. Containers: Docker/Kubernetes
  4. 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

  1. Use versioning
  2. Implement monitoring
  3. Add health checks
  4. Load testing

Mini Practice

  1. Deploy with Flask
  2. Create FastAPI endpoint
  3. Containerize with Docker
  4. 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.