# A Survey on Machine-Learning Based Security Design for Cyber-Physical Systems
## 4 ML-Based Cyber-Physical Attack Detection  
Due to the advances in communication and computing technologies, the management of a large-scale CPS has been enabled, where each CPS component (including massive physical systems), the communication networks, and the various CPS applications generate enormous amounts of data in each CPS layer of the hierarchical CPS structure proposed in Section 2. Because of the complexity of a large-scale CPS and the substantial amounts of data generated, ML techniques are adopted to detect cyber-physical attacks in order to overcome the detection limits of conventional, static, rule-based anomaly detection and misuse detection methods. In this section, we discuss ML-based cyber-physical attack detection strategies in each hierarchical CPS layer. An ML-based anomaly detector consists of two phases [97], the training phase and the anomaly detection phase, as shown in Figure 6. In the training phase, the ML-based detector first collects the various CPS data related to cyber-physical security on each CPS layer in normal and attacked environments. On the physical system layer, safety-critical data including massive amounts of sensor measurements from multiple physical systems, control input signals, and control period information can be collected to train the ML-model in the detector. At the network layer, a variety of packet and network environment information related to threats, as discussed in Section 3, can be collected, such as packet headers, network channel state information, SNR, packet drops, and mean round trip time between the computing system and the physical system. At the application layer, information on the computing system, which can damage system software and hardware, can be collected, including the utilization of the CPU and RAM, the files in storage, and the frequency of specific command execution. After data collection, the ML-based detector labels data regarding whether they are generated under legitimate or abnormal situations. Finally, the ML model is built with features and labels, where various ML classification models can be adopted, such as a neural network [98], Q-learning [99], random forest [100], and the support vector machine (SVM) [101]. In the anomaly detection phase, the ML-based detector classifies abnormal behavior in the CPS with well-trained ML models in the training phase for unknown CPS data. When abnormal data, such as packets maliciously modified by an attacker, are injected into the CPS, the ML model analyzes abnormal behavior from that data. If the ML model classifies the data as abnormal, then the ML-based detector alerts CPS users to the attack and handles it to guarantee the stability of the CPS. The performance of the ML-based detector is assessed with four metrics [102]: accuracy, precision, recall, and F1-score. * Accuracy is defined as the number of correctly classified cases for the entire test dataset, whih is calculated as follows: \[Accuracy=\frac{TP+TN}{TP+FP+TN+FN},\] (9) where \(TP\) is the number of correctly classified anomalies, \(TN\) is the number of samples correctly classified as normal, \(FP\) is the number of normal samples classified as anomalies, and \(FN\) is the number of anomalies wrongly classified as normal. * Precision is defined as true-positive detection from samples the detector has determined to be abnormal, and is calculated as follows: \[Precision=\frac{TP}{TP+FP}.\] (10) Precision is related to false-positive detection, which degrades the control performance of physical systems. * Recall is defined as detection performance with real anomalies, and is calculated as follows: \[Recall=\frac{TP}{TP+FN}.\] (11) Recall is related to misdetection probability, where a missed detection makes the physical system unstable.