# Hyperparameter Optimization of Ensemble Models for Spam Email Detection
## 4 Results and Discussion
### Results and Discussion
#### 4.2.1 Performance Evaluation Metrics  
The metrics that were used to evaluate the performance of the ensemble algorithms are accuracy, sensitivity (recall), precision, F1-score, specificity, and the Area under the Receiver Operating Curve (ROC) curve. The true positive (TP), true negative (TN), false positive (FP), and false negative (FN), which are components of the confusion matrix (Table 3), were used to compute the performance metrics. The confusion matrixes for the random forest baseline model, XGBoost baseline model, random forest tuned model, and the XGBoost tuned model are presented in Table 4.  
Accuracy measures the number of emails correctly predicted against the total number of predictions (Equation (5)). The accuracy metric is a reliable metric for performance evaluation, considering that there is no significant imbalance in the class distribution in the dataset used. \[Accuracy=\frac{(TP+TN)}{(P+N)} \tag{5}\]  
The random forest baseline model, XGBoost baseline model, random forest tuned model, and XGBoost tuned model achieved an accuracy of 0.9752, 0.9748, 0.9778, and 0.9809, respectively. This implies that for all classes 98.09% of the emails were correctly predicted by the tuned XGBoost model which achieved the highest accuracy as shown in Figure 6.  
\begin{table} \begin{tabular}{c c c c c c} \hline \hline  & \multicolumn{2}{c}{**RF Baseline Model**} & \multicolumn{3}{c}{**XGBoost Baseline Model**} \\ \hline  & Spam & Ham & & Spam & Ham \\ \hline Spam & 4907 & 102 & Spam & 4957 & 52 \\ \cline{2-6} Ham & 140 & 4604 & Ham & 194 & 4550 \\ \cline{2-6}  & \multicolumn{2}{c}{**RF Tuned Model**} & \multicolumn{3}{c}{**XGBoost Tuned Model**} \\ \cline{2-6} Spam & 4931 & 78 & Spam & 4951 & 58 \\ \cline{2-6} Ham & 139 & 4605 & Ham & 128 & 4616 \\ \hline \hline \end{tabular} \begin{tabular}{c} where \\ \end{tabular} \begin{tabular}{c} Positive (P): Absolute number of spam emails. \\ \end{tabular} \begin{tabular}{c} Negative (N): Absolute number of ham emails. \\ \end{tabular} \begin{tabular}{c} True positive (TP): Absolute number of e-mails correctly classified as spam. \\ \end{tabular} \begin{tabular}{c} True negative (TN): Absolute number of e-mails classified as ham (not spam) and are truly ham. \\ \end{tabular} \begin{tabular}{c} False positive (FP): Absolute number of e-mails classified as spam, but they are not spam. \\ \end{tabular}  \ \begin{tabular}{c} False negative (FN): Absolute number of e-mails classified as ham, but they are spam. \\ \end{tabular} 
\begin{tabular}{c} Accuracy measures the number of emails correctly predicted against the total number of predictions (Equation (5)). The accuracy metric is a reliable metric for performance evaluation, considering that there is no significant imbalance in the class distribution in the dataset used. \[Accuracy=\frac{(TP+TN)}{(P+N)} \tag{5}\]  
The random forest baseline model, XGBoost baseline model, random forest tuned model, and XGBoost tuned model achieved an accuracy of 0.9752, 0.9748, 0.9778, and 0.9809, respectively. This implies that for all classes 98.09% of the emails were correctly predicted by the tuned XGBoost model which achieved the highest accuracy as shown in Figure 6. \begin{table}
\begin{tabular}{c c c} \hline \hline  & \multicolumn{2}{c}{**Predicted Class**} \\ \hline \multirow{2}{*}{Actual Class} & TP & FN \\ \cline{2-4}  & FP & TN \\ \hline \hline \end{tabular}
\end{table} 
Table 3: A confusion matrix and its constituents. Sensitivity (Recall)  
Sensitivity measures the number of positives that are accurately predicted as a positive class for all positive data points. This metric is determined as presented in Equation (6). \[Recall=\frac{TP}{(TP+FN)} \tag{6}\]  
The random forest baseline model, XGBoost baseline model, random forest tuned model, and XGBoost tuned model achieved a sensitivity of 0.9796, 0.9896, 0.9844, and 0.9884, respectively. As observed in Figure 6, the XGBoost baseline model has the highest (sensitivity) spam email detection rate.