Anomaly detection for fraud prevention using Isolation Forest and LOF with FastAPI serving
Synthetic fraud/anomaly detection pipeline that trains Isolation Forest + LOF on 50k hourly transactions, tracks runs in MLflow, exposes Streamlit + FastAPI for dashboards/RPA, and outputs alerts.
Set directory:
cd /Users/andresverafigueroa/Documents/GitHub/Works/03-anomaly-detection-fraud-prevention
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export MLFLOW_TRACKING_URI="$(pwd)/mlruns"
python3 scripts/train.py --config configs/config.yaml
Outputs: model joblib, metrics JSON, scores CSV, MLflow run../scripts/run_api.sh
Endpoints: /health, /score (single transaction), /batch_score, /metrics.streamlit run src/app.py -- --config configs/config.yaml
http://localhost:8000/score or /batch_score with JSON payload for live anomaly data.configs/ – config (paths, model params, threshold, alerts)data/03-anomaly/ – raw + processed CSVsmodels/03-anomaly/ – serialized pipelineartifacts/ – metrics, scores, alertssrc/ – data gen, features, model training, API, dashboardscripts/ – train, run API, serve Streamlit, run alertstests/ – unit + integration testsdocs/ – reference notespython3 scripts/train.py --config configs/config.yaml./scripts/run_api.shstreamlit run src/app.py -- --config configs/config.yamlpytest -qalerts.jsonl with flagged transactions; inspect it to feed RPA.configs schema (see src/api/app.py).