# Enhancing Phishing Email Detection through Ensemble Learning and Undersampling
## 4 Hybrid Ensemble Learning with Data Undersampling
### FMMPED Algorithm  
Like the FMPED algorithm, the FMMPED algorithm also contains three stages as follows.  
* Stage 1: Remove the overlapping majority class samples  
Different from the RMCSPV algorithm, the RMCSBM (removing majority class samples based on Markov) method combines FLD and Markov sampling to sample majority class samples near a classification hyperplane. The main reason is [38] mentions that Markov sampling can obtain samples near the hyperplane. The specific process of Stage 1 can be stated as Algorithm 3.  
* Stage 2: Markov Undersampling  
This process is exactly the same as the MUS algorithm and will not be repeated here.  
* Stage 3: Ensemble classifier  
The FMMPED algorithm controls the number of undersampling rounds based on the imbalance ratio. In each round, the sampled majority class samples are combined with the minority class samples to train a classifier and compute the corresponding weight. If the sum of all metrics of the newly obtained classifier is higher than that of the previous classifier, it is accepted. Otherwise, it is rejected. Finally, the accepted classifiers corresponding to weights above the mean are integrated to obtain the final classifier. The specific process of the FMMPED algorithm can be stated as Algorithm 4. All experimental results of MUS are based on \(r_{1}=0.15\) in this article. Section 5 will discuss the choice of \(r_{1}\).  
```
Input:\(\mathcal{D}_{maj},\mathcal{D}_{min},\mathcal{D},\theta,q,\bar{n},\bar{n}\) Output:\(\hat{\mathcal{D}}_{maj}\)
1\(N\leftarrow\theta*|D_{maj}|\);
2 Get a learning model \(f\) by training FLD with \(\mathcal{D}\);
3 Let \(j\gets 1,\bar{n}\gets 0\). Take a sample \(z_{j}\) from \(\mathcal{D}_{maj}\) randomly;
4 while\(j\leq N\)do
5 Draw randomly a sample \(z_{*}\) from \(\mathcal{D}_{maj}\);
6\(P\gets e^{-V(f,z_{*})}/e^{-V(f,z_{j})}\);
7 if\(\bar{n}>\bar{n}\)then
8\(P\leftarrow\min\{1,qP\}\);
9 if\(P\equiv 1\) and \(y_{j}y_{*}=1\)then
10\(P\gets e^{-y_{*}f}/e^{-y_{j}f}\);
11 if\(P>rand(1)\) or \(\bar{n}>\bar{n}\)then
12\(z_{j}\gets z_{*},\hat{\mathcal{D}}\gets z_{j},j\gets j+1,N^{ \prime}\gets j,\bar{n}\gets 0\);
13 if\(z_{*}\) is not acceptedthen
14\(\bar{n}\leftarrow\bar{n}+1\);
15 Let \(\hat{\mathcal{D}}_{maj}=\mathcal{D}_{maj}-\{z_{j}\}_{j=1}^{N}\);
```  
**Algorithm 3**RMCSBM  
```
Input:\(\mathcal{D}_{maj},\mathcal{D}_{min},\mathcal{D},r_{1}\) Output:\(f\)
1\(r\leftarrow\lfloor\frac{|D_{maj}|}{|D_{min}|}\rfloor,s\gets r,o\gets 0,flag \gets 1,n\gets 0\);
2 while\(|\mathcal{D}_{maj}|\
eq 0\)do
3 if\(flag==1\)then
4 Put \(\mathcal{D}_{\mathcal{D}}\),\(\mathcal{D}_{maj}\);\(\mathcal{D}_{min}\) in Algorithm 3, get new \(\mathcal{D}_{maj}\leftarrow\hat{\mathcal{D}}_{maj}\);
5\(r\leftarrow\lfloor\frac{|D_{maj}|}{|D_{min}|}\rfloor,flag\gets 0\);
6 if\(r\geq r_{1}*s\)then
7 Put \(\mathcal{D}_{\mathcal{D}}\),\(\mathcal{D}_{maj}\);\(\mathcal{D}_{min}\) in Algorithm 2, get \(\hat{\mathcal{D}}\) and new \(\mathcal{D}_{maj}\leftarrow\hat{\mathcal{D}}_{maj}\);
8 Get a learning model \(f\) by training \(\hat{\mathcal{D}}\) with Soft-voting ensemble learning, and calculate sum of \(F\), \(A\), \(R\), \(G\), \(M\) with \(\mathcal{D}\);
9 if\(sum\geq o\)then
10\(n\gets n+1\), \(w_{n}\leftarrow-0.5*\log((5-sum)/(sum)),f_{n}=f\);
11\(o\)=sum;
12\(r\leftarrow\frac{|D_{maj}|}{|D_{min}|}\);
13
14
15 Retain \(n_{1}\) models with weights higher than \(\frac{\sum_{n}w_{n}}{n}\);
16\(f=sign(\sum_{1}^{n_{1}}w_{n_{1}}*f_{n_{1}})\);
```  
**Algorithm 4**FMMPED Algorithm