> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/sdgm/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/sdgm/_mcp/server.

# Credit Card Fraud Detection Solution

## Solution Background and Business Value

Credit card fraud causes significant losses for financial institutions, businesses, and consumers.
Fraud occurs when a malicious actor gains unauthorized access to a customer’s credit card and makes fraudulent transactions.

Machine learning models can detect fraud **in real-time**, enabling teams to:

* **Identify suspicious transactions early** and intervene before money is lost.
* **Reduce false positives**, so legitimate transactions are not blocked.
* **Improve detection accuracy** by learning from **graph-based patterns** in transaction networks.

## Data Requirements and Schema

Kumo AI processes relational data as interconnected tables using **Graph Neural Networks (GNNs)**.
This approach allows the model to learn from **transaction patterns, account behavior, and merchant interactions** without extensive feature engineering.

![Entity relationship diagram showing connections between the credit cards, transactions, and fraud reports tables](file:images/Screenshot2025-06-27at1.34.01PM.png "Credit card fraud detection data schema")

**Core Tables**

1. **Transactions Table**
   * Stores all recorded transactions.
   * **Key attributes:**
     * `transaction_id`: Unique identifier for each transaction.
     * `timestamp`: When the transaction occurred.
     * `credit_card_id`: Links transaction to a credit card.
     * `merchant_id`: Links transaction to a merchant.
     * **Optional:** Location, currency, amount, transaction type.
2. **Credit Cards Table**
   * Represents unique credit cards in the system.
   * **Key attributes:**
     * `credit_card_id`: Unique identifier.
     * `cc_open_date`: Date when the card was issued.
     * `cc_close_date`: Date when the card was closed (if applicable).
     * **Optional:** Credit limit, APR, fraud risk score.
3. **Fraud Reports Table**
   * Stores fraud labels for transactions.
   * **Key attributes:**
     * `transaction_id`: Links to the transaction flagged as fraudulent.
     * `timestamp`: When the fraud report was filed.
     * `label`: 1 if fraudulent, 0 if legitimate.

**Additional Tables (Optional)**

* **Users Table:** Links credit cards to customers.
* **User Stats Table:** Stores aggregated stats like transaction count and total spend.
* **Merchants Table:** Stores merchant details (for example, category, location, or risk rating).

**Entity Relationship Diagram (ERD)**

```mermaid
erDiagram
    CREDIT_CARDS {
        INT credit_card_id PK
        TIMESTAMP cc_open_date
        TIMESTAMP cc_close_date
        FLOAT credit_limit
    }
    
    TRANSACTIONS {
        INT transaction_id PK
        INT credit_card_id FK
        INT merchant_id FK
        TIMESTAMP timestamp
        FLOAT amount
    }
    
    FRAUD_REPORTS {
        INT report_id PK
        INT transaction_id FK
        TIMESTAMP timestamp
        INT label
    }

    CREDIT_CARDS ||--o{ TRANSACTIONS : "used in"
    TRANSACTIONS ||--o{ FRAUD_REPORTS : "flagged"
```

## Predictive Query for Credit Card Fraud Detection

A **predictive query** (PQL) tells Kumo what to predict and for which entity.
The examples below cover three common fraud detection targets.

**1. Transaction-Level Fraud Detection**

Predict whether a transaction is fraudulent based on past fraud reports:

```pql
PREDICT transactions.LABEL
FOR EACH transactions.transaction_id
```

* When scoring new transactions, leave `LABEL` empty: Kumo generates a fraud risk score for each.

**2. Time-Based Fraud Prediction**

Predict whether a fraud report will be linked to a transaction in the next 30 days.
The `ASSUMING` clause filters predictions to transactions that already have at least one associated fraud report in that window, keeping the training set focused:

```pql
PREDICT SUM(fraud_reports.LABEL, 0, 30, days) > 0
FOR EACH transactions.transaction_id
ASSUMING COUNT(fraud_reports.*, 0, 30, days) >= 1
```

**3. Credit Card Risk Prediction**

Predict whether a credit card will be associated with fraudulent transactions in the next 7 days:

```pql
PREDICT COUNT(transactions.LABEL, 0, 7, days) >= 1
FOR EACH credit_cards.credit_card_id
ASSUMING COUNT(transactions.LABEL, 0, 7, days) >= 1
```

## Deployment Strategy

**1. Batch Predictions for Fraud Analysts**

* Fraud teams review **high-risk transactions** flagged by the model.
* Predictions are generated **hourly or daily** in batch mode.
* Fraud analysts **label new fraudulent transactions**, which can be fed back to improve the model over time.

To limit batch predictions to recent transactions, add a timestamp filter to your predictive query:

```pql
WHERE transactions.TIMESTAMP > MIN_TIMESTAMP
```

**2. Real-Time Fraud Detection**

* The system generates **instant fraud risk scores** when a transaction occurs.
* High-risk transactions can trigger **manual review or two-factor authentication**.
* Model embeddings can also enhance existing rule-based fraud detection pipelines.

## Building Models with the Kumo Fine-Tune SDK

**1. Initialize the Kumo Fine-Tune SDK**

```python
import kumoai as kumo

kumo.init(url="https://<customer_id>.kumoai.cloud/api", api_key=API_KEY)
```

**2. Connect data**

```python
connector = kumo.S3Connector("s3://your-dataset-location/")
```

**3. Select tables**

```python
credit_cards = kumo.Table.from_source_table(
    source_table=connector.table('credit_cards'),
    primary_key='credit_card_id',
).infer_metadata()

transactions = kumo.Table.from_source_table(
    source_table=connector.table('transactions'),
    time_column='timestamp',
).infer_metadata()

fraud_reports = kumo.Table.from_source_table(
    source_table=connector.table('fraud_reports'),
    time_column='timestamp',
).infer_metadata()
```

**4. Create graph schema**

```python
graph = kumo.Graph(
    tables={
        'credit_cards': credit_cards,
        'transactions': transactions,
        'fraud_reports': fraud_reports,
    },
    edges=[
        dict(src_table='transactions', fkey='credit_card_id', dst_table='credit_cards'),
        dict(src_table='fraud_reports', fkey='transaction_id', dst_table='transactions'),
    ],
)

graph.validate(verbose=True)
```

**5. Train the model**

The training table is generated asynchronously (`non_blocking=True`), while `trainer.fit` waits for training to complete before returning (`non_blocking=False`).

```python
pquery = kumo.PredictiveQuery(
    graph=graph,
    query="PREDICT transactions.LABEL FOR EACH transactions.transaction_id"
)
pquery.validate(verbose=True)

model_plan = pquery.suggest_model_plan()
trainer = kumo.Trainer(model_plan)
training_job = trainer.fit(
    graph=graph,
    train_table=pquery.generate_training_table(non_blocking=True),
    non_blocking=False,
)
print(f"Training metrics: {training_job.metrics()}")
```