# Defect Prediction for Capacitive Equipment in Power System
## 4 Experiments
### Defect Prediction Model Based on RF  
In this experiment, the hardware configuration includes Intel(R) Xeon(R) Gold 5115 CPU @ 2.40 Ghz (INTEL Corporation, Santa Clara, CA, USA), 32 GB RAM, and NVIDIA RTX 1060 GPU (NVIDIA Corporation, Santa Clara, CA, USA), with Python as the programming language. The objective of this study is to forecast the occurrence of defects in capacitive equipment within a specified time period. The dataset utilized comprises both defect and nondefect data. Supervised learning is conducted using the RF algorithm, leveraging historical data of capacitive equipment to construct a defect occurrence prediction model. Parameter tuning is executed utilizing grid search and random search techniques. Additionally, a defect level model is established using the RF algorithm on the defect dataset, predicting four levels of defects: urgent, critical, general, and others. The same parameter tuning methodology employed for the defect occurrence prediction model is applied. To address the task of defect level prediction, the problem is transformed into four individual binary classification problems, as depicted in Figure 4.  
During the training phase, four separate classifiers are trained using a one-vs-all approach. In each iteration, one class is considered to be the positive class, while all examples of the other classes serve as negative instances. For example, classifier F1 is trained to classify 'urgent' samples as a distinct class while grouping the remaining samples of 'critical', 'general', and 'others' into another class. During the testing phase, if only one classifier predicts a positive class, the corresponding class label is selected as the final classification result. The defect occurrence prediction model based on RF can be trained using the RandomForestClassifier module from Scikit-learn library. Among all the parameters, 'Max_features' and 'N_estimators' exert the most significant impact on the prediction model. 'Max_features' determines the maximum number of features available for each individual decision tree, and increasing its value generally improves the model's performance. With 24 features in each sample, the decision tree can be trained using any combination of these features. 'N_estimators' refers to the number of subtrees to be created, and increasing its value can enhance the performance of the model. However, there is a saturation point beyond which the prediction accuracy will not further improve. To obtain the best-performing model, it is necessary to determine the optimal values for 'Max_features' and 'N_estimators'. In this study, 70% of the samples are utilized as the training set, while the remaining 30% are used as the testing set. To enhance computational efficiency, 20,000 samples were randomly selected for parameter tuning. 'Max_features' is set to 'none','sqrt', and '15', while 'N_estimators' varies from 10 to 300. 'none' indicates no restriction on the maximum number of features and is set to 24. 'sqrt' represents the square  
Figure 4: The strategy of transforming a four-classification problem into a binary classification problem. root of the maximum number of selected features and is set to four. The value '15' is self-set based on the characteristics of the capacitive data. The out-of-bag (OOB) error rate is used to measure the accuracy of the model, with lower error rates indicating higher accuracy. The OOB error curves for different numbers of subtrees are shown in Figures 5 and 6. Based on the findings presented in Figure 5, it can be observed that the defect occurrence prediction model tends to reach a state of convergence when the number of subtrees exceeds 110. Similarly, as depicted in Figure 6, the defect level prediction model exhibits a convergence trend when the number of subtrees surpasses approximately 130. Subsequently, further fine-tuning of the parameters is performed using grid search, resulting in the determination of the optimal parameter combinations.