Abstract
Anomaly detection in sequential data has been studied for a long time because of its potential in various applications, such as detecting abnormal system behaviors from log data. Although many approaches can achieve good performance on anomalous sequence detection, how to identify the anomalous entries in sequences is still challenging due to a lack of information at the entry-level. In this work, we propose a novel framework called CFDet for fine-grained anomalous entry detection. CFDet leverages the idea of interpretable machine learning. Given a sequence that is detected as anomalous, we can consider anomalous entry detection as an interpretable machine learning task because identifying anomalous entries in the sequence is to provide an interpretation to the detection result. We make use of the deep support vector data description (Deep SVDD) approach to detect anomalous sequences and propose a novel counterfactual interpretation-based approach to identify anomalous entries in the sequences. Experimental results on three datasets show that CFDet can correctly detect anomalous entries.
Introduction
Anomaly detection in sequential data, such as server logs or user clickstreams, is critical for cybersecurity and system health monitoring. However, most existing tools are "coarse-grained": they can identify that a sequence is suspicious but fail to pinpoint why or where the specific problem lies. This limitation stems from two primary challenges: a lack of entry-level labels in real-world datasets and the inherent complexity of anomalies that only emerge within a specific context.
CFDet addresses these issues by treating fine-grained detection as an interpretability task. By asking "what is the smallest change that would make this sequence look normal?", the framework generates counterfactual explanations that naturally identify the anomalous entries responsible for a sequence-level alert.
Methodology
CFDet operates in a two-phase framework designed to move from broad sequence detection to granular entry identification.
Phase 1: Anomalous Sequence Detection
The model first establishes a baseline for "normal" behavior using Deep Support Vector Data Description (Deep SVDD). An LSTM is trained to map normal sequences into a latent space, clustering them tightly around a central point (a hypersphere). Sequences that fall outside this hypersphere are flagged as anomalous.
Phase 2: Fine-grained Entry Detection
Once a sequence is flagged, CFDet identifies the specific entries causing the anomaly. It utilizes a second LSTM-based detector to generate a binary indicator sequence ($A$). This indicator partitions the original sequence into a "normal" subsequence ($Z^+$) and an "anomalous" subsequence ($Z^-$).
To train this detector without entry-level labels, the authors employ a composite loss function based on four key properties:
- Normality: The kept entries ($Z^+$) must map close to the "normal" center in the latent space.
- Comprehensiveness: The removed entries ($Z^-$) should be distinctively non-normal.
- Continuity: Since log anomalies often occur in bursts, the model favors selecting consecutive entries.
- Sparsity: The model assumes anomalies are relatively rare within any given sequence.
Because the indicator sequence is discrete, standard gradient descent is inapplicable. Instead, the authors utilize Policy Gradient (Reinforcement Learning), rewarding the detector for finding an optimal counterfactual subsequence.
Evaluation and Results
The framework was evaluated on three benchmarks: BGL (BlueGene/L), Thunderbird, and CERT Insider Threat. While these datasets contain entry-level labels for validation, CFDet was trained using only sequence-level information.
Performance Metrics
CFDet significantly outperformed traditional baselines and common interpretability methods like Attention weights or Shapley values:
- Thunderbird: Achieved an F1-score of 94.97% and 100% recall, successfully capturing every malicious log line in the test set.
- CERT: Demonstrated high precision (99.31%), effectively ignoring noise that typically triggers false positives in simpler models.
Sensitivity Analysis
The effectiveness of the model is sensitive to the weights assigned to the loss function components. For instance, the continuity weight ($\beta$) plays a vital role in ensuring the model captures bursts of anomalous activity rather than isolated, disconnected points.
Discussion and Future Work
CFDet demonstrates that explainable AI (XAI) can serve as a powerful tool for unsupervised fine-grained detection. By finding the "minimal change" to normalize a sequence, the model naturally identifies abnormal components without requiring expensive manual labeling.
However, the framework's performance is inherently capped by the initial sequence detector; if Phase 1 fails to flag a sequence, Phase 2 is never initiated. Additionally, the use of Reinforcement Learning introduces higher computational complexity compared to gradient-based attribution. Future research may explore incorporating causal structures to generate even more realistic counterfactuals and improving the efficiency of the policy gradient optimization.
Summary updated