Nikhil1417/Ann-Drift-detection
0
๐ ModelShift Monitor
A lightweight, end-to-end data drift detection tool built with a pre-trained autoencoder, a FastAPI inference backend, and a Streamlit frontend.
Upload any CSV โ ModelShift scores each row against the training distribution and tells you whether your live data has drifted.
๐๏ธ Project Structure
ModelShift-Monitor/
โโโ app.py # Streamlit UI
โโโ main.py # FastAPI backend
โโโ requirements.txt
โโโ runtime.txt
โโโ .streamlit/
โ โโโ config.toml # UI theme
โโโ .devcontainer/
โ โโโ devcontainer.json # VS Code dev container
โโโ model/
โโโ autoencoder_drift_model.h5
โโโ scaler.pkl
โโโ feature_columns.pkl
โโโ drift_threshold.jsonโ๏ธ How It Works
- Autoencoder โ trained on the original (clean) dataset to learn its distribution.
- Reconstruction error โ for each incoming row, the model attempts to reconstruct it. High error โ the sample is out-of-distribution.
- Drift ratio โ the fraction of samples whose error exceeds the calibrated threshold.
- Decision โ if more than 30 % of samples exceed the threshold, drift is flagged.
๐ Running Locally
1 โ Install dependencies
pip install -r requirements.txt2 โ Start the FastAPI backend
uvicorn main:api --reload --port 80003 โ Launch the Streamlit app
streamlit run app.pyOpen http://localhost:8501 in your browser.
๐ API Endpoints
Example request body
{
"columns": ["feature_1", "feature_2"],
"data": [[0.5, 1.2], [0.9, 0.3]]
}Example response (/detect_drift)
{
"drift_ratio": 0.12,
"drift_detected": false
}๐งฉ Tech Stack
๐ Notes
- Input CSV must contain numeric columns that overlap with the training feature set.
- Rows are capped at 1 000 before inference for latency reasons.
- The hosted backend is on Hugging Face Spaces and may cold-start โ allow ~30 s on the first request.
