Skip to main content

Command Palette

Search for a command to run...

πŸ› οΈ MLflow Hands-On Projects: From Experiment Tracking to Cloud Deployment

Published
β€’3 min read
πŸ› οΈ MLflow Hands-On Projects: From Experiment Tracking to Cloud Deployment
B

I am Bittu Sharma, a DevOps & AI Engineer with a keen interest in building intelligent, automated systems. My goal is to bridge the gap between software engineering and data science, ensuring scalable deployments and efficient model operations in production.! π—Ÿπ—²π˜'π˜€ π—–π—Όπ—»π—»π—²π—°π˜ I would love the opportunity to connect and contribute. Feel free to DM me on LinkedIn itself or reach out to me at bittush9534@gmail.com. I look forward to connecting and networking with people in this exciting Tech World.

Learning MLflow theory is great, but the real magic happens when you apply it in projects. Hands-on work helps you understand how MLflow fits into the end-to-end MLOps pipeline β€” from experiment tracking to deployment in production.

In this guide, we’ll walk through 4 practical projects that will solidify your MLflow skills:

  1. Experiment Tracking β†’ Compare multiple ML models in MLflow UI.

  2. Model Registry + Serving β†’ Register best model, deploy as API with Docker.

  3. CI/CD Pipeline β†’ Automate ML lifecycle with MLflow + GitHub Actions + Kubernetes.

  4. Cloud Deployment β†’ Deploy model on AWS SageMaker or GCP Vertex AI.


πŸ”Ή Project 1: Experiment Tracking

πŸ“Œ Goal: Train multiple ML models (RandomForest, XGBoost, Neural Net) and compare results in the MLflow Tracking UI.

Steps:

  1. Install dependencies:
pip install mlflow scikit-learn xgboost tensorflow
  1. Train & log models:
import mlflow
import mlflow.sklearn
import mlflow.xgboost
import mlflow.tensorflow

from sklearn.ensemble import RandomForestClassifier
from xgboost import XGBClassifier
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

# Start MLflow experiment
mlflow.set_experiment("model_comparison")

def train_random_forest(X_train, y_train, X_test, y_test):
    with mlflow.start_run(run_name="RandomForest"):
        model = RandomForestClassifier(n_estimators=100)
        model.fit(X_train, y_train)
        acc = model.score(X_test, y_test)
        mlflow.log_param("n_estimators", 100)
        mlflow.log_metric("accuracy", acc)
        mlflow.sklearn.log_model(model, "model")

def train_xgboost(X_train, y_train, X_test, y_test):
    with mlflow.start_run(run_name="XGBoost"):
        model = XGBClassifier(n_estimators=100, max_depth=5)
        model.fit(X_train, y_train)
        acc = model.score(X_test, y_test)
        mlflow.log_params({"n_estimators": 100, "max_depth": 5})
        mlflow.log_metric("accuracy", acc)
        mlflow.xgboost.log_model(model, "model")
  1. Compare runs in the MLflow UI:
mlflow ui

πŸ“Š You’ll see side-by-side metrics & artifacts to pick the best model.


πŸ”Ή Project 2: Model Registry + Serving with Docker

πŸ“Œ Goal: Register your best model in MLflow Model Registry and deploy it as a REST API using Docker.

Steps:

  1. Register best model in Registry:
result = mlflow.register_model(
    "runs:/<RUN_ID>/model", "fraud_detection_model"
)
  1. Serve model locally:
mlflow models serve -m "models:/fraud_detection_model/1" -p 5000
  1. Build Docker image:
mlflow models build-docker -m "models:/fraud_detection_model/1" -n fraud-model-api
docker run -p 5000:8080 fraud-model-api
  1. Test API endpoint:
curl -X POST http://127.0.0.1:5000/invocations \
    -H "Content-Type: application/json" \
    -d '{"columns":["feature1","feature2"],"data":[[1.2,3.4]]}'

βœ… You now have a production-ready API served with MLflow + Docker.


πŸ”Ή Project 3: CI/CD Pipeline with GitHub Actions + Kubernetes

πŸ“Œ Goal: Automate model training, registry, and deployment using MLflow, GitHub Actions, and Kubernetes.

Workflow:

  1. GitHub Actions YAML (.github/workflows/mlops.yml):
name: MLflow CI/CD

on:
  push:
    branches: [ main ]

jobs:
  train-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Train & Log Model
        run: python train.py
      - name: Deploy to Kubernetes
        run: kubectl apply -f k8s/deployment.yaml
  1. Kubernetes Deployment YAML (k8s/deployment.yaml):
apiVersion: apps/v1
kind: Deployment
metadata:
  name: fraud-model
spec:
  replicas: 2
  selector:
    matchLabels:
      app: fraud-model
  template:
    metadata:
      labels:
        app: fraud-model
    spec:
      containers:
        - name: fraud-model
          image: fraud-model-api:latest
          ports:
            - containerPort: 8080

βœ… Every time you push code β†’ GitHub Actions retrains model β†’ Deploys new version on Kubernetes.


πŸ”Ή Project 4: Cloud Deployment (AWS SageMaker / GCP Vertex AI)

a) AWS SageMaker Deployment

import mlflow.sagemaker as mfs

mfs.deploy(
    app_name="fraud-detector",
    model_uri="models:/fraud_detection_model/Production",
    region_name="us-east-1",
    mode="create"
)
  • Creates a SageMaker Endpoint.

  • Supports scaling & IAM-based access.


b) GCP Vertex AI Deployment

import mlflow.models

mlflow.models.deploy(
    name="fraud-detector-gcp",
    model_uri="models:/fraud_detection_model/Production",
    platform="gcp-vertex-ai",
    region="us-central1"
)
  • Deploys to a managed Vertex AI endpoint.

  • Supports autoscaling and A/B testing.

βœ… Both clouds provide enterprise-ready, scalable model serving.


πŸ”Ή Summary

With these hands-on projects, you’ve taken MLflow from concept β†’ production-ready workflows:

  1. Experiment Tracking β†’ Compare models in MLflow UI.

  2. Model Registry + Serving β†’ Deploy as REST API with Docker.

  3. CI/CD Pipeline β†’ Automate ML lifecycle with GitHub Actions + Kubernetes.

  4. Cloud Deployment β†’ Push to AWS SageMaker or GCP Vertex AI.

πŸš€ These projects will make your MLflow journey resume-ready and prove your end-to-end MLOps capability.

Follow me on LinkedIn

Follow me on GitHub