A smart meter fault classification method based on nearest neighbor sample pair construction
Through the method based on nearest neighbor sample pair construction, the sample balance and difference mining problems caused by the complexity of the fault type of smart meter are solved, and fault classification with high accuracy and recall is achieved, and noise and offset problems in the prior art are overcome. .
Patent Information
- Application Number
- CN202210363323.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2042-04-07
AI Technical Summary
Smart meter fault types are complex and diverse. The existing technology is difficult to achieve sample balance without introducing noise and losing information, and it is difficult to dig out the differences between samples in a few categories and distribution differences between categories, resulting in the offset of classifier prediction results. and overfitting.
Using a method based on nearest neighbor sample pair construction, the smart meter fault data set is divided into multiple second-class data sets, and a balanced nearest neighbor sample pair data set is constructed through the KNN algorithm, and a model discrimination network based on comparison learning is constructed, using multiple nearest neighbors. Samples classify the result integration.
It improves the accuracy and recall of smart meter fault classification, avoids the introduction of noise, enhances the model's learning ability of a few types of samples, and improves the stability and accuracy of the classifier.
Smart Images

Figure CN114722940B_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to a smart meter fault classification method, and in particular to a smart meter fault classification method based on nearest neighbor sample pair construction. [Background technology]
[0002] Since the 21st century, smart meters have been widely used in the field of electricity consumption information collection, and the power industry has entered the era of big data. As the terminal equipment under the current smart grid construction in my country, smart meters integrate multiple functions such as measurement, display, and communication, and play an important supporting role in the stable operation of the power grid. With the development of smart grids, the functions of smart meters are becoming increasingly rich, and at the same time, their fault types are also increasing. The timely maintenance of faulty meters is of great significance to the stable operation of the power grid and the stable electricity consumption of users. However, since operation and maintenance personnel often only have maintenance experience for certain specific faulty meters, when a smart meter fails, it is difficult to dispatch maintenance personnel with relevant maintenance experience to perform meter maintenance when the meter fault type is unknown. Therefore, accurate prediction of smart meter fault types is crucial.
[0003] With the development of smart grids, the demand for smart meters is increasing, and the number of smart meter manufacturers has increased accordingly. Different manufacturers have different design schemes, component selection and process flows. In addition, the complex production environment and application environment lead to complex and diverse fault types of smart meters. The occurrence of faults is affected by the above factors at the same time. Finding the mapping relationship between these factors and fault types is extremely complex, which is a typical machine learning problem. In addition, the frequency of occurrence of meters with different fault types is also different, and the fault data presents multi-modal distribution characteristics, which further increases the prediction difficulty of smart meters. Direct learning based on unbalanced data will cause the prediction results of the classifier to shift to the majority class. The processing method at the data level can achieve sample balance, but it does not generate new information in essence. It only expands the number according to the specific sample generation principle. After obtaining a balanced sample data set, the classifier is learned. It is difficult to fully explore the feature differences between categories, and random noise will inevitably be introduced. The algorithm-level method mainly improves the model's learning of minority class samples by changing the model's loss function or model structure, but there is a problem of model overfitting, and it is difficult to learn the distribution difference of two classes of samples from a relatively small number of minority class samples. In the field of imbalanced learning, there are still the following challenges: 1. How to achieve sample balance without introducing noise and losing information; 2. How to mine the differences between samples when the minority class is relatively small; 3. How to learn the distribution differences in the overlapping areas of sample features between categories. Based on the above analysis, the present invention proposes a smart meter fault classification method based on nearest neighbor sample pair construction to improve the performance of smart meter fault classification. [Summary of the invention]
[0004] In view of this, the present invention proposes a smart meter fault classification method based on neighbor sample pair construction to improve the performance of smart meter fault classification.
[0005] The present invention proposes a smart meter fault classification method based on neighbor sample pair construction, comprising the following steps:
[0006] (1) Taking the fault history data of different categories of smart meters as the input data set, multiple second-category data sets are obtained, specifically:
[0007] The actual fault data set of smart meters is input. The samples in this data set include working hours, arrival batch number, power supply unit number, electric energy meter category, fault identification month, installation month, province, equipment specification, communication method, and equipment identification feature variables; its fault category labels include appearance fault, metering fault, storage unit fault, processing unit fault, display unit fault, control unit fault, power supply unit fault, communication unit fault, clock unit fault, other faults, and software faults. Each category of samples in the fault data set is traversed, and all samples under this category are regarded as minority class sample sets, and all samples of other categories are majority class sample sets, and the original data set is converted into 11 second-category data sets; for each of the second-category data sets, the data set can be described as:
[0008] X=[X min ,X maj ]
[0009] Among them, X is a two-category data set, and x is defined i is any sample in the X data set, that is, x i ∈X;X min For the minority class sample set, define x min,i For X min Any sample in the data set, that is, x min,i ∈X min ;X maj is the majority class sample set, define x maj,i For X maj Any sample in the data set, that is, x maj,i ∈X maj ;
[0010] (2) For each second-class data set, each sample is taken as the target sample, and multiple random sampling is performed from its neighbor sample pool to obtain multiple equal-sized groups of similar and heterogeneous control samples, which are combined with the target sample to obtain multiple neighbor sample pairs as positive samples or negative samples in the subsequent classification task. Specifically:
[0011] Based on the unbalanced binary classification dataset X = [Xmin ,X maj ], construct a balanced dataset of neighbor sample pairs:
[0012] For any sample x in the training set i , when it is used as the target sample, multiple groups of nearest neighbor sample pairs can be constructed. Specifically, the KNN algorithm is used to find the target sample x i In X maj and X min The n nearest neighbor samples in get x i The majority class nearest neighbor sample pool and the minority class nearest neighbor sample pool are randomly sampled from the alternative majority class nearest neighbor sample pool as the majority class control sample group c maj (x i ), and combined with the target sample to obtain the nearest neighbor sample pair p i,maj,k =(x i ,c maj (x i )); Randomly sample m samples from the candidate minority class neighbor sample pool as the minority class control sample group c min (x i ), and combined with the target sample to obtain the nearest neighbor sample pair p i,min,k =(x i ,c min (x i ));
[0013] Where n is the size of the nearest neighbor sample pool, m is the number of samples in the control sample group, k∈[1,K] is the label of the control sample group, K is a hyperparameter, which is the preset number of constructed samples for each sample in each category, and represents the number of ordered permutations of m samples from n samples; the subscripts min and maj represent the minority class and the majority class, respectively, that is: c min (x i ) represents x i The minority class control sample group, c maj (x i ) represents x i The majority control sample group, p i,min,k Represents sample x i The kth minority class control sample group, p i,maj,k Represents sample x i The kth majority class control sample group;
[0014] When the target sample and the control sample group are of the same type, the neighbor sample pair is called a positive sample pair and the label is set to 1. Otherwise, it is a negative sample pair and the label is 0. Specifically: (x maj,i ,c maj (x maj,i)) and (x min,i ,c min (x min,i )) has a label of 1; (x maj,i ,c min (x maj,i )) and (x min,i ,c maj (x min,i )) has a label of 0; for any category of target samples, we can get multiple positive sample pairs and negative sample pairs of equal quantity. Therefore, we traverse the samples in X and store the constructed neighbor sample pairs and their labels in sets P and Y respectively. P In this way, we can obtain a balanced neighbor sample pair data set D = (P, Y P ), and use the positive sample pairs and negative sample pairs in D as positive samples or negative samples in the subsequent classification task respectively;
[0015] Among them, P is the constructed set of nearest neighbor sample pairs, Y P is the correct label for P;
[0016] (3) Based on the balanced nearest neighbor sample pair dataset, a pattern discrimination network based on contrastive learning is constructed for the label matching task between the target sample and the control sample group. Specifically:
[0017] Based on the balanced sample pair data set obtained in step (2), a pattern discrimination network model is constructed and trained, and its optimization goal is:
[0018]
[0019] Among them, L model is the loss of the model, And (p,y p )∈(P,Y P ) is the training sample in the nearest neighbor sample pair data set, p is the constructed nearest neighbor sample pair, y p is the correct label for p, is the model’s predicted label for p;
[0020] (4) For a given test sample, any combination of the corresponding control sample groups of different categories is used to obtain a large number of neighboring sample pairs. The discrimination results of the classifier under each two-class data set are obtained through result integration and reverse reasoning, and its fault category is obtained through soft voting, which is specifically:
[0021] Based on the pattern discrimination classifier model trained in step (3), for a test sample x test , the calculation process of its predicted label is as follows:
[0022]
[0023] Among them, p test,maj,k is x test A set of majority class control sample pairs, p test,min,k is x test A set of minority class control sample pairs, For x test Prediction results under this two-category dataset;
[0024] Repeat the above process to get 11 pattern discrimination classifier models j , j is the subscript of the pattern discrimination classifier, j∈[1,11]; for the sample to be tested x test , its predicted label The calculation of is as follows:
[0025]
[0026] When the value is j, it means x test The predicted fault category is the jth fault.
[0027] In the above method, in step (2), the value of n is The value of m is 4, and the value of K is
[0028] in, To round down, len(X min ) is the number of samples in the minority class sample set under the current two-class data set.
[0029] In the above method, in step (3), the structure of the mode discrimination network model is as follows:
[0030]
[0031] Among them, Reshape() is a tensor deformation function; Conv2D() is a two-dimensional convolutional layer construction function, in which the value of the tensor expansion option padding is 'same'; BatchNormalization() is a batch normalization function; Flatten() is a tensor flattening function; Dense() is a fully connected layer construction function; LeakyReLU and Sigmoid represent the corresponding activation functions; Dropout() is a random dropout function.
[0032] The smart meter fault classification method based on nearest neighbor sample pair construction improves the accuracy and recall rate of smart meter fault classification.
[0033] It can be seen from the above technical solutions that the present invention has the following beneficial effects:
[0034] In the technical solution implemented in the present invention, a combination of data level and algorithm level is adopted to balance and amplify data without introducing noise. At the same time, based on the construction method of neighbor sample pairs, the unbalanced classification task is redefined. The introduction of control samples is conducive to the model learning the differences between samples of different categories. The integration of multiple neighbor sample pairs is conducive to improving the accuracy and stability of the results, thereby improving the accuracy and recall rate of smart meter fault classification.
Brief Description of the Drawings
[0035] In order to more clearly illustrate the technical solution of the present invention, the drawings required for use in the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0036] Figure 1 It is a schematic diagram of the framework flow of the smart meter fault classification method based on global sample rebalancing proposed in the present invention;
[0037] Figure 2 It is a flowchart for solving smart meter fault classification;
[0038] Figure 3 It is a detailed schematic diagram of the algorithm of the present invention;
[0039] Figure 4 It is a schematic diagram of the structure and input and output of the model proposed in the present invention. [Specific implementation method]
[0040] In order to better understand the technical solution of the present invention, the present invention is described in detail below with reference to the accompanying drawings.
[0041] It should be clear that the described embodiments of the invention are only part of the embodiments of the invention, not all of the embodiments. Based on the embodiments of the invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the invention.
[0042] The present invention provides a smart meter fault classification method based on neighbor sample pair construction. In order to meet the fault classification of smart meters, the present invention uses the fault history data of smart meters under different categories as input data sets, and divides them into multiple two-category data sets; for each two-category data set, each sample is used as a target sample, and multiple random sampling is performed from its neighbor sample pool to obtain multiple similar or heterogeneous control sample groups, which are combined with the target samples to obtain multiple neighbor sample pairs, which are used as positive samples or negative samples in subsequent classification tasks; based on the balanced neighbor sample pair data set, a pattern discrimination network based on contrastive learning is constructed for the label matching task of the target sample and the control sample group; for a given test sample, a large number of neighbor sample pairs are obtained by arbitrarily combining the control sample groups of different categories corresponding to it, and the discrimination results of the classifier under each two-category data set are obtained through result integration and reverse reasoning, and its fault category is obtained through soft voting.
[0043] Figure 1 The figure is a schematic diagram of the framework flow of the smart meter fault classification method based on the nearest neighbor sample pair construction proposed in the present invention. The method comprises the following steps:
[0044] Step 101: taking fault history data of different categories of smart meters as input data sets, and dividing them into multiple second-category data sets, specifically:
[0045] The actual fault data set of smart meters is input. The samples in this data set include working hours, arrival batch number, power supply unit number, electric energy meter category, fault identification month, installation month, province, equipment specification, communication method, and equipment identification feature variables; its fault category labels include appearance fault, metering fault, storage unit fault, processing unit fault, display unit fault, control unit fault, power supply unit fault, communication unit fault, clock unit fault, other faults, and software faults. Each category of samples in the fault data set is traversed, and all samples under this category are regarded as minority class sample sets, and all samples of other categories are majority class sample sets, and the original data set is converted into 11 second-category data sets; for each of the second-category data sets, the data set can be described as:
[0046] X=[X min ,X maj ]
[0047] Among them, X is a two-category data set, and x is defined i is any sample in the X data set, that is, x i ∈X;X min For the minority class sample set, define x min,i For X min Any sample in the data set, that is, x min,i ∈X min ;X majis the majority class sample set, define x maj,i For X maj Any sample in the data set, that is, x maj,i ∈X maj .
[0048] Step 102, for each second-class data set, take each sample as the target sample, perform multiple random sampling from its neighbor sample pool, obtain multiple equal-sized groups of similar and heterogeneous control samples, and combine them with the target sample to obtain multiple neighbor sample pairs, which serve as positive samples or negative samples in the subsequent classification task, specifically:
[0049] Based on the unbalanced binary classification data set X=[X min ,X maj ], construct a balanced dataset of neighbor sample pairs:
[0050] For any sample x in the training set i , when it is used as the target sample, multiple groups of nearest neighbor sample pairs can be constructed. Specifically, the KNN algorithm is used to find the target sample x i In X maj and X min The n nearest neighbor samples in get x i The majority class nearest neighbor sample pool and the minority class nearest neighbor sample pool are randomly sampled from the alternative majority class nearest neighbor sample pool as the majority class control sample group c maj (x i ), and combined with the target sample to obtain the nearest neighbor sample pair p i,maj,k =(x i ,c maj (x i )); Randomly sample m samples from the candidate minority class neighbor sample pool as the minority class control sample group c min (x i ), and combined with the target sample to obtain the nearest neighbor sample pair p i,min,k =(x i ,c min (x i ));
[0051] Where n is the size of the nearest neighbor sample pool, m is the number of samples in the control sample group, k∈[1,K] is the label of the control sample group, K is a hyperparameter, which is the preset number of constructed samples for each sample in each category, and represents the number of ordered permutations of m samples from n samples; the subscripts min and maj represent the minority class and the majority class, respectively, that is: c min (x i ) represents x i The minority class control sample group, cmaj (x i ) represents x i The majority control sample group, p i,min,k Represents sample x i The kth minority class control sample group, p i,maj,k Represents sample x i The kth majority class control sample group;
[0052] When the target sample and the control sample group are of the same type, the neighbor sample pair is called a positive sample pair and the label is set to 1. Otherwise, it is a negative sample pair and the label is 0. Specifically: (x maj,i ,c maj (x maj,i )) and (x min,i ,c min (x min,i )) has a label of 1; (x maj,i ,c min (x maj,i )) and (x min,i ,c maj (x min,i )) has a label of 0; for any category of target samples, we can get multiple positive sample pairs and negative sample pairs of equal quantity. Therefore, we traverse the samples in X and store the constructed neighbor sample pairs and their labels in sets P and Y respectively. P In this way, we can obtain a balanced neighbor sample pair data set D = (P, Y P ), and use the positive sample pairs and negative sample pairs in D as positive samples or negative samples in the subsequent classification task respectively;
[0053] Among them, P is the constructed set of nearest neighbor sample pairs, Y P is the correct label for P.
[0054] Step 103, based on the balanced nearest neighbor sample pair data set, construct a pattern discrimination network based on contrastive learning for the label matching task of the target sample and the control sample group, specifically:
[0055] Based on the balanced sample pair data set obtained in step 102, a mode discrimination network model is constructed and trained, and its optimization goal is:
[0056]
[0057] Among them, L model is the loss of the model, And (p,y p )∈(P,Y P ) is the training sample in the nearest neighbor sample pair data set, p is the constructed nearest neighbor sample pair, y p is the correct label for p, is the model's predicted label for p.
[0058] Step 104: for a given test sample, any combination of the corresponding control sample groups of different categories is used to obtain a large number of neighbor sample pairs. The discrimination results of the classifier under each two-category data set are obtained through result integration and reverse reasoning, and the fault category is obtained through soft voting, which is specifically:
[0059] Based on the pattern discrimination classifier model trained in step 103, for a sample x to be tested test , the calculation process of its predicted label is as follows:
[0060]
[0061] Among them, p test,maj,k is x test A set of majority class control sample pairs, p test,min,k is x test A set of minority class control sample pairs, For x test Prediction results under this two-category dataset;
[0062] Repeat the above process to get 11 pattern discrimination classifier models j , j is the subscript of the pattern discrimination classifier, j∈[1,11]; for the sample to be tested x test , its predicted label The calculation of is as follows:
[0063]
[0064] When the value is j, it means x test The predicted fault category is the jth fault.
[0065] Figure 2 The present invention is a flow chart of solving the problem of smart meter fault classification. First, the fault history data sets under different categories of smart meters are divided into multiple two-category data sets. The proposed invention applies the smart meter fault classification method based on neighbor sample pair construction (Fault Classification Method for smart meters with Sample-Neighbors Pair construction, SNP-FCM) to balance the sample sets, and obtain multiple balanced two-category data sets. Pattern discrimination classifiers are trained respectively. For samples to be tested, the pattern discrimination classifiers obtained under each two-category data set can be used for discrimination, and the final prediction category can be obtained by a soft voting method.
[0066] Figure 3This is a schematic diagram of the core idea of the algorithm of the present invention. The algorithm of the present invention is based on the nearest neighbor sample pair construction method, which transforms the traditional imbalanced classification problem into a pattern matching problem between the target sample and the control sample group, and is used to solve the problem of noise introduced in the sample generation process, while overcoming the problem that the number of minority class samples is relatively small and the features of the overlapping areas of categories are difficult to mine. The traditional imbalanced classification method is a classification method at the sample point level, which is to model p(y|x) by training the classification model with minority class sample points and majority class sample points, where the minority class samples and the majority class samples correspond to point in the figure respectively. + and point - .
[0067] Due to the imbalance between majority class samples and minority class samples, the obtained classifier has decision bias problems. Through the neighbor sample pair construction method proposed in the present invention, the traditional classification problem is converted into a classification method at the sample pair level, which is to model p(same / different categories|(x,c(x))) through the neighbor sample pair training classification model, where (x,c(x)) is a neighbor sample pair, x is the target sample, c(x) is a set of control sample groups of the target sample obtained by sampling, and the subscripts min and maj represent the minority class and the majority class respectively. For any point in the traditional imbalanced classification problem + or point - , multiple equal pairs of nearest neighbor positive samples can be constructed + and the nearest negative sample pair - .
[0068] Therefore, for the classification problem constructed based on nearest neighbor sample pairs, the number of samples of each category in the training set is not only balanced, but also multiplied.
[0069] Figure 4 It is a schematic diagram of the model structure and input and output proposed in the present invention. The target sample and the control sample group constitute a nearest neighbor sample pair, which is input into the proposed model as a sample. After the model analyzes and compares its characteristics, the judgment result of whether the types of samples in the target sample and the control sample group are the same is obtained.
[0070] Algorithm 1 is the pseudo code of the nearest neighbor sample pair construction algorithm:
[0071]
[0072]
[0073] In the specific embodiment, the fault history data set of different categories of smart meters was used for testing. The data set collected a total of 11 types of smart meter data in 25 provinces. Due to the influence of various factors such as manual statistics and external conditions, the data labels were mislabeled or missing. After data cleaning by various technologies such as cluster analysis, missing value completion, and outlier processing, a total of 15,885 fault sample data were obtained. In order to reduce the randomness of the results, the data set was randomly divided into a training set and a test set with a fixed random number seed in a ratio of 8:2.
[0074] Table 1 Datasets used in specific examples
[0075]
[0076] To verify the effectiveness of the proposed algorithm, 10 data-level methods and 6 mainstream deep learning sample generation methods are used in the embodiment of the present invention for comparison, as shown in Table 2. Considering the large amount of sample data and complex categories of the smart meter fault dataset, RF is used as a classifier to verify the sample balance effect. The embodiment of the present invention is represented by SNP-FCM in the table.
[0077] Table 2 Algorithms compared in specific embodiments
[0078]
[0079]
[0080] The embodiment of the present invention uses macro-F1 and G-mean indicators to evaluate the classification effect of the algorithm. The macro-F1 indicator is the arithmetic mean of the F1-measure of each category, which is used to comprehensively evaluate the accuracy and recall of the model in each category. The G-mean indicator is the geometric mean of the recall rate in each category, which is used to evaluate the recall of the model in each category. Both Macro-F1 and G-mean have values from 0 to 1. The larger the value, the better the classification performance of the model.
[0081] The experimental results of the embodiment of the present invention and the mainstream oversampling method on the F1-measure and macro-F1 indicators under various fault categories of smart meters are shown in Table 3, and the experimental results on the recall rate and G-mean indicators of each category are shown in Table 4. It can be seen that the smart meter fault classification method constructed based on the nearest neighbor sample pair of the present invention has obtained F1-measure and recall rates that exceed those of other methods in most categories, and has obtained the highest macro-F1 and G-mean. Combining the results of Tables 3 and 4, it is shown that the smart meter fault sample balancing effect of the method of the embodiment of the present invention is better than that of the data level balancing method, and can obtain higher classification accuracy and recall rate.
[0082] Table 3 Experimental results of SNP-FCM and data-level methods on F1-measure and macro-F1 indicators for various fault categories of smart meters
[0083]
[0084]
[0085] Table 4 Experimental results of VAE-SLGAN and oversampling method on recall rate and G-mean index for each fault category of smart meter
[0086]
[0087] The experimental results of the embodiment of the present invention and the mainstream algorithm-level methods on the F1-measure and macro-F1 indicators under various fault categories of smart meters are shown in Table 5, and the experimental results on the recall rate and G-mean indicators of each category are shown in Table 6. It can be seen that the smart meter fault classification method constructed based on neighbor sample pairs of the present invention has obtained F1-measure and recall rates that exceed other methods in most categories, and has obtained the highest macro-F1 and G-mean. The results of Tables 5 and 6 show that the smart meter fault sample balancing effect of the method of the embodiment of the present invention is better than that of the algorithm-level method, and can obtain higher classification accuracy and recall rate.
[0088] Table 5 Experimental results of SNP-FCM and algorithm-level methods on F1-measure and macro-F1 indicators under various fault categories of smart meters
[0089]
[0090]
[0091] Table 6 Experimental results of SNP-FCM and algorithm-level methods on recall rate and G-mean index for each fault category of smart meters
[0092]
[0093] A large number of comparison results with mainstream oversampling methods and deep learning sample generation methods show that the proposed neighbor sample pair construction method can achieve sample balance without introducing noise when dealing with the multi-classification problem of smart meters with a relatively small number of minority class samples and overlapping features between class data. It is beneficial to the differences between similar samples, and can effectively improve the accuracy and recall rate of faulty meter classification through comparative learning and result integration between target samples and control sample groups.
[0094] In summary, the embodiments of the present invention have the following beneficial effects:
[0095] In the technical solution implemented in the present invention, fault history data of smart meters under different categories are taken as input data sets, and divided into multiple two-category data sets; for each two-category data set, each sample is taken as a target sample, and multiple random sampling is performed from its neighbor sample pool to obtain multiple similar or heterogeneous control sample groups, which are respectively combined with the target samples to obtain multiple neighbor sample pairs, which are used as positive samples or negative samples in subsequent classification tasks; based on the balanced neighbor sample pair data set, a pattern discrimination network based on contrastive learning is constructed for the label matching task of the target sample and the control sample group; for a given test sample, a large number of neighbor sample pairs are obtained by arbitrarily combining the control sample groups of different categories corresponding to it, and the discrimination result of the classifier under each two-category data set is obtained through result integration and reverse reasoning, and its fault category is obtained through soft voting.
[0096] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A smart meter fault classification method based on nearest neighbor sample pair construction, characterized in that: The steps include: (1) Taking the fault history data of different categories of smart meters as the input data set, multiple second-category data sets are obtained, specifically: The actual fault data set of smart meters is input. The samples in this data set include working hours, arrival batch number, power supply unit number, electric energy meter category, fault identification month, installation month, province, equipment specification, communication method, and equipment identification feature variables; Its fault category labels include 11 categories: appearance fault, metering fault, storage unit fault, processing unit fault, display unit fault, control unit fault, power supply unit fault, communication unit fault, clock unit fault, other faults, and software faults. Each category of samples in the fault data set is traversed, and all samples under this category are regarded as minority class sample sets, and all samples of other categories are majority class sample sets, and the original data set is converted into 11 second-category data sets. For each of the second-category data sets, the data set can be described as: X=[X min ,X maj ] Among them, X is a two-category data set, and x is defined i is any sample in the X data set, that is, x i ∈X;X min For the minority class sample set, define x min,i For X min Any sample in the data set, that is, x min,i ∈X min ;X maj is the majority class sample set, define x maj,i For X maj Any sample in the data set, that is, x maj,i ∈X maj ; (2) For each second-class data set, each sample is taken as the target sample, and multiple random sampling is performed from its neighbor sample pool to obtain multiple equal-sized groups of similar and heterogeneous control samples, which are combined with the target sample to obtain multiple neighbor sample pairs as positive samples or negative samples in the subsequent classification task. Specifically: Based on the unbalanced binary classification dataset X = [X min ,X maj ], construct a balanced neighbor sample pair dataset: For any sample x in the training set i , when it is used as the target sample, multiple groups of nearest neighbor sample pairs can be constructed. Specifically, the KNN algorithm is used to find the target sample x i In X maj and X min The n nearest neighbor samples in get x i The majority class nearest neighbor sample pool and the minority class nearest neighbor sample pool are randomly sampled from the alternative majority class nearest neighbor sample pool as the majority class control sample group c maj (x i ), and combined with the target sample to obtain the nearest neighbor sample pair p i,maj,k =(x i ,c maj (x i )); Randomly sample m samples from the candidate minority class neighbor sample pool as the minority class control sample group c min (x i ), and combined with the target sample to obtain the nearest neighbor sample pair p i,min,k =(x i ,c min (x i )); Where n is the size of the nearest neighbor sample pool, m is the number of samples in the control sample group, k∈[1,K] is the label of the control sample group, K is a hyperparameter, which is the preset number of constructed samples for each sample in each category, and represents the number of ordered permutations of m samples from n samples; the subscripts min and maj represent the minority class and the majority class, respectively, that is: c min (x i ) represents x i The minority class control sample group, c maj (x i ) represents x i The majority control sample group, p i,min,k Represents sample x i The kth minority class control sample group, p i,maj,k Represents sample x i The kth majority class control sample group; When the target sample and the control sample group are of the same type, the neighbor sample pair is called a positive sample pair and the label is set to 1. Otherwise, it is a negative sample pair and the label is 0. Specifically: (x maj,i ,c maj (x maj,i )) and (x min,i ,c min (x min,i )) has a label of 1; (x maj,i ,c min (x maj,i )) and (x min,i ,c maj (x min,i )) has a label of 0; for any category of target samples, we can get multiple positive sample pairs and negative sample pairs of equal quantity. Therefore, we traverse the samples in X and store the constructed neighbor sample pairs and their labels in sets P and Y respectively. P In this way, we can obtain a balanced neighbor sample pair data set D = (P, Y P ), and use the positive sample pairs and negative sample pairs in D as positive samples or negative samples in the subsequent classification task respectively; Among them, P is the constructed set of nearest neighbor sample pairs, Y P is the correct label for P; (3) Based on the balanced nearest neighbor sample pair dataset, a pattern discrimination network based on contrastive learning is constructed for the label matching task between the target sample and the control sample group. Specifically: Based on the balanced sample pair data set obtained in step (2), a pattern discrimination network model is constructed and trained, and its optimization goal is: Among them, L model is the loss of the model, And (p,y p )∈(P,Y P ) is the training sample in the nearest neighbor sample pair data set, p is the constructed nearest neighbor sample pair, y p is the correct label for p, is the model's predicted label for p; (4) For a given test sample, any combination of the corresponding control sample groups of different categories is used to obtain a large number of neighboring sample pairs. The discrimination results of the classifier under each two-class data set are obtained through result integration and reverse reasoning, and its fault category is obtained through soft voting, which is specifically: Based on the pattern discrimination classifier model trained in step (3), for a test sample x test , the calculation process of its predicted label is as follows: Among them, p test,maj,k is x test A set of majority class control sample pairs, p test,min,k is x test A set of minority class control sample pairs, For x test Prediction results under this two-category dataset; Repeat the above process to get 11 pattern discrimination classifier models j , j is the subscript of the pattern discrimination classifier, j∈[1,11]; for the sample to be tested x test , its predicted label The calculation of is as follows: When the value is j, it means x test The predicted fault category is the jth fault.
2. The smart meter fault classification method based on neighbor sample pair construction according to claim 1 is characterized in that: In step (2), the value of n is The value of m is 4, and the value of K is in, To round down, len(X min ) is the number of samples in the minority class sample set under the current two-class data set.
3. The smart meter fault classification method based on neighbor sample pair construction according to claim 1 is characterized in that: In step (3), the structure of the mode discrimination network model is as follows: Among them, Reshape() is a tensor deformation function; Conv2D() is a two-dimensional convolutional layer construction function, The value of the tensor expansion option padding is 'same'; BatchNormalization() is a batch normalization function; Flatten() is a tensor flattening function; Dense() is a fully connected layer construction function; LeakyReLU and Sigmoid represent the corresponding activation functions; Dropout() is a random dropout function.