# Visualization Assisted Approach to Anomaly and Attack Detection in Water Treatment Systems
## 5 Experiments and Discussion  
### Machine Learning Based Detection  
To detect attacks, machine learning modules contained in the Scikit-learn library and the Python programming language are used. When performing experiments on attack detection with data sets presenting states of the water treatment system, we used the following machine learning modules taken from the Scikit-learn library:  
* AdaBoost classifier (AdaBoostClassifier class);
* Random Forest classifier (RandomForestClassifier class);
* Bayesian classifier (MultinomialNB class);
* LogisticRegression classifier (LogisticRegression class);
* Linear classifier SVM (SGDClassifier class);
* DecisionTree (DecisionTreeClassifier class);
* Ridge Classifier (RidgeClassifier class). The data sets present records of the state of the water treatment system at a definite point in time, i.e., records of the states of the system's sensors and its actuators. Each of the samples may contain at least one attack, as described above. The following files were taken as input: \begin{table}
\begin{tabular}{c c c} \hline \hline
**Attack Class** & **Attack Name** & **Description** \\ \hline
2 & Attack aimed at falsification of the total size of water in the tanks & - the attack consists of an inconsistency between the indicators of the water level of one tank and the other. Since the system is closed, the total amount of water is unchanged, and this attack is also potentially realizable. By manipulating sensor readings, an attacker changes data on the total size of water, including physically withdrawing it. For example, in a normal state, if the first tank is 70\% full, the second one is 30\% full. In the event of an attack, the first and second ones can be equally filled by 30\%. Within the data set, this attack is marked by the classAttack label equal to 2 - the attack consists in replacing the sensor readings when the water level in the tanks does not change, and the controlled crane is closed (or the pump is turned off and the water flow sensor detects its overflow). The attack is relevant for both the flow sensor between tanks and the water flow sensor attached to the pump. Within the data set, this attack is marked by the classAttack label equal to 3 - the attack is similar to the previous class, but in this case, the readings are changed when the pump is turned on or the crane is open. The sensor shows the absence of water flow while, in fact, it is flowing. Within the data set, this attack is marked by the classAttack label equal to 4 - the attack consists in replacing the indicator of water flow between the tanks relative to the degree of opening of the controlled crane. If the crane is fully open and the water flow is weak (even if the tank is full, or vice versa), the valve is almost closed and the water flow is maximum. It is labeled by 5 in the classAttack field of the data set \\ \hline \hline \end{tabular}
\end{table} 
Table 2: _Cont._- 7200 records; normal
- 4200; attack
- 3000; attack class 1)
* 7200 records; normal
- 4200; attack
- 3000; attack class
* 7200 records; normal
- 4765; attack
- 2435; attack class
* 7200 records; normal
- 4200; attack
- 3000; attack class
* 7200 records; normal
- 6649; attack
- 551; attack class
* 7200 records; normal
- 2413; attack
- 4787; attack classes
- 1, 2, 3, 4, 5)  
The architecture of the used experimental framework for the classification of attacks is shown in Figure 5. All the samples of the data sets were divided into training and testing sets at ratios of 70% to 30%, respectively. The testing of the trained models was performed using a testing set, and the calculation of classification quality was fulfilled by accuracy and f1-score indicators. For the training phase, the columns containing record identifiers attack classes and attack indicators were excluded in order to avoid overfitting. The time feature was also eliminated because its strong correlation with the resulting variable was revealed.