Anomaly detection API for transaction scoring. Exposes a FastAPI service that returns a fraud probability and binary prediction from a JSON payload (e.g. Time, Amount, Hour).
- Python 3.11+
- Or Docker
pip install -r requirements.txtuvicorn api.main:app --host 127.0.0.1 --port 8000Then open http://127.0.0.1:8000/docs for the interactive API docs.
From the project root:
docker build -t fraud-scanner .
docker run -p 8000:8000 fraud-scannerThe API is available at http://localhost:8000.
| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check → {"status":"ok"} |
| POST | /predict |
Score a transaction (JSON body) |
Example /predict request:
{ "Time": 0.0, "Amount": 100.0, "Hour": 14 }Example response:
{
"prob": 0.23,
"pred": 0,
"threshold": 0.5,
"missing_features": []
}prob: fraud probability (0–1)pred: 1 if fraud, 0 otherwise (based onthreshold)missing_features: list of expected features not sent (filled with 0.0)
pytest- If
models/best_model.joblibexists, it is loaded at startup (must containmodel,threshold,features). - If not, a small default logistic regression model is created and saved so the API runs out of the box. Replace
models/best_model.joblibwith your own trained bundle when ready.
api/main.py— FastAPI app and/health,/predictsrc/— training and scoring scripts (train_rf.py,batch_score.py, etc.)tests/— API and smoke testsnotebooks/— EDA and exploration