Full implementation of the TB-TARL anomaly detection model, dataset simulation, baselines, SHAP, fairness analysis, and ablation studies for my PhD dissertation.
# TB-TARL: Transformer-Based Anomaly Detection for Ghana’s Financial Transactions
This repository contains the full code, simulation pipeline, models, and research outputs
for PHD Dissertation project by Sandra Birikorang:
"Designing a Novel Transformer-Based Algorithm for Anomaly Detection in Ghana’s Financial Transactions."
Data Availability & Reproducibility
This project uses external dataset, which is already included in the repository: API_GHA_DS2_en_csv_v2_43964.zip
World Bank Ghana development indicators used to anchor the simulation.
All other datasets (transactions, features, windows, labels, anomalies) are generated automatically when you run the notebook.
How Data Is Generated in the Workflow
The notebook builds the full synthetic Ghana mobile-money dataset through the following steps:
1️⃣Big Simulation Pipeline (first cell) reads the World Bank ZIP file, Generates 5,000 synthetic users and demographic profiles and Creates Ghana-style distributions for channels, devices, amounts, merchants, regions
2️⃣ Cell X — Cleaning Setup prepares cleaned structures and ensures stable feature computation
3️⃣ Cell 1 — Transaction + Feature Generation simulates all transactions, computes timing gaps, switching behavior, geo distance, merchant drift, builds 30-step sliding windows, injects anomalies realistically and saves raw and cleaned datasets into /content/data/
4️⃣ Cell 2 — TB-TARL Model trains the reconstruction + attention hybrid model and computes anomaly scores for each window
5️⃣ Cell 3 — Baselines (Isolation Forest, One-Class SVM ,Autoencoder) aggregates scores to window-level
6️⃣ Cell 4 — SHAP (RQ3) trains surrogate Random Forest and computes and ranks SHAP values
7️⃣ Cell 5 — Stratified Evaluation computes fairness metrics across gender, region, income band, and urbanicity
8️⃣ Cell 6 — Ablation Study tests the importance of time encoding, sequence order, attention, and reconstruction loss
Why the Large Data Files Are Not Uploaded
The CSVs generated by …