Skip to content

About

A zero-cost, high-performance Trust Engine that identifies complex fraud archetypes across 1M+ synthetic banking transactions with sub-second inference speed.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

πŸ›‘οΈ RiskMetric β€” Algorithmic Fraud Detection & Spatial-Temporal Risk Modeling

A zero-cost, high-performance Trust Engine that identifies complex fraud archetypes across 1M+ synthetic banking transactions with sub-second inference speed.

Python DuckDB dbt Streamlit


πŸ“Š Executive Overview

RiskMetric Landing Page The executive dashboard provides real-time KPI tracking, fraud archetype distributions, and spatial-temporal risk metrics across all processed transactions.

πŸ—ΊοΈ Geographic & Behavioral Analysis

RiskMetric Geographic Analysis Detailed spatial analysis mapping impossible travel hotspots, alongside velocity spike and behavioral drift detection metrics to identify compromised accounts.

🚨 Operational Triage Queue

RiskMetric Triage Queue An interactive alert management system allowing fraud analysts to filter by risk tier, review evidence (e.g., ground speed, Z-scores), and disposition cases in real-time.


Architecture β€” Medallion System

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    GitHub Actions CI/CD                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  BRONZE  β”‚      SILVER      β”‚     GOLD      β”‚   INTERFACE   β”‚
β”‚          β”‚                  β”‚               β”‚               β”‚
β”‚ generatorβ”‚ Impossible Travelβ”‚ Risk Scores   β”‚  Streamlit    β”‚
β”‚   .py    β”‚ (Haversine/GPS)  β”‚ (Composite)   β”‚  Dashboard    β”‚
β”‚          β”‚                  β”‚               β”‚               β”‚
β”‚ 1M+ raw  β”‚ Velocity Spikes  β”‚ User Risk     β”‚  Real-time    β”‚
β”‚ records  β”‚ (60s windows)    β”‚ Profiles      β”‚  Watchdog     β”‚
β”‚          β”‚                  β”‚               β”‚               β”‚
β”‚ Parquet  β”‚ Behavioral Drift β”‚ Fraud         β”‚  SQL Explorer β”‚
β”‚          β”‚ (Z-Score/30d MA) β”‚ Attribution   β”‚               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Faker   β”‚     DuckDB       β”‚   dbt-core    β”‚   Plotly      β”‚
β”‚  PyArrow β”‚   + dbt macros   β”‚  + dbt tests  β”‚   + Geo Maps  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Fraud Archetypes Detected

Archetype Method Threshold
Impossible Travel Haversine distance + ground speed between consecutive transactions > 500 mph
Velocity Spikes 60-second sliding window transaction count β‰₯ 10 txns / 60s
Behavioral Drift Z-Score against 30-day rolling average |Z| > 3Οƒ

Tech Stack ($0 Cost)

  • Engine: DuckDB β€” vectorized, in-process OLAP
  • Storage: Apache Parquet β€” columnar, compressed
  • Pipeline: dbt-core β€” modular, tested, version-controlled SQL
  • Orchestration: GitHub Actions β€” CI/CD on every push
  • Interface: Streamlit + Plotly β€” executive-level dashboard

Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Run Full Pipeline (Bronze β†’ Silver β†’ Gold)

python run_pipeline.py

This will:

  • Generate 1M+ synthetic transactions with injected fraud
  • Run all dbt models (Silver enrichment + Gold aggregation)
  • Run dbt data integrity tests
  • Export Gold tables to Parquet
  • Generate dbt documentation and data lineage graph
  • Print a summary report with model evaluation metrics

3. Launch Dashboard

streamlit run dashboard/app.py

4. View Data Lineage (dbt Docs)

dbt docs serve --profiles-dir riskmetric --project-dir riskmetric

Manual Steps (Optional)

# Generate data only
python generator.py

# Run dbt models only (with full refresh for incremental models)
cd riskmetric
dbt run --profiles-dir . --project-dir . --full-refresh
dbt test --profiles-dir . --project-dir .
dbt docs generate --profiles-dir . --project-dir .

Project Structure

Banking Sentinel/
β”œβ”€β”€ generator.py                    # Bronze: 1M+ synthetic transaction generator
β”œβ”€β”€ run_pipeline.py                 # Full pipeline orchestrator
β”œβ”€β”€ config.yml                      # Centralized thresholds & calibration config
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ data/                           # Generated data (gitignored)
β”‚   β”œβ”€β”€ raw_transactions.parquet    # Bronze layer
β”‚   β”œβ”€β”€ user_profiles.parquet       # Bronze layer
β”‚   └── riskmetric.duckdb           # DuckDB warehouse
β”œβ”€β”€ riskmetric/                     # dbt project
β”‚   β”œβ”€β”€ dbt_project.yml             # dbt config + vars for threshold calibration
β”‚   β”œβ”€β”€ profiles.yml
β”‚   β”œβ”€β”€ macros/
β”‚   β”‚   └── haversine.sql           # Haversine distance macro
β”‚   └── models/
β”‚       β”œβ”€β”€ staging/                # Raw β†’ Staged
β”‚       β”‚   β”œβ”€β”€ stg_transactions.sql
β”‚       β”‚   └── stg_user_profiles.sql
β”‚       β”œβ”€β”€ silver/                 # Fraud detection (incremental)
β”‚       β”‚   β”œβ”€β”€ silver_impossible_travel.sql
β”‚       β”‚   β”œβ”€β”€ silver_velocity_spikes.sql
β”‚       β”‚   └── silver_behavioral_drift.sql
β”‚       └── gold/                   # Curated risk models
β”‚           β”œβ”€β”€ gold_risk_scores.sql
β”‚           β”œβ”€β”€ gold_user_risk_profiles.sql
β”‚           β”œβ”€β”€ gold_fraud_attribution.sql
β”‚           β”œβ”€β”€ gold_model_evaluation.sql       # Precision/Recall/F1
β”‚           └── gold_threshold_calibration.sql  # Threshold sensitivity
β”œβ”€β”€ dashboard/
β”‚   └── app.py                      # Streamlit dashboard (8 pages)
└── .github/workflows/
    └── pipeline.yml                # CI/CD automation

Risk Scoring

The composite risk score (0–100) is a weighted sum of detected fraud signals:

Signal Weight Rationale
Impossible Travel 40 pts Strongest signal β€” rarely a false positive at >500 mph
Velocity Spike 35 pts Card testing precursor β€” high urgency for blocking
Behavioral Drift 25 pts Spending anomalies β€” higher FP rate, requires human review

Risk Tiers: CRITICAL (β‰₯60) Β· HIGH (β‰₯35) Β· MEDIUM (β‰₯25) Β· LOW (<25)

All weights and tier cutoffs are externalized as dbt variables in dbt_project.yml and documented in config.yml, enabling data-driven recalibration without code changes.

Model Evaluation

The pipeline computes full classification metrics against ground-truth labels:

Metric Description
Precision TP / (TP + FP) β€” how many flags are real fraud
Recall TP / (TP + FN) β€” how much fraud is caught
F1-Score Harmonic mean of Precision and Recall
False Positive Rate FP / (FP + TN) β€” operational noise level
Confusion Matrix Full TP/FP/FN/TN breakdown per archetype

The gold_threshold_calibration model evaluates detection performance across a range of thresholds per archetype, producing precision-recall tradeoff curves for optimal operating point selection.

Calibration Methodology

  1. Initial weights set by domain expertise (fraud analyst heuristics)
  2. Threshold sensitivity analysis via gold_threshold_calibration β€” tests speed thresholds (200–800 mph), velocity counts (3–20 txns), and Z-Score bounds (1.5–5.0Οƒ)
  3. Validation against labeled ground truth using gold_model_evaluation β€” reports precision, recall, and F1 per archetype
  4. Production path: weights would be tuned via logistic regression coefficients or gradient-boosted model feature importances; periodic recalibration (quarterly) as fraud patterns evolve

Incremental Processing

Silver-layer models use dbt's incremental materialization strategy:

  • On first run: full table build
  • On subsequent runs: only processes transactions newer than MAX(transaction_timestamp) in the existing table
  • Use --full-refresh flag to force a complete rebuild

This mirrors production patterns where millions of daily transactions are processed incrementally rather than rebuilt from scratch.

Dashboard Pages

Page Purpose
Overview Executive KPIs, fraud by archetype, timeline, accuracy
Impossible Travel Speed distribution, geo map, flagged transactions
Velocity Spikes Burst analysis, amount patterns
Behavioral Drift Z-Score distribution, amount vs rolling average
User Profiles Per-user risk aggregation, tier filtering
Model Evaluation Precision/Recall/F1, confusion matrix, calibration curves
Triage Queue Alert case management with disposition workflow
Raw Explorer Ad-hoc SQL queries against DuckDB warehouse

Known Limitations & Future Work

  • Self-labeled data: Fraud is injected by the same system that detects it, creating circular validation. A production system would use externally labeled data or blind holdout sets.
  • No temporal train/test split: All evaluation is in-sample. Production deployment would require forward-looking validation on unseen future data.
  • Static thresholds: Current thresholds are fixed. A production system would use adaptive thresholds that adjust to evolving fraud patterns (concept drift).
  • Scale ceiling: DuckDB handles 1M+ records locally with ease. At 1B+ records, consider partitioned Parquet, incremental dbt models with date-based partitioning, and migration to cloud OLAP (Snowflake/BigQuery).
  • No real-time stream: Current architecture is batch-oriented. Real-time fraud detection would require a streaming layer (Kafka + Flink) feeding into the same model logic.

About

A zero-cost, high-performance Trust Engine that identifies complex fraud archetypes across 1M+ synthetic banking transactions with sub-second inference speed.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages