AI in Finance & Fraud · Lesson 4 of 8

Feature Engineering for Transactions & Graph Fraud

⏱ 10 min read✅ Check-yourself quiz🏦 Banking & fintech

In fraud detection, features matter more than the algorithm. A plain gradient-boosted model with strong behavioural features beats a fancy model on raw columns. This lesson covers the main feature families and how graphs expose fraud rings.

Behavioural (velocity) features

Compare now with the customer's normal behaviour:

df = df.sort_values("ts")
g = df.set_index("ts").groupby("card_id")["amount"]
df["cnt_1h"]  = g.rolling("1h").count().reset_index(level=0, drop=True).values
df["sum_24h"] = g.rolling("24h").sum().reset_index(level=0, drop=True).values
df["amt_vs_avg"] = df.amount / df.groupby("card_id").amount.transform(lambda s: s.shift().expanding().mean()).fillna(df.amount)

Entity and context features

Graph features: catching rings

Fraudsters reuse resources: devices, phone numbers, addresses, beneficiary accounts. Build a graph:

Useful signals:

import networkx as nx
G = nx.Graph()
G.add_edges_from(zip("acct:" + df.account_id, "dev:" + df.device_id))
size = {n: len(c) for c in nx.connected_components(G) for n in c}
df["device_cluster_size"] = ("acct:" + df.account_id).map(size)

Serving features in real time

Check yourself

What is point-in-time correctness and why does it matter? Each feature value must be computed only from data available before the event. Otherwise the model learns from the future (leakage), and offline performance will not hold in production.
How do graph features help detect money mules? Mule accounts often receive money from many unrelated senders and quickly pass it on. A high in-degree from new senders, shared devices or phones with other suspicious accounts, and proximity to confirmed fraud all stand out in a graph.
How should merchant fraud rate be encoded without leakage? Use out-of-fold target encoding with smoothing towards the global rate, computed only from transactions before the scoring time.
Created by Ajeetkumar