## 4 Random Forests Theory
### Improved Random Forest Algorithm
The development of the proposed Algorithm 1 is as follows:  
``` Begin: (1) Determine the out-of-bag data rate, \(Xos\), the test data rate, \(X_{TP}\), the number of decision trees, \(K\), and the Gaussian white noise variance, \(M\); (2) According to \(X_{TP}\), determine the training data, \(T\), and predict the test data, \(P\); fork = 1 to K do (3) Using bootstrap sampling and according to \(X_{OS}\), the training set, \(T\), is divided into training subset, \(S_{k}\), and out-of-bag data, \(O_{k}\); (4) According to the C4.5 algorithm, \(N\) features are randomly selected as node classification features, and \(S_{k}\) is used to generate a decision tree; (5) Add random Gaussian white noise of \(M\) decibels to \(O_{k}\); (6) Take \(O_{K}\), \(P\) as the test set; (7) According to Equations (7) and (8), calculate the weights of the \(k\)th decision tree as \(w_{Ok}\) and \(w_{Pk}\); (8) Calculate the final weight, \(w_{k}\), of the \(k\)th decision tree by Equation (9); endfor (9) The test data are classified by the decision tree set, and the final classification result is determined by Equation (11);  ENDFinally, the type with the most votes is the fault diagnosis result of random forests. The final weights of the RFs model, the fault diagnosis result of each decision tree, and the fault diagnosis result of random forests are as follows:

\[w_{k}=\frac{w_{h_{k}}+w_{O_{k}}}{2},\,k=1,2,\ldots,K \tag{9}\]

\[h_{k}{}^{DT}(x)=y_{k} \tag{10}\]

\[H^{\prime}\left(x\right)=\underset{y\in Y}{\operatorname{argmax}}\sum_{k=1}^{ K}w_{k}I(h_{k}{}^{DT}(x)=y_{k}) \tag{11}\]

In order to obtain a better fault diagnosis effect, an optimization model is constructed to optimize the hyperparameters \(X_{TP}\), \(X_{OS}\), \(K\) and \(M\). The optimization objective function is defined as:

\[\text{max}F_{obj}=X_{ORF}+X_{PRF} \tag{12}\]

\[X_{ORF}=\frac{\sum\limits_{k=1}^{K}X_{O_{k}}^{corr}}{K} \tag{13}\]

\(X_{ORF}\) is the average number of samples correctly classified by the random forests model in the out-of-bag data test set. \(X_{PRF}\) predicts the correct number of samples for the random forests in the test dataset \(P\). Boundary Condition:

\[s.t\left\{ \begin{array}{c}X_{TP}T\leq P\\ M\leq a_{h}\text{max}(THD_{I}),1\leq a_{h}\leq 2\\ X_{OS}\leq 0.5\\ K\in N\end{array} \right. \tag{14}\]

In the formula: max (\(THD_{I}\)) is the maximum total harmonic ratio of the measured object current. In recent years, particle swarm optimization algorithm has been widely used in various optimization problems because of its simplicity, easy implementation and fast convergence speed. The optimization objective is solved by the particle swarm optimization algorithm. For details, please refer to [29]. ## 5 Simulation and Experimental

In order to verify the effectiveness of the proposed data-driven method in practical applications, simulation tests and experiments are carried out. The performance of the ANN, SVM, and RFs, weighted RFs, PSO weighted RFs fault diagnosis model was evaluated in the simulation phase. The commonly used evaluation indicators of data-driven method fault diagnosis, accuracy, precision, recall, and model training time are used to measure the performance of the proposed method. The definition of the fault diagnosis accuracy, precision, and recall are as follows:

\[Accu=\frac{TP+TN}{TP+TN+FP+FN} \tag{15}\]

\[\text{Prec}=\frac{TP}{TP+FP} \tag{16}\]

\[\text{Reca}=\frac{TP}{TP+FN} \tag{17}\]

_TP_, _TN_, _FP_, and _FN_ denote true positive, true negative, false positive and false negative, respectively. ### Database Generation

In order to generate fault diagnosis models, a comprehensive and informative database is required. Such databases can be obtained from historical measurements or simulations. Considering that the measured object has a variety of random disturbance factors, which are caused by sensors disturbance, converter parameters and so on, therefore, the fault data are not easy to precisely obtain from object system.