> This page is for Kumo Engine.

> 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.

# Credit Card Fraud Detection Solution

Kumo's temporal heterogeneous graph neural network (GNN) combines transaction attributes with connected account and merchant histories, modeling relationships across entity types over time.
It learns relational fraud signals from labeled transactions, reducing the need for task-specific cross-table aggregates.
The same architecture supports transaction scoring and predictions of future fraud at the card or merchant level.

## Why the Temporal Graph Matters

Account neighborhoods capture changes in individual spending behavior.
Merchant neighborhoods expose activity shared across cardholders.
Multi-hop message passing combines signals across connected entities, so the model can learn patterns that span multiple transactions and entity types.

Temporal sampling separates historical inputs from the outcome being predicted.
Relative-time encodings preserve recency within that history.
Together, they let the model learn how a pattern's timing affects its relevance to a fraud decision.

![A temporal subgraph around transaction v connects its card account to earlier transactions and merchants. Node encoders and GNN aggregation produce a representation of v, followed by a binary fraud prediction.](/sdgm/_fern-files/nvidia-sdgm.docs.buildwithfern.com/24eecf617e5d557cc2703d065564272928fce81f12250dd1bf79900bd3a42df1/_dot_dot_/images/diagrams/fraud-gnn-architecture.svg)

The classifier produces a fraud probability; the figure shows the binary decision after thresholding.
See [Temporal Hetero-GNN](/sdgm/kumo-engine/user-code-guide/train-a-model/temporal-hetero-gnn).

## The Prediction Questions

The entity being predicted determines the decision the model supports: reviewing an individual transaction, identifying a compromised card, or detecting merchant activity that affects multiple cardholders.
Each question can reuse the same graph snapshot with its own target and trained model.

<details>
  <summary>
    Tables used in the query examples
  </summary>

  The queries assume a prepared Kumo Engine `graph` and matching `snapshot` with these tables:

  ![Transactions link to credit\_cards through credit\_card\_id and to merchants through merchant\_id. Transactions also define transaction\_id, the time column timestamp, and label. Card and merchant attribute examples are shown without assigning column names or types.](/sdgm/_fern-files/nvidia-sdgm.docs.buildwithfern.com/dbd26a3506448fa3e8ec26727fedb21415baff9abb7f309b36e7b5aca400a25d/_dot_dot_/images/diagrams/workflow-credit-card-fraud-detection-solution-schema.svg)

  | Table          | Columns used here                                                       | Role                                                                                                      |
  | -------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
  | `transactions` | `transaction_id`, `credit_card_id`, `merchant_id`, `timestamp`, `label` | Payments made with a card at a merchant, where `label` is `1` for fraud and `0` for a legitimate payment. |
  | `credit_cards` | `credit_card_id`                                                        | Card accounts, with attributes such as opening date and credit limit.                                     |
  | `merchants`    | `merchant_id`                                                           | Merchants, with attributes such as category.                                                              |

  `timestamp` places each payment in its history.
  For graph preparation and training, see [Train a Classification Model](/sdgm/kumo-engine/user-code-guide/code-examples/linux-deployment/train-a-classification-model).
</details>

## Score each transaction for fraud

Transaction scoring estimates the fraud risk of an observed payment using the account and merchant history available at its timestamp.
The target `transactions.label = 1` specifies binary classification; predicting the numeric `label` column directly would define a regression task.

```python
from kumo.engine import PredictiveQuery

query_text = (
    "PREDICT transactions.label = 1 "
    "FOR EACH transactions.transaction_id"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Predict future fraud on a card

Card-level prediction identifies accounts at risk of fraud before another payment is attempted.
The target is positive if any fraudulent payment occurs during `(t, t + 7 days]`, where `t` is the scoring time.
The aggregation constructs that target from the transaction fraud labels.

```python
query_text = (
    "PREDICT SUM(transactions.label, 0, 7, days) > 0 "
    "FOR EACH credit_cards.credit_card_id"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Predict future fraud at a merchant

Merchant-level prediction supports decisions that apply across cardholders, such as prioritizing merchants for investigation.
It combines evidence from transactions made with different cards and predicts whether the merchant will receive a fraudulent payment during `(t, t + 30 days]`.

```python
query_text = (
    "PREDICT SUM(transactions.label, 0, 30, days) > 0 "
    "FOR EACH merchants.merchant_id"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Reading the predictions

Evaluate fraud recall at the false-positive rate or review volume the application can support.
Keep evaluation chronological and report results separately for transaction, card, and merchant predictions.
Their target populations and seven-day or 30-day horizons define different operating problems.