# Fault Prediction and Reconfiguration Optimization in Smart Grids: AI-Driven Approach
## 5 Evaluation
### Machine Learning Techniques
#### 5.3.2 Hyperparameters' Optimization  
To find the best combination of hyperparameters for each model, the Grid Search method [48] was used. This method performs an exhaustive search through a grid of hyperparameters to identify the combination that offers the highest accuracy. Additionally, since it is based on cross-validation, the dataset was divided into five folds.  
In the case of the RF technique, the focus was on two main hyperparameters: the number of estimators or trees and the impurity measurement criterion. The execution of the method determined, based on the _best_score_ and _best_params_ attributes, the best combination of hyperparameters, achieving an accuracy of 99.18% with a classifier of 100 estimators using the entropy criterion (Table 5). For a more detailed analysis, the _cv_results_ attribute was used, which provided comprehensive information about the search. It can be observed that, although the variations in accuracy between different parameter combinations were minimal, the fitting times showed significant differences. As shown in Table 6, the duration of the training increased proportionally with the number of estimators configured in the model. Therefore, since accuracy did not improve significantly when using more than 25 estimators, the classifier with 25 estimators based on the entropy criterion was determined to be the optimal model.  
To model an optimal SVM, two hyperparameters were mainly studied: the type of kernel and the regularization parameter \(C\) (See Tables 7 and 8). The parameter \(\gamma\) was omitted due to the prior scaling of the data, which eliminated its impact. In this case, different from the RF, the search for the best combination of hyperparameters required more execution time, taking approximately 350 h. The results of this process showed that the optimal model was an SVM with an RBF kernel and a regularization parameter \(C\) equal to one, achieving an accuracy of 97.78% and requiring a relatively low training time compared to other hyperparameter combinations. The analysis of the _cv_results_ attribute revealed that the _sigmoid_ kernel offered the worst performance and that the polynomial (_poly_) kernel showed an increase in training time as \(C\) increased, suggesting that a high \(C\) value was not suitable for this kernel.  
\begin{table}
\begin{tabular}{c c c} \hline \multirow{2}{*}{_Number of Estimators_} & \multicolumn{2}{c}{_Criterion_} \\ \cline{2-3}  & _Entropy_ & _Gini_ \\ \hline
10 & 147 & 146 \\ \hline
25 & 373 & 382 \\ \hline
50 & 747 & 761 \\ \hline
75 & 1072 & 1002 \\ \hline
100 & 1439 & 987 \\ \hline \end{tabular}
\end{table}
Table 6: Time (s) (_mean_fit_time) of _cv_results_ attribute from the _Grid Search_ in the RF.  
\begin{table}
\begin{tabular}{c c c} \hline \multirow{2}{*}{_Number of Estimators_} & \multicolumn{2}{c}{_Criterion_} \\ \cline{2-3}  & _Entropy_ & _Gini_ \\ \hline
10 & 99.07 & 99.02 \\ \hline
25 & 99.16 & 99.14 \\ \hline
50 & 99.16 & 99.15 \\ \hline
75 & 99.17 & 99.17 \\ \hline
100 & 99.18 & 99.16 \\ \hline \end{tabular}
\end{table}
Table 5: Accuracy (\(\%\)) (_mean_test_score_) of _cv_results_ attribute from the _Grid Search_ in the RF.