## 4 Man-in-the-Middle (MITM) Attacks
### Federating Learning to Mitigate MITM Attacks: An IoT Case
Subsequently, the revised global model parameters are sent back to the _distribution substation_ for subsequent training iterations (see Figure 2). The inherent design of FedAvg aligns well to mitigate cybersecurity risks, like MITM attacks. The dataset used in this work is the State Grid Corporation of China (SGCC) ([[https://github.com/henryRDlab/ElectricityTheftDetection](https://github.com/henryRDlab/ElectricityTheftDetection)]([https://github.com/henryRDlab/ElectricityTheftDetection](https://github.com/henryRDlab/ElectricityTheftDetection)), accessed on 28 December 2023) which comprises real-time EC records of 42,372 residential consumers with 10 times more honest data points than theft (see Table 4 for details). The dataset is first pre-processed using linear interpolation as an imputation method to replace the missing values. Next, the three-sigma rule method is used to identify and remove outliers (see clean data in Table 4). To address the data imbalance issue in the training dataset, we implement a hybrid approach, combining undersampling and oversampling techniques using the synthetic minority oversampling technique (SMOTE); see [2] for more details. Similar to [2], an energy-aware approach for model training and ETD evaluation is adopted in this work, which estimates the actual monetary loss due to (1) undetected theft and (2) honest users falsely classified as dishonest. In addition, this work proposes an FL-CNN system to mitigate the risk of data leakage in the centralised system in [2]. We assume that _C distribution substations_ are deployed, where each carries \(E\) epochs of learning during which the adaptive moment estimation (Adam) is used in the training phase with a learning ratio of 0.001 \(\lambda\). At the end of the training epochs, the model weights are communicated to the FS in what is referred to as a communication round. At each communication round, given \(r_{i}\) for \(i=\{1\dots R\}\) (where \(R\) is the maximum number of rounds), the local model weights \(\theta_{m}^{i}\) of _distribution substation_\(m\) are forwarded to the FS, which then calculates the averaged weights (based on FedAvg) \(\theta_{m}^{i}\) and pushes these back to the clients. This process repeats until the convergence of the global model, which is \begin{table}
\begin{tabular}{c c c} \hline \hline
**Attributes** & **Raw Data** & **Clean Data** \\ \hline Total Customers & 42,372 & 41,897 \\ Honest Customers & 38,757 & 38,321 \\ Dishonest Consumers & 3615 & 3576 \\ Outliers & 475 (39 theft) & \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Overview of the SGCC dataset [2]. \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameters** & **Values** \\ \hline Number of epochs \(E\) & 10 \\ Communication rounds \(R\) & 10 \\ Number of clients \(C\) & 2, 5, 10 \\ Learning ratio \(\lambda\) & 0.001 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: FL-CNN parameters used in the comparative analysis [2]. similarly trained using Adam. The parameter settings adopted in this work are listed in Table 3. The mathematical representation of FedAvg is represented in Equation (1):  
\[\theta_{i}^{t}= \begin{cases}\frac{1}{n}\sum_{i=1}^{n}\theta_{i}^{t-1}-\eta\
abla \mathcal{J}_{i}(\theta_{i}^{t-1})&\text{if $t\
eq 0$}\\ \theta_{i}^{t-1}-\eta\
abla\mathcal{J}_{i}(\theta_{i}^{t-1})&\text{if $t=0$}\end{cases}  \tag{1}\]  
The parameters in the equation are as follows:  
* \(\theta_{i}^{t}\): The parameter vector for the \(i\)-th client or model at iteration \(t\). * \(n\): The total number of clients or models in the learning process. * \(\eta\): The learning rate, a positive scalar that determines the step size in the direction of the negative gradient. * \(\
abla I_{i}(\theta_{i}^{t-1})\): The gradient of the loss function \(J_{i}\) with respect to the parameter vector \(\theta_{i}^{t-1}\) for the \(i\)-th client or model at iteration \(t-1\).