An Explainable Markov Chain–Machine Learning Sequential-Aware Anomaly Detection Framework for Industrial IoT Systems Based on OPC UA
Abstract
1. Introduction
- How can stateless machine learning models be effectively transformed to incorporate the sequential dynamics inherent in industrial protocols?
- How can anomalies be detected that reside not in static values, but in the structure and temporality of transitions?
- (1)
- Model the OPC UA sequence using adaptive Markov chains.
- (2)
- Train several ML detectors (OCSVM, Isolation Forest, LOF, MLP) to capture various anomalies.
- (3)
- Integrate explainability and causal inference modules to attribute the impact of variables and reveal underlying dependencies.
- Hybrid framework design: We propose a unified anomaly detection framework that combines adaptive Markov chains, multiple machine learning detectors, and explainability modules to explicitly capture temporal dependencies in OPC UA traffic.
- Sequential-aware enhancement: We demonstrate how stateless models such as MLP and Isolation Forest can be enriched with Markov-based memory to improve both accuracy and robustness in detecting contextual anomalies.
- Explainability and causality integration: We incorporate SHAP analysis and causal inference graphs to provide multi-level interpretability, enabling better traceability and faster remediation in industrial environments.
- Comprehensive evaluation: We validate our approach on a realistic OPC UA dataset with industrial attack scenarios (MITM, DoS), showing significant gains in F1-score and interpretability when sequential memory is injected.
2. Related Work
2.1. ICS Anomaly Detection Using Machine Learning
- -
- Lack of temporal memory: context-limited models ignore long-term trends. This makes gradual attacks (e.g., slowly drifting sensors) or discrete message reordering invisible.
- -
- Vulnerability to fixed thresholds: ML models can be exploited by injecting low-level but structured noise, leading to misclassifications [42].
- -
- False positive/false negative trade-off: overly sensitive settings cause excessive alerts, while overly tolerant thresholds create a gray area that is conducive to stealth attacks [43].
- Does adding a Markovian memory score significantly improve anomaly detection by static models?
- Does a higher memory order enrich the quality of the information, or does it introduce harmful noise?
- Is there an identifiable causal link between memory order, Markov score, and the final decision of the ML model?
2.2. Explicability and Causality for ICS Cybersecurity
3. Methodologies
3.1. System Model
- Markov module: captures the probabilistic transitions between OPC UA session states (e.g., StartRawConnection → SecureChannel → Session → ReadRequest, etc.) by constructing Markov chains of variable order. This module detects unusual deviations in the temporal structure of the flows.
- ML detectors: a set of machine learning models operating on classic statistical characteristics of traffic (bytes, duration, frequency, etc.), with and without sequential memory.
- SHAP explanation: for each alert triggered, this module identifies the characteristics that contributed most to the detection, via the assignment of SHAP values.
- Causal analysis: estimates a graph of causal dependencies between the observed variables, making it possible to explain the mechanisms underlying the detected anomalies (e.g., propagation effects, abnormal dependencies).
3.2. Dataset OPC UA
3.3. Data Processing Procedure
- IP session: grouping of frames according to the source address (src_ip), simulating continuous interactions of the same automaton or sensor.
- TCP flow: segmentation based on session boundaries (flowStart, flowEnd) to reflect complete transactions.
- Time windowing: application of a sliding window to long sessions to capture recurring patterns localized in time.
- With order 1, each state is conditioned solely by the immediately preceding state.
- At order 4, the probability of the current state depends on the four previous states, thus incorporating a richer contextual history.
3.3.1. Derivation of Markov-Based Characteristics
- Log-likelihood evaluates the probability of the entire sequence according to the learned model [55]:
- Local conditional entropy measures the uncertainty about the next state given the current context:
- Anomaly score (or “surprise”): quantifies the local improbability of a transition:
3.3.2. Fusion of Classic and Sequential Features for Machine Learning
3.3.3. Class Imbalance
- Stratified subsampling of abnormal instances, to maintain a representative sample of the normal class.
- Weighting of the loss function for supervised models (MLP, LOF), expressed as [60]:
3.4. Data Preprocessing
- Static characteristics (instantaneous descriptors, global statistics).
- Sequential characteristics (Markov transition scores, surprise indices, conditional entropy), capturing the temporal and contextual dynamics of the monitored process.
3.4.1. Standardization of Numerical Variables
3.4.2. Encoding Categorical Variables (One-Hot Encoding)
3.4.3. Integration and Selection of Characteristics
- Variance filtering: application of a threshold via to eliminate columns with too low variance; retain only features such that .
- Imputation of missing values: each missing value is replaced by the median of the corresponding column:
- Normalization: to limit the influence of extreme values, normalization based on the median and interquartile range (IQR) is applied:
3.5. Detection Models and Theoretical Foundations
3.5.1. Learning Paradigms
- Unsupervised learning:
- Semi-supervised learning:
- Supervised learning:
3.5.2. Mathematical Foundations and Detailed Models
Isolation Forest
One-Class SVM
- It is trained solely on normal data, making it particularly suitable for contexts where anomalies are very rare.
- It is robust to noisy data if the parameter ν is well calibrated.
- It enables accurate detection of structural deviations even in large spaces.
Elliptic Envelope (Robust Covariance Estimation)
Multi-Layer Perceptron (MLP)
K-Nearest Neighbors (KNN)
- Calculates the distance between x and all instances in the training set (often the Euclidean distance),
- selects the closest neighbors ,
- assigns the majority class among these neighbors.
Random Forest
3.5.3. Decision and Evaluation
Binarization of the Anomaly Score
- Quantile method: selection of a threshold based on the empirical distribution of scores (e.g., 95th percentile).
- ROC curve optimization: selection of the threshold that maximizes the trade-off between TPR and FPR (e.g., Youden’s criterion).
Evaluation Metrics
- -
- TP (True positives): anomalies correctly detected,
- -
- FP (False positives): normal cases incorrectly reported as anomalies,
- -
- TN (True negatives): normal cases correctly detected,
- -
- FN (False negatives): undetected anomalies.
- -
- AUC-ROC: area under the ROC curve, which plots TPR vs. FPR for all thresholds
- -
- AUC-PR: area under the Precision-Recall curve, more suitable for unbalanced datasets.
3.6. Parsimony and Complexity: Akaike Information Criterion (AIC)
3.7. Training Protocols and Overfitting Control
Overfitting Control and Training/Validation Protocols:
- Isolation Forest—random subsampling, enough trees, calibration of the contamination rate by cross-validation, and selection of the model that minimizes inter-fold variance to limit overfitting and stabilize isolation scores.
- Random Forest—systematic use of out-of-bag error as an unbiased estimator of generalization, control of tree capacity, and maximum depth, adjusted by cross-validation [83].
- MLP—L2 regularization, dropout, and early stopping on validation, supplemented by Bayesian search for layer size hyperparameters, dropout rate, regularization coefficient, recognized practices to limit co-adaptation of neurons and stop training before validation loss drift.
- OCSVM—prior standardization and grid search of parameters ν, γ with RBF kernel, based on the margin/outlier rate compromise validated on ROC-AUC, which avoids an overly specialized boundary.
- LOF and k-NN—robust selection of k by cross-validation, distance weighting, and multi-k aggregation to reduce sensitivity to a single configuration, with the classic Cover–Hart results [84] motivating an increase in k to mitigate overfitting.
- Elliptic Envelope—robust estimation of mean/covariance via Minimum Covariance Determinant with choice of fraction , which limits the influence of extreme points and local overfitting.
3.8. Explicability
- Identification, for each anomaly score, of the explanatory share of sequential Markov features compared to standard variables.
- Comparison of the relative importance of different Markov memory orders within the decision process.
- Visualization of the actual influence of memory on the ML model’s decision.
3.9. Causal Structure Discovery
- Inputs: normalized data matrix, with the option to include anomaly labels as the target variable.
- is a conditioning subset,
- denotes conditional independence.
4. Results
4.1. Overall Results and Performance Evolution
- Random Forest and IF maintained excellent stability across all orders (low FP rate),
- OCSVM showed a significant decline in precision as early as order 1,
- MLP and KNN gained slightly in recall up to order 2, before declining thereafter.
- Figure 6 summarizes the overall results by showing the evolution of the F1-score according to the memory orders (from 0 to 4). It clearly shows:
- A moderate gain for MLP, KNN, and IF up to order 2 (+1–2.3%),
- stabilization or even a slight loss beyond that, indicating a memory saturation effect.
- A clear degradation for OCSVM, illustrating its poor adaptability to sequential structures.
- Decision Tree-Based Models:
- Random Forest (RF):
- Summary: Slight improvement of +0.4% in F1-score, followed by stabilization, and a minor decrease (<0.3%) beyond that.
- Isolation Forest (IF):
- Summary: Optimal gain of +0.25% in F1-score at orders 1–2, then a decline of ~1% due to overfitting (order 4).
- K-Nearest Neighbors (KNN):
- Summary: Moderate gain of +1.8% (order 2), then a loss of 1.6% (order 4).
- Multi-Layer Perceptron (MLP):
- Summary: Moderate gain of +0.31% (order 1), then stabilization at 0% (order 4).
- One-Class SVM (OCSVM):
- Summary: Continuous degradation of F1-score: −5 to −9% as soon as Markov memory is added. No beneficial effect
- Robust Covariance (RobustCov):
- Summary: No gain, loss of ~1.3% from order 1. Curves remain completely stable thereafter.
- LSTM and GRU
4.2. Comparative Analysis of the Akaike Information Criterion
- Multi-Layer Perceptron: The AIC score decreases significantly between order 0 (5088.2) and order 2 (4715.4), reflecting a clear improvement in the quality/complexity trade-off thanks to the addition of sequential memory. From order 3 onwards, the curve flattens (4743.8), indicating a plateau effect.
- Random Forest: The AIC follows a similar trend, reaching a minimum at order 2 (4138.5) from an initial score of 4262.4. This suggests that the model effectively benefits from short-term memory, without additional overhead beyond that point.
- Isolation Forest (IF): There is a steady decrease in AIC up to order 2 (4757.8), but improvements become negligible from order 3 onwards, showing moderate usefulness of temporal memory.
- K-Nearest Neighbors: A moderate improvement is visible up to order 2 (AIC = 5136.5), but the indicator then increases (5244.7 and then 5314.1), revealing potential overfitting from order 3 onward.
- One-Class SVM: By contrast, the AIC continues to rise markedly with the Markov order, from 5918.5 to 8524.8. This behavior highlights the inadequacy of this model for temporal dynamics, made worse by the induced complexity.
- Robust Covariance: No significant variation is observed, with a constant AIC around 8372 for all orders. This confirms that this model does not exploit sequential memory, being purely based on the static structure of the covariance matrix.
5. Explainability and Causality
5.1. Evolution of Explainability
5.2. Evolution of the Causal Structure According to Memory Order
6. Deployment in Edge-IIoT Environments
7. Discussions
8. Conclusions and Perspectives
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
Abbreviations
| Abbreviation | Meaning |
| SHAP | SHapley Additive exPlanations |
| PC | Peter–Clark (causal discovery algorithm) |
| MLP | Multi-Layer Perceptron |
| KNN | K-Nearest Neighbors |
| RF | Random Forest |
| IF | Isolation Forest |
| OCSVM | One-Class Support Vector Machine |
| LOF | Local Outlier Factor |
| RNN | Recurrent Neural Network |
| LSTM | Long Short-Term Memory |
| GRU | Gated Recurrent Unit |
| HMM | Hidden Markov Model |
| DAG | Directed Acyclic Graph |
| AIC | Akaike Information Criterion |
| ROC | Receiver Operating Characteristic |
| AUC | Area Under the Curve |
| PR | Precision-Recall |
| TP | True Positive |
| FP | False Positive |
| TN | True Negative |
| FN | False Negative |
| BCE | Binary Cross-Entropy |
| ReLU | Rectified Linear Unit |
| RBF | Radial Basis Function |
| OH | One-Hot (encoding) |
| IQR | Interquartile Range |
| RSS | Residual Sum of Squares |
| IR | Imbalance Ratio |
| SMOTE | Synthetic Minority Oversampling Technique |
| OOB | Out-of-Bag (error, for RF) |
| Surprisek | Markov “surprise” score |
References
- Ladegourdie, M.; Leclercq, E.; Amrani, M. Performance Analysis of OPC UA for Industrial Interoperability towards Industry 4.0. Informatics 2022, 3, 27. [Google Scholar] [CrossRef]
- Erba, A.; Müller, A.; Tippenhauer, N.O. Security Analysis of Vendor Implementations of the OPC UA Protocol for Industrial Control Systems. In Proceedings of the 4th ACM Workshop on Cyber-Physical System Security (CPSIoTSec), Los Angeles, CA, USA, 7 November 2022; pp. 1–13. [Google Scholar]
- Dahlmanns, M.; Lohmöller, J.; Fink, I.B.; Pennekamp, J.; Wehrle, K.; Henze, M. Easing the Conscience with OPC UA: An Internet-Wide Study on Insecure Deployments. In Proceedings of the ACM Internet Measurement Conference (IMC), Virtual Event, 27–29 October 2020; pp. 101–110. [Google Scholar]
- Zhukabayeva, T.; Zholshiyeva, L.; Karabayev, N.; Khan, S.; Alnazzawi, N. Cybersecurity Solutions for Industrial Internet of Things–Edge Computing Integration: Challenges, Threats, and Future Directions. Sensors 2025, 25, 213. [Google Scholar] [CrossRef]
- Mahadevappa, P.; Al-amri, R.; Alkawsi, G.; Alkahtani, A.A.; Alghenaim, M.F.; Alsamman, M. Analyzing Threats and Attacks in Edge Data Analytics within IoT Environments. IoT 2024, 5, 7. [Google Scholar] [CrossRef]
- Yaben, R.; Vasilomanolakis, E. Drifting Away: A Cyber-Security Study of Internet-Exposed OPC UA Servers. In Proceeding of the 10th International Workshop on Traffic Measurements for Cybersecurity, Venice, Italy, 30 June 2025. [Google Scholar]
- Diemunsch, V.; Domínguez, H.; Goubault, E.; Paulin, S. A Comprehensive Formal Security Analysis of OPC UA. In Proceedings of the USENIX Security Symposium, Seattle, WA, USA, 13–15 August 2025. [Google Scholar]
- Ahmed, C.M.; Palleti, V.R.; Mathur, A.P. WADI: A water distribution testbed for research in the design of secure cyber-physical systems. In Proceedings of the 3rd International Workshop on Cyber-Physical Systems for Smart Water Networks (CySWATER ’17), Pittsburgh, PA, USA, 21 April 2017; Association for Computing Machinery: New York, NY, USA, 2017; pp. 25–28. [Google Scholar] [CrossRef]
- Mathur, A.; Tippenhauer, N.O. SWaT: A Water Treatment Testbed for Research and Training on ICS Security. In Proceedings of the International Workshop on Cyber-Physical Systems for Smart Water Networks (CySWater), Vienna, Austria, 11 April 2016; pp. 31–36. [Google Scholar] [CrossRef]
- Taormina, R.; Galelli, S.; Tippenhauer, N.O.; Park, D.J.; Ostfeld, A.; Eliades, D.G.; Aghashahi, M.; Sundararajan, R.; Pourahmadi, M.; Banks, M.K.; et al. Batadal: Battle of the attack detection algorithms on water distribution systems. J. Water Resour. Plan. Manag. 2018, 144, 04018065. [Google Scholar] [CrossRef]
- Schölkopf, B.; Platt, J.C.; Shawe-Taylor, J.; Smola, A.J.; Williamson, R.C. Estimating the Support of a High-Dimensional Distribution. Neural Comput. 2001, 13, 1443–1471. [Google Scholar] [CrossRef] [PubMed]
- Zhou, C.; Paffenroth, R.C. Anomaly Detection with Robust Deep Autoencoders. In Proceedings of the 23rd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD 2017), Halifax, NS, Canada, 13–17 August 2017; pp. 665–674. [Google Scholar] [CrossRef]
- Kravchik, M.; Shabtai, A. Detecting Cyberattacks in Industrial Control Systems Using Convolutional Neural Networks. arXiv 2018, arXiv:1806.01554. [Google Scholar] [CrossRef]
- Kim, J.; Yun, J.-H.; Kim, H.C. Anomaly Detection for Industrial Control Systems Using Sequence-to-Sequence Neural Networks. In Proceedings of the Computer Security—ESORICS 2019, Luxembourg, 26–27 September 2020; pp. 3–18. [Google Scholar] [CrossRef]
- Sukhostat, L. Anomaly Detection in Industrial Control System Based on Hierarchical Hidden Markov Model. In Cybersecurity for Critical Infrastructure Protection via Reflection of Industrial Control Systems; IOS Press: Amsterdam, The Netherlands, 2022; pp. 48–55. [Google Scholar] [CrossRef]
- Smith, T.; Garcia, M. Unsupervised Anomaly Detection via Markov Depth Analysis. arXiv 2024, arXiv:2406.16759. [Google Scholar]
- Shanmuganathan, V.; Suresh, A. LSTM-Markov based efficient anomaly detection algorithm for IoT environment. Appl. Soft Comput. 2023, 136, 110054. [Google Scholar] [CrossRef]
- Kravchik, M.; Shabtai, A. Detecting Cyber Attacks in Industrial Control Systems Using Markov Models. In Proceedings of the 2018 Workshop on Cyber-Physical Systems Security and PrivaCy (CPS-SPC ’18), Toronto, ON, Canada, 15–19 October 2018; pp. 1–12. [Google Scholar] [CrossRef]
- Hundman, K.; Constantinou, V.; Laporte, C.; Colwell, I.; Soderstrom, T. Detecting Spacecraft Anomalies Using LSTMs and Nonparametric Dynamic Thresholding. In Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, London, UK, 19–23 August 2018. [Google Scholar]
- Wu, Y.; Dai, H.-N.; Tang, H. Graph neural networks for anomaly detection in industrial internet of things. IEEE Internet Things J. 2022, 9, 9214–9231. [Google Scholar] [CrossRef]
- Han, C.; Gim, G. Time-Series-Based Anomaly Detection in Industrial Control Systems Using Generative Adversarial Networks. Processes 2025, 13, 2885. [Google Scholar] [CrossRef]
- Wu, Z.; Zhu, L.; Yin, Z.; Xu, X.; Zhu, J.; Wei, X.; Yang, X. MAFCD: Multi-Level and Adaptive Conditional Diffusion Model for Anomaly Detection. Inf. Fusion 2025, 118, 102965. [Google Scholar] [CrossRef]
- Birihanu, E.; Lendák, I. Explainable correlation-based anomaly detection for industrial control systems and root cause investigation (LSTM-AE + SHAP). Front. Artif. Intell. 2024, 7, 150882. [Google Scholar] [CrossRef]
- Liu, J.; Sha, Y.; Zhang, W.; Yan, Y.; Liu, X. Anomaly Detection for Industrial Control System Operation Data Based on Time–Frequency Fusion Feature Attention Encoding. Sensors 2024, 24, 6131. [Google Scholar] [CrossRef]
- Smith, J.; Kumar, P.; Luo, Y. Unsupervised Learning Approaches for Anomaly Detection in IIoT. J. Ind. Inf. Integr. 2024, 26, 100452. [Google Scholar]
- Abdelfattah, M.S.; Ren, J.; El-Khamy, M. Accelerating Deep Neural Networks on Edge Devices. IEEE Trans. Neural Netw. Learn. Syst. 2022, 33, 2749–2761. [Google Scholar]
- Somma, M. Hybrid Temporal Differential Consistency Autoencoder for Efficient and Sustainable Anomaly Detection in Cyber-Physical Systems. arXiv 2025, arXiv:2504.06320. [Google Scholar] [CrossRef]
- Koay, A.M.Y.; Mo, Q.; Lim, A.; Potter, R.; Chia, Y.; Gour, M.; Tong, D. Machine Learning in Industrial Control System Security: Challenges, pitfalls and perceptions. J. Intell. Inf. Syst. 2023, 60, 377–405. [Google Scholar] [CrossRef]
- Fan, Y.; Fu, T.; Listopad, N.I.; Liu, P.; Garg, S.; Hassan, M.M. Utilizing correlation in space and time: Anomaly detection for industrial internet of things (IIoT) via spatiotemporal gated graph attention network. Alex. Eng. J. 2024, 106, 560–570. [Google Scholar] [CrossRef]
- Tian, J.; Li, M.; Chen, L.; Wang, Z. iADCPS: Time Series Anomaly Detection for Evolving Cyber-Physical Systems via Incremental Meta-Learning. arXiv 2025, arXiv:2504.04374. [Google Scholar]
- Abdelaty, M.; Doriguzzi-Corin, R.; Siracusa, D. DAICS: A deep learning solution for anomaly detection in industrial control systems. IEEE Trans. Emerg. Top. Comput. 2022, 10, 1117–1129. [Google Scholar] [CrossRef]
- Kwon, H.-Y.; Kim, T.; Lee, M.-K. Advanced Intrusion Detection Combining Signature-Based and Behavior-Based Detection Methods. Electronics 2022, 11, 867. [Google Scholar] [CrossRef]
- Goetz, C.; Humm, B. A Hybrid and Modular Integration Concept for Anomaly Detection in Industrial Control Systems. AI 2025, 6, 91. [Google Scholar] [CrossRef]
- Bahadoripour, S.; MacDonald, E.; Karimipour, H. A Deep Multi-Modal Cyber-Attack Detection in Industrial Control Systems. arXiv 2023, arXiv:2304.01440. [Google Scholar]
- Gao, C.; Rios-Navarro, A.; Chen, X.; Liu, S.-C.; Delbrück, T. EdgeDRNN: Enabling Low-Latency Recurrent Neural Network Edge Inference. arXiv 2019, arXiv:1912.12193. [Google Scholar]
- ArunKumar, K.E.; Kalaga, D.V.; Mohan Sai Kumar, C.; Kawaji, M.; Brenza, T.M. Comparative analysis of Gated Recurrent Units (GRU), long Short-Term memory (LSTM) cells, autoregressive Integrated moving average (ARIMA), seasonal autoregressive Integrated moving average (SARIMA) for forecasting COVID-19 trends. Alex. Eng. J. 2022, 61, 7585–7603. [Google Scholar] [CrossRef]
- Macas, M.; Wu, C.; Fuertes, W. An Attention-Based Deep Generative Model for Anomaly Detection in Industrial Control Systems. arXiv 2024, arXiv:2405.05277. [Google Scholar]
- Mouradian, C.; Barthelemy, J.; Auge, J.; Desprez, F. A Comprehensive Survey on Fog Computing: State-of-the-art and research challenges. IEEE Commun. Surv. Tutor. 2018, 20, 416–464. [Google Scholar] [CrossRef]
- Shi, T.; Shide, K. A comparative analysis of LSTM, GRU, and Transformer models for construction cost prediction with multidimensional feature integration. J. Asian Archit. Build. Eng. 2025, 1–16. [Google Scholar] [CrossRef]
- Cahuantzi, R.; Chen, T.; Güttel, S.A. Comparison of LSTM and GRU Networks for Learning Symbolic Sequences. arXiv 2021, arXiv:2107.02248. [Google Scholar]
- Yunita, A.; Pratama, M.I.; Almuzakki, M.Z.; Ramadhan, H.; Akhir, E.A.P.; Mansur, A.B.F.; Basori, A.H. Performance analysis of neural network architectures for time series forecasting: A comparative study of RNN, LSTM, GRU, and hybrid models. MethodsX 2025, 15, 103462. [Google Scholar] [CrossRef]
- Albassam, H.; Xiao, J.; An, Z.; Islam, S. Multi-Feature Hybrid Anomaly Detection in ICS: Mitigating False Positives via Dynamic Thresholds; ACM: New York, NY, USA, 2025. [Google Scholar]
- Mijalkovic, J. Reducing the False Negative Rate in Deep Learning-Based Network Intrusion Detection. Algorithms 2022, 15, 258. [Google Scholar] [CrossRef]
- Tang, S.; Ding, Y.; Wang, H. An Interpretable Method for Anomaly Detection in Multivariate Time Series Predictions. Appl. Sci. 2025, 15, 7479. [Google Scholar] [CrossRef]
- Franco de la Peña, M.; Perales, Á.L.; Fernández, L. ShaTS: A Shapley-Based Explainability Method for Time Series Models Applied to IIoT Anomaly Detection. arXiv 2025, arXiv:2506.01450. [Google Scholar]
- Li, Z.; Zhu, Y.; van Leeuwen, M. A Survey on Explainable Anomaly Detection. arXiv 2022, arXiv:2210.06959. [Google Scholar] [CrossRef]
- Yang, W.; Zhang, K.; Hoi, S.C. A Causal Approach to Detecting Multivariate Time-series Anomalies and Root Causes. arXiv 2022, arXiv:2206.15033. [Google Scholar] [CrossRef]
- Le, T.D.; Hoang, T.; Li, J.; Liu, L.; Liu, H.; Hu, S. A Fast PC Algorithm for High Dimensional Causal Discovery with Multi-Core PCs. arXiv 2015, arXiv:1502.02454. [Google Scholar] [CrossRef]
- Maiti, R.; Adepu, S.; Lupu, E.C. ICCPS: Impact Discovery Using Causal Inference for Cyberattacks in Cyber-Physical Systems. arXiv 2023, arXiv:2307.14161. [Google Scholar]
- Jadidi, Z.; Hagemann, J.; Quevedo, D. Multi-Step Attack Detection in Industrial Control Systems Using Causal Analysis. Comput. Ind. 2022, 139, 103741. [Google Scholar] [CrossRef]
- Pinto, R.; Vazquez, C.; Pires, M.; Almeida, J.; Vidal, T. M2M using OPC UA Dataset: OPC UA Traffic in a CPPS Testbed Including Normal Behavior and Attacks (DoS, MITM, Spoofing). IEEE DataPort. Available online: https://ieee-dataport.org/open-access/m2m-using-opc-ua (accessed on 19 September 2025).
- ESET Research. Industroyer2: Industroyer Reloaded. ESET. 2022. Available online: https://www.welivesecurity.com/2022/04/12/industroyer2-industroyer-reloaded/ (accessed on 19 September 2025).
- Dragos Inc. CHERNOVITE’s PIPEDREAM Malware Targeting Industrial Control Systems (ICS); Dragos Threat Intelligence Report; Dragos Inc.: Hanover, MD, USA, 2022. [Google Scholar]
- Norris, J.R. Markov Chains; Cambridge University Press: Cambridge, UK, 1998. [Google Scholar]
- Ren, H.; An, J.; Chen, M.; Yang, Z.; Lv, J.; Wang, W. Anomaly Detection Based on a Dynamic Markov Model. Entropy 2017, 19, 541. [Google Scholar] [CrossRef] [PubMed]
- Xu, J.; Wu, H.; Wang, J.; Long, M. Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy. arXiv 2021, arXiv:2110.02642. [Google Scholar]
- Chawla, N.V.; Bowyer, K.W.; Hall, L.O.; Kegelmeyer, W.P. SMOTE: Synthetic Minority Over-sampling Technique. J. Artif. Intell. Res. 2002, 16, 321–357. [Google Scholar] [CrossRef]
- Japkowicz, N. The Class Imbalance Problem: Significance and Strategies. In Proceedings of the International Conference on Artificial Intelligence (ICAI), Las Vegas, NV, USA, 26–29 June 2000; pp. 111–117. [Google Scholar]
- King, G.I.; Zeng, L. Logistic Regression in Rare Events Data. Political Anal. 2001, 9, 137–163. [Google Scholar] [CrossRef]
- Kingma, D.P.; Ba, J. Adam: A Method for Stochastic Optimization. In Proceedings of the 3rd International Conference on Learning Representations (ICLR), San Diego, CA, USA, 7–9 May 2015. [Google Scholar]
- Bishop, C.M. Pattern Recognition and Machine Learning; Springer: New York, NY, USA, 2006. [Google Scholar]
- Phan, T.H.; Yamamoto, K. Resolving Class Imbalance in Detection Models with Weighted Cross-Entropy Losses. arXiv 2020, arXiv:2006.01413. [Google Scholar]
- Zhou, Z.; Chen, X.; Li, E.; Zeng, L.; Luo, K.; Zhang, J. Edge intelligence: Paving the last mile of artificial intelligence with edge computing. Proc. IEEE 2019, 107, 1738–1762. [Google Scholar] [CrossRef]
- Liu, F.T.; Ting, K.M.; Zhou, Z.H. Isolation Forest. In Proceedings of the 2008 Eighth IEEE International Conference on Data Mining (ICDM), Pisa, Italy, 15–19 December 2008; pp. 413–422. [Google Scholar]
- Breiman, L. Random Forests. Mach. Learn. 2001, 45, 5–32. [Google Scholar] [CrossRef]
- Salehinejad, H.; Sankar, S.; Barfett, J.; Colak, E.; Valaee, S. Recent advances in recurrent neural networks. arXiv 2018, arXiv:1801.01078. [Google Scholar] [CrossRef]
- Diana, L.; Dini, P.; Paolini, D. Overview on Intrusion Detection Systems for Computers Networking Security. Computers 2025, 14, 87. [Google Scholar] [CrossRef]
- Kravchik, M.; Biggio, B.; Shabtai, A. Poisoning attacks on cyber attack detectors for industrial control systems. arXiv 2020, arXiv:2012.15740. [Google Scholar] [CrossRef]
- Shao, C.; Du, X.; Yu, J.; Chen, J. Cluster-based improved isolation forest. Entropy 2022, 24, 611. [Google Scholar] [CrossRef] [PubMed]
- Powers, D.M.W. Evaluation: From precision, recall and F-measure to ROC, informedness, markedness and correlation. arXiv 2011, arXiv:2010.16061. [Google Scholar] [CrossRef]
- Tax, D.M.J.; Duin, R.P.W. Support Vector Data Description. Mach. Learn. 2004, 54, 45–66. [Google Scholar] [CrossRef]
- Rousseeuw, P.J.; Van Driessen, K. A Fast Algorithm for the Minimum Covariance Determinant Estimator. Technometrics 1999, 41, 212–223. [Google Scholar] [CrossRef]
- Goodfellow, I.; Bengio, Y.; Courville, A. Deep Learning; MIT Press: Cambridge, MA, USA, 2016. [Google Scholar]
- Witten, I.H.; Frank, E.; Hall, M.A.; Pal, C.J. Data Mining: Practical Machine Learning Tools and Techniques, 4th ed.; 1515; Morgan Kaufmann: Burlington, MA, USA, 2016. [Google Scholar]
- Cover, T.; Hart, P. Nearest Neighbor Pattern Classification. IEEE Trans. Inf. Theory 1967, 13, 21–27. [Google Scholar] [CrossRef]
- Cutler, D.R.; Edwards, T.C., Jr.; Beard, K.H.; Cutler, A.; Hess, K.T.; Gibson, J.; Lawler, J.J. Random Forests for Classification in Ecology. Ecology 2007, 88, 2783–2792. [Google Scholar] [CrossRef]
- Gulzar, Q.; Mustafa, K. Interdisciplinary Framework for Cyber-Attacks and Anomaly Detection in ICS Using Attention-Driven Deep RNN, LSTM and Bi-LSTM. Sci. Rep. 2025, 15, 5473. [Google Scholar] [CrossRef]
- Saito, T.; Rehmsmeier, M. The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets. PLoS ONE 2015, 10, e0118432. [Google Scholar] [CrossRef]
- Chicco, D.; Jurman, G. The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation. BMC Genom. 2020, 21, 6. [Google Scholar] [CrossRef]
- Akaike, H. A New Look at the Statistical Model Identification. IEEE Trans. Autom. Control 1974, 19, 716–723. [Google Scholar] [CrossRef]
- Kohavi, R. A Study of Cross-Validation and Bootstrap for Accuracy Estimation and Model Selection. In Proceedings of the 14th International Joint Conference on Artificial Intelligence (IJCAI), Montreal, QC, Canada, 20–25 August 1995; Volume 2, pp. 1137–1143. [Google Scholar]
- Pearl, J. Causality: Models, Reasoning and Inference, 2nd ed.; Cambridge University Press: Cambridge, UK, 2009. [Google Scholar]
- Onnx, “Sklearn-Onnx: Convert Scikit-Learn Models and Pipelines to ONNX,” GitHub Repository. 2025. Available online: https://github.com/onnx/sklearn-onnx (accessed on 21 August 2025).
- Altman, N.S. An Introduction to k-Nearest Neighbors for Statistical Pattern Recognition; The American Statistician: Alexandria, VA, USA, 1992. [Google Scholar]
- Antwarg, L.; Miller, R.; Shapira, B.; Rokach, L. Explaining Anomalies Detected by Autoencoders Using SHAP. Expert Syst. Appl. 2021, 186, 115736. [Google Scholar] [CrossRef]
- Spirtes, P.; Glymour, C. An Algorithm for Fast Recovery of Sparse Causal Graphs. Soc. Sci. Comput. Rev. 1991, 9, 62–72. [Google Scholar] [CrossRef]
- Raspberry Pi Foundation. Raspberry Pi 4 Model B Product Brief; Raspberry Pi (Trading) Ltd.: Cambridge, UK, 2020; Available online: https://datasheets.raspberrypi.com/rpi4/raspberry-pi-4-product-brief.pdf (accessed on 21 September 2025).
- Xu, X.; Zhang, X.; Gao, H.; Xue, Y.; Qi, L.; Dou, W. BeCome: Blockchain-Enabled Computation Offloading for IoT in Mobile Edge Computing. IEEE Trans. Ind. Inform. 2020, 16, 4187–4195. [Google Scholar] [CrossRef]
- Pedregosa, F.; Varoquaux, G.; Gramfort, A.; Michel, V.; Thirion, B.; Grisel, O.; Blondel, M.; Prettenhofer, P.; Weiss, R.; Dubourg, V.; et al. Scikit-learn: Machine learning in Python. J. Mach. Learn. Res. 2011, 12, 2825–2830. Available online: https://www.jmlr.org/papers/v12/pedregosa11a.html (accessed on 21 September 2025).
- Dehlaghi-Ghadim, A.; Helali Moghadam, M.; Balador, A.; Hansson, H. Anomaly detection dataset for industrial control systems. arXiv 2023, arXiv:2305.09678. [Google Scholar] [CrossRef]
- Chen, R.; Zhang, T.; Wang, S. TREELITE: A Model Compiler for Efficient Deployment of Decision Tree Ensembles. In Proceedings of the 2nd SysML Conference, Palo Alto, CA, USA, 31 January–2 February 2019. [Google Scholar]
- Shokhanda, J.; Pal, U.; Kumar, A.; Chattopadhyay, S.; Bhattacharya, A. SafeTail: Efficient tail latency optimization in edge service scheduling via computational redundancy management. arXiv 2024, arXiv:2408.17171. [Google Scholar] [CrossRef]
- Halfacree, G. Raspberry Pi 4 Benchmarks: The New Single-Board Computer Delivers a Big Performance Boost. MagPi Magazine. 2019. Available online: https://magazine.raspberrypi.com/articles/raspberry-pi-4-specs-benchmarks (accessed on 19 September 2025).
- Rabiner, L.R. A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. Proc. IEEE 1989, 77, 257–286. [Google Scholar] [CrossRef]
- Asres, M.W.; Omlin, C.W. Scalable Temporal Anomaly Causality Discovery in Large Systems. arXiv 2024, arXiv:2412.11800. [Google Scholar] [CrossRef]
- Profanter, S.; Tekat, A.; Dorofeev, K.; Rickert, M.; Knoll, A. OPC UA versus ROS, DDS, and MQTT: Performance evaluation of industry 4.0 protocols. In Proceedings of the IEEE International Conference on Industrial Technology (ICIT 2019), Melbourne, Australia, 13–15 February 2019; IEEE: Piscataway, NJ, USA, 2019; pp. 955–962. [Google Scholar] [CrossRef]
- Rocha, M.S.; Sestito, G.S.; Dias, A.L.; Turcato, A.C.; Brandão, D. Performance comparison between OPC UA and MQTT for data exchange. In Proceedings of the Workshop on Metrology for Industry 4.0 and IoT, Brescia, Italy, 16–18 April 2018; pp. 175–179. Available online: https://api.semanticscholar.org/CorpusID:51980864 (accessed on 21 September 2025).
- Liang, F.; Yu, W.; Liu, X.; Griffith, D.; Golmie, N. Toward edge-based deep learning in industrial internet of things. IEEE Internet Things J. 2020, 7, 4329–4341. [Google Scholar] [CrossRef] [PubMed]
- Chandola, V.; Banerjee, A.; Kumar, V. Anomaly detection: A survey. ACM Comput. Surv. 2009, 41, 1–58. [Google Scholar] [CrossRef]
- Zong, B.; Song, Q.; Min, M.R.; Cheng, W.; Lumezanu, C.; Cho, D.; Chen, H. Deep Autoencoding Gaussian Mixture Model for Unsupervised Anomaly Detection. In Proceedings of the International Conference on Learning Representations, Vancouver, BC, Canada, 30 April–3 May 2018. [Google Scholar]
- Chen, T.; Moreau, T.; Jiang, Z.; Zheng, L.; Yan, E.; Shen, H.; Cowan, M.; Wang, L.; Hu, Y.; Ceze, L.; et al. TVM: An automated end-to-end optimizing compiler for deep learning. In Proceedings of the 13th USENIX Symposium on Operating Systems Design and Implementation (OSDI ’18), Carlsbad, CA, USA, 8–10 October 2018; USENIX Association: Berkeley, CA, USA, 2018; pp. 578–594. [Google Scholar]
- Kour, R.; Sood, S.; Kumar, B.; Singh, A.; Shrivastava, R. Cybersecurity for Industry 5.0: Trends and Gaps. Front. Comput. Sci. 2024, 2, 1434436. [Google Scholar] [CrossRef]
















| Throughput/Load | Timing/Duration | Business Ratios | Errors/Message Sizes |
|---|---|---|---|
| - pktTotalCount - octetTotalCount - avg_ps - f_rate - b_pktTotalCount - f_pktTotalCount | - flowDuration - flowInterval - avg_flowDuration - f_flowStart - b_flowStart | - same_srv_rate - dst_host_same_src_port_rate - count, srv_count | - msg_size - min_msg_size - service_errors - status_errors |
| Markov Order | F1-Score | Precision | Rappel | Difference F1 (%) vs. Order 0 |
|---|---|---|---|---|
| 0 | 0.964 | 0.976 | 0.953 | 0% |
| 1 | 0.967 | 0.974 | 0.959 | +0.4 |
| 2 | 0.966 | 0.973 | 0.960 | +0.2% |
| 3 | 0.965 | 0.971 | 0.959 | +0.1% |
| 4 | 0.964 | 0.970 | 0.958 | 0% |
| Markov Order | F1-Score | Precision | Rappel | Difference F1 (%) vs. Order 0 |
|---|---|---|---|---|
| 0 | 0.912 | 0.967 | 0.864 | 0% |
| 1 | 0.915 | 0.961 | 0.873 | +0.25% |
| 2 | 0.914 | 0.958 | 0.874 | +0.18% |
| 3 | 0.909 | 0.948 | 0.874 | −0.36% |
| 4 | 0.905 | 0.942 | 0.871 | −0.8% |
| Markov Order | F1-Score | Precision | Rappel | Difference F1 (%) vs. Order 0 |
|---|---|---|---|---|
| 0 | 0.879 | 0.948 | 0.819 | 0% |
| 1 | 0.894 | 0.944 | 0.849 | +1.7% |
| 2 | 0.895 | 0.938 | 0.855 | +1.8% |
| 3 | 0.887 | 0.931 | 0.846 | +0.9% |
| 4 | 0.880 | 0.928 | 0.834 | +0.1% |
| Markov Order | F1-Score | Precision | Rappel | Difference F1 (%) vs. Order 0 |
|---|---|---|---|---|
| 0 | 0.964 | 0.9756 | 0.953 | 0% |
| 1 | 0.967 | 0.9743 | 0.959 | +0.31% |
| 2 | 0.966 | 0.9728 | 0.960 | +0.21% |
| 3 | 0.965 | 0.9713 | 0.959 | +0.10% |
| 4 | 0.964 | 0.9698 | 0.958 | 0% |
| Order Markov | F1-Score | Precision | Rappel | Difference F1 (%) vs. Order 0 |
|---|---|---|---|---|
| 0 | 0.876 | 0.961 | 0.804 | 0% |
| 1 | 0.826 | 0.926 | 0.745 | −5.7% |
| 2 | 0.815 | 0.918 | 0.733 | −7.0% |
| 3 | 0.806 | 0.910 | 0.724 | −8.0% |
| 4 | 0.799 | 0.906 | 0.715 | −8.8% |
| Markov Order | F1-Score | Precision | Rappel | Difference F1 (%) vs. Order 0 |
|---|---|---|---|---|
| 0 | 0.713 | 0.889 | 0.596 | 0% |
| 1 | 0.708 | 0.879 | 0.587 | −1.3% |
| 2 | 0.704 | 0.879 | 0.585 | −1.6% |
| 3 | 0.702 | 0.874 | 0.582 | −1.6% |
| 4 | 0.704 | 0.872 | 0.580 | −1.8% |
| Model | F1-Score | Precision | Rappel | RAM (MB) |
|---|---|---|---|---|
| LSTM | 0.972 | 0.965 | 0.980 | 883 |
| GRU | 0.970 | 0.963 | 0.978 | 864 |
| MLP + Markov-2 | 0.966 | 0.972 | 0.960 | ≈312 |
| Features | % SHAP > 0 | Mean | Standard Deviation |
|---|---|---|---|
| pktTotalCount | 61.0% | −0.02 | 2.25 |
| octetTotalCount | 58.0% | 0.01 | 0.90 |
| log_byte_rate | 57.2% | −0.01 | 0.92 |
| log_packet_rate | 54.8% | 0.007 | 0.70 |
| flowDuration | 54.6% | 0.01 | 1.02 |
| packet_rate | 54.2% | 0.018 | 1.22 |
| byte_rate | 51.22% | −0.01 | 1.73 |
| count | 51.2% | −0.012 | 1.43 |
| Features | % SHAP > 0 | Mean | Standard Deviation |
|---|---|---|---|
| octetTotalCount | 65.0% | −0.05 | 4.40 |
| pktTotalCount | 64.8% | 0.01 | 2.54 |
| markov_score_order1 | 60.2% | −0.01 | 1.81 |
| flowDuration | 58.8% | 0.02 | 2.01 |
| log_packet_rate | 58.6% | 0.02 | 2.36 |
| byte_rate | 58.4% | −0.04 | 4.00 |
| log_byte_rate | 58.0% | −0.01 | 3.00 |
| packet_rate | 57.6% | −0.02 | 1.53 |
| Features | % SHAP > 0 | Mean | Standard Deviation |
|---|---|---|---|
| octetTotalCount | 66.8% | 0.03 | 2.51 |
| pktTotalCount | 64.2% | −0.06 | 4.74 |
| log_byte_rate | 59.2% | −0.01 | 3.58 |
| markov_score_order2 | 59.0% | 0.02 | 3.31 |
| log_packet_rate | 58.8% | 0.03 | 2.89 |
| flowDuration | 58.6% | −0.04 | 4.24 |
| byte_rate | 58.4% | −0.01 | 2.01 |
| packet_rate | 57.6% | −0.02 | 1.74 |
| Model | Order | F1_Off | F1_Edge | ΔF1 | p95 Py (ms) | p95 ONNX (ms) | Flops |
|---|---|---|---|---|---|---|---|
| MLP | 0 | 0.964 | 0.959 | −0.005 | 1.02 | 0.54 | 11.12 k |
| MLP | 2 | 0.966 | 0.962 | −0.004 | 1.49–1.98 | 0.93–1.51 | 11.43 k |
| RF | 0 | 0.961 | 0.959 | −0.002 | 1.51–2.03 | 1.04–1.50 | 3 k comparisons |
| RF | 2 | 0.963 | 0.961 | −0.002 | 3.61–3.92 | 2.5–2.90 | 3 k comparisons |
| IF | 0 | 0.912 | 0.909 | −0.003 | 4.03–5.08 | 3.09–3.48 | 1 k comparisons |
| Ref | Approach | Sequentially | Latency/Resources | Edge Applicability |
|---|---|---|---|---|
| [14] | Autoencoder | ++ | – | – |
| [34,35] | LSTM/GRU | ++ | – | – |
| [64] | Isolation Forest | – | + | ++ |
| [65] | Random Forest | – | ± | + |
| [73] | MLP | – | + | ++ |
| Our approach | Markov–ML | ) | + | ++ |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Ghazi, Y.; Tabaa, M.; Ennaji, M.; Zaz, G. An Explainable Markov Chain–Machine Learning Sequential-Aware Anomaly Detection Framework for Industrial IoT Systems Based on OPC UA. Sensors 2025, 25, 6122. https://doi.org/10.3390/s25196122
Ghazi Y, Tabaa M, Ennaji M, Zaz G. An Explainable Markov Chain–Machine Learning Sequential-Aware Anomaly Detection Framework for Industrial IoT Systems Based on OPC UA. Sensors. 2025; 25(19):6122. https://doi.org/10.3390/s25196122
Chicago/Turabian StyleGhazi, Youness, Mohamed Tabaa, Mohamed Ennaji, and Ghita Zaz. 2025. "An Explainable Markov Chain–Machine Learning Sequential-Aware Anomaly Detection Framework for Industrial IoT Systems Based on OPC UA" Sensors 25, no. 19: 6122. https://doi.org/10.3390/s25196122
APA StyleGhazi, Y., Tabaa, M., Ennaji, M., & Zaz, G. (2025). An Explainable Markov Chain–Machine Learning Sequential-Aware Anomaly Detection Framework for Industrial IoT Systems Based on OPC UA. Sensors, 25(19), 6122. https://doi.org/10.3390/s25196122

