| title | Fraud Detection | ||||||
|---|---|---|---|---|---|---|---|
| description | Find transfers that may be fraudulent by looking at payment details and the flow of money between accounts. Then prioritize cases for investigators by both the chance of fraud and the amount at stake. | ||||||
| featured | true | ||||||
| experience_level | advanced | ||||||
| industry | Financial Services | ||||||
| reasoning_types |
|
||||||
| tags |
|
||||||
| sidebar |
|
Full guide: Explore the Fraud Detection model, run the example, and follow the code.
Payments teams often receive more fraud alerts than investigators can review, and transaction attributes alone can miss suspicious account-network behavior. This template combines network signals with a fraud classifier, then selects the investigations that maximize expected loss averted within a fixed investigator-hours budget. Adapt its transaction data, fraud signals, predictive model, and review constraints for your workflow.
Before you start, install Python 3.10 or later and get access to a Snowflake
account with the RAI Native App. Graph, Predictive, and Prescriptive reasoning
are in Public Preview; ask your RelationalAI support representative to enable
Prescriptive reasoning. Preview features are for evaluation and testing, not
production applications. The local demo uses bundled CSVs and runs on CPU
without an external dataset or GPU. The template pins
relationalai[gnn]==1.27.1 in pyproject.toml.
Ask an administrator to run this SQL before you start. It creates the writable
experiment schema used by fraud_detection_local.py and grants the RAI Native
App access:
CREATE DATABASE IF NOT EXISTS FRAUD_DETECTION;
CREATE SCHEMA IF NOT EXISTS FRAUD_DETECTION.EXPERIMENTS;
GRANT USAGE ON DATABASE FRAUD_DETECTION TO APPLICATION RELATIONALAI;
GRANT USAGE ON SCHEMA FRAUD_DETECTION.EXPERIMENTS TO APPLICATION RELATIONALAI;
GRANT CREATE EXPERIMENT ON SCHEMA FRAUD_DETECTION.EXPERIMENTS TO APPLICATION RELATIONALAI;
GRANT CREATE MODEL ON SCHEMA FRAUD_DETECTION.EXPERIMENTS TO APPLICATION RELATIONALAI;Use this sequence to run the bundled example:
-
Download the template
Download the ZIP, unzip it, and enter the template directory:
unzip fraud-detection.zip cd fraud-detection -
Create a Python environment
Create and activate a virtual environment, then update pip:
python -m venv .venv source .venv/bin/activate python -m pip install --upgrade pip -
Install the template
Install the dependencies pinned in
pyproject.toml:python -m pip install . -
Configure your project
Use the configuration builder in Start building with PyRel to create
raiconfig.yamlin the template directory and verify your connection.Add this setting to
raiconfig.yamlbefore running the template:data: ensure_change_tracking: true
-
Run the template
Run the bundled script from the template directory:
python fraud_detection_local.py
The run reports the classifier's ROC-AUC score, ranked alerts, and the audit schedule that fits the investigator budget. The bundled PaySim sample overrepresents fraud for CPU training, so its scores don't estimate real-world detection accuracy. The sample comes from Edgar Lopez-Rojas's PaySim synthetic mobile-money dataset under CC BY-SA 4.0. See
data/paysim_mini/LICENSE.txtfor attribution and citation details.