0
0
ML Pythonml~20 mins

CI/CD for ML pipelines in ML Python - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - CI/CD for ML pipelines
Problem:You have an ML pipeline that trains a model and deploys it manually. This process is slow and error-prone.
Current Metrics:Training accuracy: 90%, Validation accuracy: 88%, Deployment time: 2 hours manually
Issue:Manual deployment causes delays and risks mistakes. No automation to test, build, and deploy the ML model.
Your Task
Automate the ML pipeline with CI/CD to reduce deployment time to under 10 minutes and ensure consistent model quality.
Use GitHub Actions for CI/CD automation
Keep the same model architecture and dataset
Include automated testing of model training and evaluation
Hint 1
Hint 2
Hint 3
Solution
ML Python
name: ML Pipeline CI/CD

on:
  push:
    branches: [ main ]

jobs:
  build-and-test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.12'

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install scikit-learn

    - name: Train and evaluate model
      run: |
        python train_and_evaluate.py

    - name: Check accuracy
      run: |
        ACC=$(python get_accuracy.py)
        echo "Model accuracy: $ACC"
        if (( $(echo "$ACC < 0.85" | bc -l) )); then
          echo "Accuracy too low, failing build."
          exit 1
        fi

    - name: Deploy model
      run: |
        echo "Deploying model..."
        # Simulate deployment step
        sleep 5
        echo "Model deployed successfully."
Added GitHub Actions workflow to automate training, testing, and deployment
Included accuracy check to fail pipeline if model quality is low
Reduced manual deployment time by automating with scripts
Results Interpretation

Before: Manual deployment took 2 hours and risked errors.
After: Automated CI/CD pipeline runs training, tests accuracy, and deploys model in under 10 minutes.

Automating ML pipelines with CI/CD improves speed, consistency, and reliability of model deployment.
Bonus Experiment
Add automated data validation and model performance monitoring to the CI/CD pipeline.
💡 Hint
Use scripts to check input data quality and track model metrics over time, triggering alerts if performance drops.