Explainable Anomaly Detection in Accounting Journal Entries Using Autoencoders and Counterfactual Explanations
Abstract
In financial auditing, an autoencoder (AE) can flag a journal entry as anomalous, but the auditor still needs to know which attributes triggered the flag and how to correct the entry. We address both questions with a pipeline that uses attribute-level SHAP (SHapley Additive exPlanations) attribution (RESHAPE) for root-cause identification, and RESHAPE-guided beam search with gradient-based numeric optimization for counterfactual explanation (CF) generation. We use two thresholds: global binary cross-entropy (BCE) loss for detection, and per-attribute thresholds for CF validity. The detection threshold is selected label-free, from a target false-positive rate measured on a held-out clean validation set, so that no anomaly labels enter threshold selection. On 532,789 normal SAP-format accounting journal entries, split into training, validation, and test partitions with 120 injected anomalies held out for evaluation, the detector flagged all 120 anomalies (100% recall) while raising only 31 false positives on the 79,919-entry clean test set (false-positive rate $3.9\times 10^{-4}$ ). On those 120 anomalies, the CF pipeline exactly matched the ground-truth modified attributes in 30 cases (25.0%) and hit at least one ground-truth attribute in 99 cases (82.5%), averaging 1.18 modifications per CF, and outperformed the Wachter, DiCE, and FACE counterfactual baselines, achieving the highest exact-match rate at full validity with the sparsest corrections.