liveBook · Manning

Chapter 8: Building AI fraud detectors: From supervised scoring to anomaly identification

What you will learn in chapter 8 of Financial AI in Practice

The introduction scopes this chapter to single-transaction fraud detection, contrasts its two modeling tasks with network analysis, and emphasizes the need to handle fraud-data challenges rigorously.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction scopes this chapter to single-transaction fraud detection, contrasts its two modeling tasks with network analysis, and emphasizes the need to handle fraud-data challenges rigorously.

Key terms: single-transaction detection, supervised learning, unsupervised anomaly detection, network and graph analytics, extreme class imbalance, adversarial drift, production-ready models

8.1 Recognizing the known: The power and nuances of supervised learning in fraud detection

Introduces supervised fraud detection as learning from labeled historical transactions to produce risk scores for real-time decisions.

Key terms: supervised learning, labeled experiences, historical data, risk score

8.1.1 The cornerstone: Acquiring, managing, and wrestling with labeled data

This section explains why supervised fraud detection depends on reliable labels, how rare fraud distorts training, and which metrics reveal useful performance.

Key terms: labeled data, ground truth, chargeback data, human review teams, class imbalance, resampling, oversampling, undersampling, cost-sensitive learning, accuracy

8.1.2 Beyond binary labels: Achieving contextual understanding in fraud classification

The section explains how supervised fraud detection can use transaction context to distinguish unusual but legitimate spending from fraud, reducing false positives.

Key terms: binary classification, context-aware understanding, false positives, benign deviations, fraud signals, data asset layer, feature engineering, customer behavior clustering, feedback from human analysts

8.1.3 Practical realities: The ongoing vigilance in supervised fraud modeling

Effective supervised fraud detection requires explainable decisions, vigilance against model decay, and ways to cope with scarce fraud labels.

Key terms: model interpretability, eXplainable AI (XAI), SHAP, LIME, model decay, concept drift, continuous performance monitoring, retraining, label scarcity, semi-supervised learning

8.2 Data preparation and initial exploration for supervised modeling

This section frames the Kaggle fraud dataset as a simplified snapshot of the dynamic data environment used in production fraud modeling.

Key terms: Credit Card Fraud Detection dataset, creditcard.csv, data asset layer, feature stores, data marts

8.2.1 Loading and understanding our dataset: The Kaggle credit card fraud data

This section inspects the credit card fraud dataset and identifies anonymized features and severe class imbalance as key considerations for modeling.

Key terms: PCA, V1 through V28, Time, Amount, Class, target label, df.shape, value_counts(), features, class imbalance

8.2.2 Essential preprocessing: Scaling features and splitting the data

This section prepares an imbalanced fraud dataset for modeling by scaling two features, making a stratified train-test split, and preserving an unbiased test set.

Key terms: Amount, Time, V1–V28, StandardScaler, standardization, LightGBM, training set, test set, stratification, Class

8.3 Supervised fraud classification in action: Training and tuning a LightGBM model

Introduces LightGBM as the supervised fraud classifier and explains why oversampling must occur within cross-validation folds during tuning.

Key terms: LightGBM, supervised learning, tabular datasets, ML pipeline, oversampling, RandomizedSearchCV, cross-validation fold, data leakage, class imbalance

8.3.1 Defining the modeling pipeline and hyperparameter search space

Defines a reproducible SMOTE–LightGBM randomized-search setup for fraud detection, including leakage-safe resampling, a hyperparameter search space, and a recall-focused objective.

Key terms: SMOTE, LightGBM, pipeline, RandomizedSearchCV, data leakage, n_estimators, num_leaves, min_child_samples, learning_rate, reg_alpha

8.3.2 Training the model with randomized hyperparameter search

This section runs a randomized search that applies SMOTE within cross-validation folds, selects the pipeline with the best recall, and refits it for later test-set evaluation.

Key terms: RandomizedSearchCV, .fit(), 5-fold cross-validation, SMOTE, LightGBM, cross-validated recall, best_model_final, random_search_final, refits, X_train

8.3.3 Evaluating the tuned model: Comprehensive metrics on the test set

This section evaluates the tuned fraud model on an untouched test set using metrics suited to imbalanced classification.

Key terms: test set, X_test, y_test, SMOTE, best_model_final, confusion matrix, true positives, true negatives, false positives, false negatives

8.3.4 Strategic insight: Analyzing performance at top-N% prediction thresholds

This section evaluates a supervised fraud model at different top-N% review depths and uses the precision–fraud-capture tradeoff to guide operational decisions.

Key terms: top N%, predicted fraud probability, precision, fraud capture rate, recall, Precision@TopN%, Fraud Capture Rate@N%, false positives, review depth, operational threshold

8.4 Finding the unknown: Unsupervised anomaly detection with autoencoders

This section explains why anomaly detection can complement supervised fraud detection by flagging behavior that departs from learned normality.

Key terms: supervised learning, unsupervised learning, anomaly detection, normal financial behavior, potential anomalies

8.4.1 Autoencoders: Learning normality to detect deviance

Explains how an autoencoder learns to reconstruct legitimate transactions and uses reconstruction error to flag unusual transactions as possible fraud.

Key terms: autoencoder, encoding, decoder, reconstruct, legitimate transactions, reconstruction error, mean squared error (MSE), mean absolute error (MAE), anomaly score

8.4.2 Preparing data for the autoencoder

This section prepares normal-only training data and a mixed test set so an autoencoder can learn legitimate transactions and later be evaluated for fraud detection.

Key terms: X_train, y_train == 0, legitimate transactions, X_train_autoencoder_legit, label, supervised learning, X_test, reconstruction errors

8.4.3 Building and training the autoencoder model

This section explains how the autoencoder is structured, why its output is linear, and how it is trained and checked using legitimate transactions.

Key terms: Encoder, Decoder, latent space, bottleneck, Dense layers, BatchNormalization, linear activation function, standardized, sigmoid, X_train_ae_fit

8.4.4 Calculating and examining reconstruction errors

This section calculates autoencoder reconstruction errors on the full test set and compares them by true class to see whether fraud produces higher errors.

Key terms: X_test, MSE, MAE, reconstruction errors, true_class, mean, median, anomaly-based fraud detection

8.4.5 Visualizing reconstruction error distributions

This section uses scatter plots to interpret reconstruction errors and show why they can serve as anomaly scores for fraud detection.

Key terms: reconstruction error, scatter plots, anomaly score, autoencoder

8.4.6 Setting practical thresholds in an unsupervised world

This section explains how to choose, safely test, and maintain reconstruction-error thresholds for live fraud detection when incoming transactions have no fraud labels.

Key terms: reconstruction errors, fraud labels, threshold, strategy and monitoring layer, legitimate transactions, golden set, normal error distribution, high percentile, review team capacity, customer friction tolerance

8.4.7 Deploying real-time fraud scoring models: Practical considerations

The section explains how real-time fraud scoring combines distributed components, layered fallbacks, and deployment checks to keep decisions fast and reliable.

Key terms: API gateway, low-latency feature store, model serving layer, decision orchestrator, resilience, layered fallback mechanism, circuit breaker, graceful degradation, legacy rule engine, 99th percentile

8.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 7: Understanding financial fraud and foundational detection strategies Chapter 9: Unveiling hidden connections: Graph-based analytics for advanced fraud detection →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.