• Security

Deloitte Quantum Machine Learning for Financial Audit and Fraud Detection

Deloitte

Deloitte built quantum kernel SVM models using PennyLane and IBM Quantum to detect financial transaction anomalies indicative of fraud or misstatement, comparing ZZFeatureMap quantum kernel performance to classical gradient boosting on engineered transaction features.

Key Outcome
Quantum kernel SVM achieved 94.2% AUC on synthetic financial fraud dataset vs 94.8% for classical XGBoost; identified 3 anomaly patterns invisible to linear classical kernels.

Financial audit at scale is fundamentally an anomaly detection problem: among billions of transactions processed annually by large enterprises, auditors seek to identify the small fraction that represent errors, misstatements, or deliberate fraud. Classical machine learning approaches (gradient boosting, including XGBoost and LightGBM, and deep neural networks) have substantially improved detection rates over rule-based systems, but struggle with concept drift as fraud patterns evolve and with the detection of low-frequency anomaly clusters that lie in complex non-linear feature spaces. Deloitte’s Quantum Computing practice, working with IBM Quantum under their joint research agreement, investigated whether quantum kernel methods (specifically the quantum kernel support vector machine, or QKSVM, using PennyLane’s quantum computing framework) could capture transaction anomaly patterns that classical kernels (RBF, polynomial) miss, particularly in high-dimensional feature spaces where the quantum kernel has theoretical expressiveness advantages.

The feature engineering pipeline extracted 12 features from each financial transaction: transaction amount (log-scaled), time-of-day, day-of-week, counterparty network centrality (derived from a transaction graph built with NetworkX), rolling 30-day average and standard deviation of amounts, counterparty diversity index, geographic anomaly score, and four categorical one-hot features (transaction type, currency, channel, business unit). These 12 features were normalized to the range [0, pi] for angle encoding into the quantum kernel circuit. The quantum kernel was implemented using Qiskit’s ZZFeatureMap, a parameterized circuit that encodes feature vectors as rotation angles and creates entanglement between feature dimensions via ZZ interactions, followed by the inner product measurement between two encoded states. This kernel function K(x, x’) = |<phi(x)|phi(x’)>|^2 was computed for all pairs of training samples and passed to scikit-learn’s SVC with the precomputed kernel option. PennyLane’s qiskit.ibmq device was used for hardware execution on IBM Eagle, with classical simulation via default.qubit for development.

import pennylane as qml
import numpy as np
from sklearn.svm import SVC
from sklearn.metrics import roc_auc_score, classification_report
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
import pandas as pd

# Feature engineering for financial transaction anomaly detection
def engineer_transaction_features(df):
    """Extract 12 features from raw transaction data."""
    features = pd.DataFrame()
    features['log_amount'] = np.log1p(df['amount'])
    features['hour_sin'] = np.sin(2 * np.pi * df['hour'] / 24)
    features['hour_cos'] = np.cos(2 * np.pi * df['hour'] / 24)
    features['dow_sin'] = np.sin(2 * np.pi * df['day_of_week'] / 7)
    features['counterparty_centrality'] = df['counterparty_centrality']
    features['rolling_mean_30d'] = df['rolling_mean_30d']
    features['rolling_std_30d'] = df['rolling_std_30d']
    features['counterparty_diversity'] = df['counterparty_diversity']
    features['geo_anomaly_score'] = df['geo_anomaly_score']
    # One-hot encoded categoricals (3 binary features)
    features['is_wire_transfer'] = (df['tx_type'] == 'wire').astype(float)
    features['is_foreign_currency'] = (df['currency'] != 'USD').astype(float)
    features['is_after_hours'] = ((df['hour'] < 7) | (df['hour'] > 21)).astype(float)
    return features.values

# Quantum kernel using ZZFeatureMap via PennyLane
n_qubits = 8  # use 8 of 12 features (selected by mutual information)
n_layers = 2  # ZZFeatureMap repetitions

dev = qml.device("default.qubit", wires=n_qubits)

@qml.qnode(dev)
def quantum_kernel_circuit(x1, x2):
    """Compute quantum kernel K(x1, x2) = |<phi(x1)|phi(x2)>|^2."""
    # Encode x1: ZZFeatureMap
    for rep in range(n_layers):
        for i in range(n_qubits):
            qml.Hadamard(wires=i)
            qml.RZ(2.0 * x1[i], wires=i)
        for i in range(n_qubits - 1):
            qml.CNOT(wires=[i, i + 1])
            qml.RZ(2.0 * (np.pi - x1[i]) * (np.pi - x1[i + 1]), wires=i + 1)
            qml.CNOT(wires=[i, i + 1])

    # Encode adjoint of x2 (for inner product measurement)
    for rep in range(n_layers - 1, -1, -1):
        for i in range(n_qubits - 2, -1, -1):
            qml.CNOT(wires=[i, i + 1])
            qml.RZ(-2.0 * (np.pi - x2[i]) * (np.pi - x2[i + 1]), wires=i + 1)
            qml.CNOT(wires=[i, i + 1])
        for i in range(n_qubits - 1, -1, -1):
            qml.RZ(-2.0 * x2[i], wires=i)
            qml.Hadamard(wires=i)

    return qml.probs(wires=range(n_qubits))

def compute_quantum_kernel(x1, x2):
    """Return K(x1, x2) as probability of measuring all-zeros state."""
    probs = quantum_kernel_circuit(x1[:n_qubits], x2[:n_qubits])
    return float(probs[0])  # |<0|phi(x2)^dag phi(x1)|0>|^2

# Build kernel matrix for training set
def build_kernel_matrix(X_train, X_test=None):
    n = len(X_train)
    K_train = np.zeros((n, n))
    for i in range(n):
        for j in range(i, n):
            k = compute_quantum_kernel(X_train[i], X_train[j])
            K_train[i, j] = k
            K_train[j, i] = k

    if X_test is not None:
        m = len(X_test)
        K_test = np.zeros((m, n))
        for i in range(m):
            for j in range(n):
                K_test[i, j] = compute_quantum_kernel(X_test[i], X_train[j])
        return K_train, K_test
    return K_train

# Synthetic fraud dataset (representative of Deloitte internal benchmark)
np.random.seed(42)
n_samples = 500
X_normal = np.random.randn(450, 12) * 0.5
X_fraud = np.random.randn(50, 12) * 1.5 + np.array([1.5, -1.0, 0.8] + [0]*9)
X = np.vstack([X_normal, X_fraud])
y = np.array([0] * 450 + [1] * 50)

scaler = MinMaxScaler(feature_range=(0, np.pi))
X_scaled = scaler.fit_transform(X)

X_train, X_test, y_train, y_test = train_test_split(
    X_scaled, y, test_size=0.2, random_state=42, stratify=y)

# Train quantum kernel SVM
K_train, K_test = build_kernel_matrix(X_train[:100], X_test[:50])  # subset for speed
svm_q = SVC(kernel='precomputed', C=1.0, probability=True)
svm_q.fit(K_train, y_train[:100])
y_scores = svm_q.predict_proba(K_test)[:, 1]
auc_quantum = roc_auc_score(y_test[:50], y_scores)
print(f"Quantum Kernel SVM AUC: {auc_quantum:.4f}")

# Classical baseline: XGBoost
from xgboost import XGBClassifier
xgb = XGBClassifier(n_estimators=200, max_depth=6, learning_rate=0.05)
xgb.fit(X_train, y_train)
auc_classical = roc_auc_score(y_test, xgb.predict_proba(X_test)[:, 1])
print(f"XGBoost AUC: {auc_classical:.4f}")

The quantum kernel SVM achieved 94.2% AUC on the synthetic financial fraud benchmark dataset, compared to 94.8% for XGBoost, a difference within the margin of statistical noise for this dataset size and consistent with the theoretical expectation that quantum kernel advantage becomes significant only at larger feature dimensions and more complex data manifolds. More practically significant was the qualitative analysis: by inspecting the support vectors and the structure of the quantum kernel Gram matrix, Deloitte’s team identified three anomaly clusters in the transaction feature space that XGBoost’s tree-based model assigned near-zero importance but that the quantum kernel clearly separated from the normal distribution. These clusters corresponded to structured transaction patterns with unusual counterparty network centrality combined with end-of-quarter timing, a signature consistent with round-tripping schemes. The clusters were invisible to linear and RBF classical kernels due to their geometric structure in the high-dimensional feature space, demonstrating that quantum kernels can provide complementary signal even when aggregate AUC is comparable to classical methods. Deloitte has incorporated quantum kernel screening as a second-stage filter in its AI-assisted audit pipeline, flagging quantum-identified anomalies for human auditor review independent of the primary XGBoost classifier.