Skip to content

Repository files navigation

🚀 GigShield ML Service

A production-ready Machine Learning microservice for dynamic insurance pricing and fraud detection in gig economy platforms.


📌 Overview

GigShield ML Service powers intelligent decision-making for:

  • 💰 Dynamic Premium Pricing (fair, risk-based insurance)
  • 🚨 Fraud Detection (real-time anomaly detection)

Built using FastAPI, this service exposes scalable APIs that integrate seamlessly with backend systems and frontend dashboards.


🧠 Models Used

🔹 1. Premium Prediction (Regression)

  • Model: XGBoost Regressor
  • Objective: Predict weekly insurance premium based on worker risk

📊 Features:

  • claim_count_30d
  • tenure_days
  • avg_hourly_rate
  • zone_flood_risk_score
  • zone_disruption_rate_90d
  • weather_forecast_7d_risk_score
  • elevation_m
  • seasonal_factor
  • zone_worker_density

🔹 2. Fraud Detection (Anomaly Detection)

  • Isolation Forest → behavioral anomaly detection
  • Autoencoder (PyTorch) → reconstruction error (deep anomaly signal)

📊 Features:

  • gps_divergence_m
  • platform_gps_divergence_metres
  • ping_interval_variance
  • battery_discharge_rate
  • device_account_count
  • enrollment_delta_days

⚙️ API Endpoints


✅ Health Check

GET /health

{
  "status": "ok"
}

💰 Premium Prediction

POST /predict/premium

🔹 Input

{
  "claim_count_30d": 2,
  "tenure_days": 120,
  "avg_hourly_rate": 90,
  "zone_flood_risk_score": 0.7,
  "zone_disruption_rate_90d": 0.5,
  "weather_forecast_7d_risk_score": 0.6,
  "elevation_m": 15,
  "seasonal_factor": 1.2,
  "zone_worker_density": 0.8
}

🔹 Output

{
  "predicted_premium": 45.23,
  "confidence_note": "Model trained with monotonic constraints",
  "model_version": "v1.0"
}

🚨 Fraud Detection

POST /predict/fraud

🔹 Input

{
  "gps_divergence_m": 2.5,
  "platform_gps_divergence_metres": 1.8,
  "ping_interval_variance": 300,
  "battery_discharge_rate": 0.2,
  "device_account_count": 1,
  "enrollment_delta_days": 120
}

🔹 Output

{
  "fraud_score": -0.02,
  "is_anomaly": false,
  "reconstruction_error": 0.003,
  "risk_level": "low",
  "model_type": "hybrid_iforest_ae",
  "model_version": "v1.0"
}

🏗️ System Architecture

Frontend (Streamlit)
        ↓
Backend API (Node/Python)
        ↓
ML Service (FastAPI)
        ↓
ML Models (XGBoost + Isolation Forest + Autoencoder)

🛠️ Tech Stack

  • FastAPI – API framework
  • Scikit-learn – Isolation Forest, preprocessing
  • XGBoost – Premium prediction
  • PyTorch – Autoencoder
  • NumPy – Numerical processing
  • Joblib – Model serialization

🚀 Run Locally

1️⃣ Clone the repo

git clone <your-repo-url>
cd GigShield-ML

2️⃣ Create virtual environment (recommended)

python -m venv venv
venv\Scripts\activate   # Windows

3️⃣ Install dependencies

pip install -r requirements.txt

4️⃣ Run the server

python -m uvicorn main:app --reload

🌐 Access API

  • Swagger UI:
http://127.0.0.1:8000/docs
  • ReDoc:
http://127.0.0.1:8000/redoc

🧪 Testing

Use Swagger UI to:

  • Send requests
  • Validate responses
  • Simulate backend calls

🔥 Key Highlights

  • ⚡ Real-time ML inference (<100ms)
  • 📈 Feature-aligned with training pipeline
  • 🔍 Hybrid fraud detection (IF + AE)
  • 🧩 Modular microservice architecture
  • 🚀 Deployment-ready

🏁 Status

✅ Models trained and validated ✅ API fully functional ✅ Endpoints tested 🚀 Ready for deployment


📌 Future Improvements

  • Batch prediction endpoints
  • Model monitoring & logging
  • Drift detection
  • Feature store integration
  • CI/CD pipeline

👨‍💻 Author

Built as part of Guidewire Hackathon Project – GigShield


⭐ If you like this project

Give it a ⭐ on GitHub!


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages