A method, device, equipment and storage medium for detecting power consumption data
By generating false abnormal electricity consumption data and combining a combination model of convolutional neural network, long-term memory network and multi-head attention mechanism, the problem of data imbalance in power theft detection is solved, and the detection accuracy of power theft behavior is improved.
Patent Information
- Application Number
- CN202210859385.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-21
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-07-21
AI Technical Summary
The existing data imbalance in the power theft detection of power theft detection results in biased detection model, low detection accuracy, and difficult to effectively identify power theft behavior.
By obtaining normal and abnormal power consumption data, the generator generates false abnormal power consumption data, constructs the target training set, and uses a combination model of convolutional neural network, long and short-term memory network and multi-head attention mechanism for training and detection, and performs class balance processing to improve detection accuracy.
It effectively avoids the bias of the detection model to most classes, improves the detection accuracy of power theft behavior, and improves the model's ability to identify samples from a few classes.
Smart Images

Figure CN115186012B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and particularly relates to a method, device, equipment and storage medium for detecting power consumption data. Background Art
[0002] Smart meters can measure and monitor power consumption information in real time and then send reports to grid service providers. However, in this process, malicious users may attack the system vulnerabilities of smart meters through new Internet of Things technologies, thereby tampering with the metering data of local and remote interactions, achieving the purpose of illegal power consumption and reducing the billing bill. In order to prevent users from stealing electricity, power theft detection (ETD) is a feasible method.
[0003] In the prior art, the method based on state estimation uses a modified ammeter to detect fraud in low-voltage devices, and operators can check and compare the differences in local and remote power theft detection measures. However, the power theft detection based on state estimation can only be applied to the substation level and cannot be applied to the end-user level. In addition, additional equipment will incur additional costs, and some types of equipment are difficult to install in existing distribution networks; the method based on game theory regards these tampering behaviors as a game between malicious users and power companies. The goal of this method is to find the Nash equilibrium of the game. The method based on game theory is relatively cheap, but it is difficult for them to find a suitable equation to explain the relationship between users and power companies; the method based on machine learning has problems in parameter selection, resulting in poor detection performance. The probability that nodes cannot correctly separate samples, causing misclassified samples to enter the next node and resulting in error accumulation will increase. The overfitting problem caused by the inclusion of duplicate data is not taken into account. The complex neural network makes the system easy to fall into local minima and unable to jump out, and it is difficult to determine the number of convolutional layers and network hyperparameters in deep learning, etc.
[0004] Therefore, how to provide an efficient and accurate power consumption data detection scheme is a technical problem that those skilled in the art need to solve urgently. Summary of the Invention
[0005] In view of this, the purpose of the present invention is to provide a method, device, equipment and storage medium for detecting power consumption data, avoiding the bias of the detection results of the detection model due to data imbalance, thereby improving the detection accuracy of power theft behaviors. The specific scheme is as follows:
[0006] The first aspect of the present application provides a method for detecting power consumption data, including:
[0007] Obtain normal power consumption data and abnormal power consumption data, and generate fake abnormal power consumption data using the generator in the first model based on the abnormal power consumption data to obtain a target training set; wherein, the target training set includes first sample data composed of the normal power consumption data and second sample data composed of the abnormal power consumption data and the fake abnormal power consumption data; the generator is a fully connected network;
[0008] Train the second model using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism;
[0009] Input the power consumption data to be detected into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network, and the multi-head attention mechanism to obtain corresponding detection results.
[0010] Optionally, after obtaining the normal power consumption data and the abnormal power consumption data, it further includes:
[0011] Use the Lagrange interpolation method to fill in the missing values of the normal power consumption data and the abnormal power consumption data respectively to obtain the filled normal power consumption data and abnormal power consumption data;
[0012] Use the min-max scaling method to normalize the filled normal power consumption data and abnormal power consumption data respectively to obtain the normalized normal power consumption data and abnormal power consumption data.
[0013] Optionally, before generating the fake abnormal power consumption data using the generator in the first model based on the abnormal power consumption data, it further includes:
[0014] Input noise variables that satisfy the distribution law of the abnormal power consumption data into the generator of the first model to obtain initial fake abnormal power consumption data, and input the initial fake abnormal power consumption data and the abnormal power consumption data into the discriminator of the first model; wherein, the discriminator is a stacked long short-term memory network;
[0015] Update the weight parameters of the generator according to the weight update situation corresponding to the loss result of the discriminator to obtain the optimal generator and discriminator, so as to generate the fake abnormal power consumption data using the optimal generator.
[0016] Optionally, the generator is a fixed generator, and the discriminator is a fixed discriminator. When the loss function of the fixed generator is the smallest and the loss function of the fixed discriminator is the largest, the fixed generator and the fixed discriminator are optimal.
[0017] Optionally, inputting the electricity consumption data to be detected into the trained second model to sequentially pass through a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism to obtain a corresponding detection result includes:
[0018] Converting the dimension of the electricity consumption data to be detected into the input dimension of the convolutional neural network, and using the convolutional neural network to perform first feature extraction on the detected electricity consumption data after dimension conversion to obtain a preliminary feature sequence;
[0019] Using the long short-term memory network to perform second feature extraction on the preliminary feature sequence to obtain a global feature sequence that fuses the front and back information features;
[0020] Using the multi-head attention mechanism constructed by the self-attention model to reassign weights to the global feature sequence, and performing weighted combination on the output features of each head in the multi-head attention mechanism to obtain a corresponding detection result.
[0021] Optionally, before using the long short-term memory network to perform second feature extraction on the preliminary feature sequence, it further includes:
[0022] Inputting the preliminary feature sequence into a Dropout layer for overfitting processing;
[0023] Inputting the preliminary feature sequence after overfitting processing into a flattening layer to convert the dimension of the preliminary feature sequence after overfitting processing into the input dimension of the long short-term memory network through the flattening layer.
[0024] Optionally, after performing weighted combination on the output features of each head in the multi-head attention mechanism, it further includes:
[0025] Using a fully connected layer to classify the features after weighted combination to obtain a mapped classification label value, and outputting a behavior type corresponding to the classification label value through an output layer.
[0026] The second aspect of the present application provides an electricity consumption data detection device, including:
[0027] An acquisition and class balance module, configured to acquire normal electricity consumption data and abnormal electricity consumption data, and generate false abnormal electricity consumption data by using a generator in the first model based on the abnormal electricity consumption data to obtain a target training set; wherein, the target training set includes first sample data composed of the normal electricity consumption data and second sample data composed of the abnormal electricity consumption data and the false abnormal electricity consumption data; the generator is a fully connected network;
[0028] A second model training module, configured to train a second model by using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism;
[0029] A model detection module, configured to input the electricity consumption data to be detected into the trained second model to sequentially pass through a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism, so as to obtain a corresponding detection result.
[0030] A third aspect of the present application provides an electronic device, which includes a processor and a memory; wherein the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the foregoing electricity consumption data detection method.
[0031] A fourth aspect of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are loaded and executed by a processor, the foregoing electricity consumption data detection method is implemented.
[0032] In the present application, first, normal electricity consumption data and abnormal electricity consumption data are obtained, and based on the abnormal electricity consumption data, a generator in the first model is used to generate false abnormal electricity consumption data to obtain a target training set; wherein, the target training set includes first sample data composed of the normal electricity consumption data and second sample data composed of the abnormal electricity consumption data and the false abnormal electricity consumption data; the generator is a fully connected network; then, the target training set is used to train a second model to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism; finally, the electricity consumption data to be detected is input into the trained second model to sequentially pass through a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism, so as to obtain a corresponding detection result. It can be seen that the present application uses the electricity consumption data after class balance processing as the training set of the second model, that is, the detection model, to avoid the detection result of the detection model being biased towards the first sample class due to data imbalance and showing misleading to the second sample class. The trained second model integrates a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism, and can improve the detection accuracy of electricity theft behavior. Description of the Drawings
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention, and for those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.
[0034] Figure 1 Flow chart of a power consumption data detection method provided for this application;
[0035] Figure 2 Schematic diagram of a specific pre - processing of power consumption data provided for this application;
[0036] Figure 3(a) is a structural diagram of a specific generator model provided for this application;
[0037] Figure 3(b) is a structural diagram of a specific discriminator model provided for this application;
[0038] Figure 4 Schematic diagram of the detection process of a CNN - BiLSTM - Attention model provided for this application;
[0039] Figure 5 Schematic diagram of the structure of a power consumption data detection device provided for this application;
[0040] Figure 6 Schematic diagram of the structure of an electronic device for power consumption data detection provided for this application. Specific embodiments
[0041] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0042] In the prior art, during the process of detecting electricity theft, due to problems such as missing values, null values, and non - linear data relationships, the existing electricity theft detection methods are difficult to process such power consumption data sets. Moreover, when detecting electricity theft behaviors, there are often problems such as large errors during training, inability to converge, and low training accuracy. In view of the above technical defects, this application provides a power consumption data detection solution, using the power consumption data after class - balance processing as the training set of the second model, that is, the detection model, to avoid the detection result of the detection model being biased towards the first sample class due to data imbalance and showing misleading to the second sample class. The trained second model integrates a convolutional neural network, a long - short - term memory network, and a multi - head attention mechanism, which can improve the detection accuracy of electricity theft behaviors.
[0043] Figure 1 Flow chart of a power consumption data detection method provided for an embodiment of this application. Refer to Figure 1 As shown, the power consumption data detection method includes:
[0044] S11: Obtain normal power consumption data and abnormal power consumption data, and generate fake abnormal power consumption data using the generator in the first model based on the abnormal power consumption data to obtain a target training set; wherein, the target training set includes first sample data composed of the normal power consumption data and second sample data composed of the abnormal power consumption data and the fake abnormal power consumption data; the generator is a fully connected network.
[0045] In this embodiment, a dataset composed of the daily power consumption data of normal users and electricity stealing users is mainly used to train the detection model in a supervised manner. The daily power consumption data of normal users and electricity stealing users are also the normal power consumption data and the abnormal power consumption data. However, since the number of normal users is much larger than that of electricity stealing users, the data is extremely imbalanced. Imbalanced data is non-uniformly distributed, which causes the detector to be biased towards the majority class, and thus be biased towards the majority class after training and show misleading to the minority class samples. In the ETD problem, this problem is more critical to handle because the identification of minority class samples is more important than that of the majority class (normal users). To address this problem, this embodiment first performs class balance processing on the dataset, and performs data preprocessing before class balance processing, and then normalizes the data to facilitate subsequent class balance processing of the data. The specific process is as Figure 2 shown, and the steps are as follows:
[0046] S111: Use the Lagrange interpolation method to fill in the missing values of the normal power consumption data and the abnormal power consumption data respectively to obtain the filled normal power consumption data and abnormal power consumption data.
[0047] S112: Use the min-max scaling method to normalize the filled normal power consumption data and abnormal power consumption data respectively to obtain the normalized normal power consumption data and abnormal power consumption data.
[0048] In this embodiment, data preprocessing is first performed on the data. During the data collection process, there is a possibility of smart meter failure, sensor failure, or data transmission and storage server failure, resulting in missing or incorrect data in the power dataset, thus affecting the training effect of the model. To solve the above problems, this embodiment uses the Lagrange interpolation method to process the missing values. Specifically, take ten data as a group and perform data interpolation processing according to the Lagrange interpolation formula. The expression is as follows:
[0049]
[0050]
[0051] In this embodiment, after dealing with missing values and outliers, since for the readings of smart meters and power consumption datasets, if the features in different dimensions show data with large differences or uneven distributions, the model will undergo long-term training and its detection performance will be affected. Therefore, it is necessary to normalize the power consumption data. The MAX-MIN scaling method can be selected to normalize the data according to the following equation:
[0052]
[0053] S113: Input the noise variables that satisfy the distribution law of the abnormal power consumption data into the generator of the first model to obtain initial false abnormal power consumption data, and input the initial false abnormal power consumption data and the abnormal power consumption data into the discriminator of the first model; wherein, the discriminator is a stacked long short-term memory network.
[0054] S114: Update the weight parameters of the generator according to the weight update situation corresponding to the loss result of the discriminator to obtain the optimal generator and discriminator, so as to use the optimal generator to generate the false abnormal power consumption data.
[0055] In this embodiment, the first model is used for class balance processing. The first model is denoted as LWGAN-GP, which uses a stacked LSTM network as the discriminator and a fully connected network as the generator. In the LWGAN-GP algorithm, the generator and the discriminator have different network structures. Using the generator network in the LWGAN-GP algorithm, false electricity theft time series are generated to obtain the distribution characteristics of false electricity theft data. The generator model is shown in Figure 3(a). Then, using the discriminator network in the LWGAN-GP algorithm, the characteristics of real data are learned. The discriminator model is shown in Figure 3(b). Finally, the generator network and the discriminator network are alternately iteratively trained, and the parameters of LWGAN-GP are updated to the optimal state to minimize the error between the generated data and the real data and reach a state where the two are indistinguishable.
[0056] Specifically, first, the discriminator (D) is trained. Its input is real electricity theft data and false electricity theft data, and the purpose is to distinguish the samples generated by the generator. After the data passes through the input layer, there is a stack composed of 3 layers of LSTM units, where the relu activation function is used in the hidden layer. Each layer has 128 neurons, and the operations are as follows:
[0057]
[0058]
[0059]
[0060] The subsequent output layer has a sigmoid activation function with a single unit. When the given input value is x test the output value of this discriminant model is interpreted as the probability that the given input comes from the true data set x true That is:
[0061] D(x test ) = Pr(x test ∈x true )
[0062] where its loss function is:
[0063]
[0064] Then the generator is trained. The generator (G) is responsible for learning the pattern of the sample distribution and generating new electricity theft data. The structure of the generator (G) is constructed by fully connected layers. At first, data of the same dimension is randomly generated according to the dimension size of the input data, and then the weights are updated according to the loss result obtained by the discriminator (D), and the relevant weight parameters of the generator are updated. Specifically, the input is the prior distribution P Z , corresponding to the random variable z, and the output is L G (θ G ), and its loss function is:
[0065]
[0066] Finally, the distribution pattern P Z of the generated data gradually fits the sample data P r (x). And through the loss function, the generator generates as realistic data as possible to confuse the discriminator. In this process, the fully connected layer accepts all the features transmitted during training and normalizes the transmitted parameters, because for data with most values distributed in a certain interval, more effective transmission can be carried out.
[0067] In this embodiment, the generator is a fixed generator, and the discriminator is a fixed discriminator. When the loss function of the fixed generator is the smallest and the loss function of the fixed discriminator is the largest, the fixed generator and the fixed discriminator are optimal. The fixed discriminator D enables the generator G to be optimized to the minimum as shown below. When both reach the optimal state, it can be ensured that the generated data conforms to the electricity consumption pattern of the real data:
[0068]
[0069]
[0070] S12: Train the second model using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism.
[0071] In this embodiment, after obtaining the target training set, the target training set is mainly used to train the second model to obtain the trained second model. The second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism, denoted as CNN-BiLSTM-Attention. Compared with other models, it is beneficial to learn basic laws and key features from large datasets. In addition, it describes stronger complex and non-linear function fitting and computing capabilities than shallow ML methods, so it is more suitable for the selection of classification tasks.
[0072] The first half is the convolutional neural network CNN for power consumption feature extraction, and the second half is the long short-term memory network BiLSTM and the multi-head attention mechanism Attention for detecting electricity theft on the extracted features. When determining the network structure, when the number of layers increases, there is a degradation problem in CNN, which is not caused by overfitting but by optimization. The network structure of CNN consists of two two-dimensional convolutional layers and one MaxPooling layer. In the model, CNN performs preliminary feature extraction on the data, the BiLSTM layer obtains global sequence features, and the multi-head attention mechanism Attention can capture the importance of feature conditions at unimportant times in the time series and is usually applied after RNN. Therefore, the attention after being calculated by the BiLSTM layer can be concentrated on the features that affect the result to improve the prediction accuracy.
[0073] S13: Input the electricity consumption data to be detected into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network, and the multi-head attention mechanism to obtain the corresponding detection result.
[0074] In this embodiment, the specific process of the second model CNN-BiLSTM-Attention processing the electricity consumption data to be detected is as Figure 4 shown, and the steps are as follows:
[0075] S131: Convert the dimension of the electricity consumption data to be detected into the input dimension of the convolutional neural network, and use the convolutional neural network to perform first feature extraction on the dimension-converted detected electricity consumption data to obtain a preliminary feature sequence.
[0076] In this embodiment, since the designed CNN is a two-dimensional convolutional layer, the data needs to be processed into two-dimensional data before input. The input data is x data =(x1, x2, x3,..., x n),x z After passing through the encoding layer, it is as follows:
[0077] x z =Encoding(x data )=(x1, x2, x3, …, x n ), x n ∈[0, 1]
[0078] The one-dimensional electricity consumption data dimension (1, 1036) of the input is processed into a dimension of (7, 148) according to the period, as follows:
[0079]
[0080] Use the CNN layer to extract high-level features from the input two-dimensional electricity consumption data. At the same time, the pooling layer selects the maximum pooling layer dimension (2, 2), which can effectively eliminate redundant data and will reduce the parameters of the dimension and further extract features. After passing through the convolutional layer, Conv(f(x i,j )) has a dimension of (Noe, 142, 5). The calculation formula of the pooling layer is as follows: Pool(Conv(f(x i,j ))), with a dimension of (None, 71, 2).
[0081] The activation function is such that it only activates positive values, and the function of this activation function can effectively prevent overfitting. The specific formula is as follows:
[0082]
[0083] Where None is the size of each batch, n and m are the total number of rows and columns of the input matrix, or the dimension of the last dimension of the tensor. x i,j represents the data at the i-th row and j-th column of the matrix. w i,j represents the weight at the i-th row and j-th column of the convolution kernel. f(i, j) is the eigenvalue of the corresponding position element of the output matrix corresponding to the convolution kernel w. relu(.) represents the linear activation function, and the bias vector is represented as b.
[0084] S132: Use the long short-term memory network to perform second feature extraction on the preliminary feature sequence to obtain a global feature sequence that fuses the front and back information features.
[0085] In this embodiment, before inputting into the long short-term memory network, the preliminary feature sequence needs to be input into the Dropout layer for overfitting processing, and then the overfitted preliminary feature sequence is input into the Flatten layers, so as to convert the dimension of the overfitted preliminary feature sequence into the input dimension of the long short-term memory network through the Flatten layer. It is found during training that as the number of iterations increases, the network fits the training set well (the loss on the training set is very small), but the fitting degree for the validation set is very poor. Therefore, an overfitting layer is added to solve the overfitting problem. Since the input data is two-dimensional data, in order to conform to the input of the next BiLSTM layer, the dimension of the two-dimensional data needs to be processed into one dimension, and one dimension needs to be added column by column. The role of the Flatten layer is to process multi-dimensional data into one dimension. Assuming the input is y, then flatten=(y, 71*2)=(None, y, 144). On this basis, a dimension with a value of 1 is added, extend(flatten)=(None, y, 1, 144). The processed data dimension is input into the BiLSTM layer.
[0086] In this embodiment, the BiLSTM layer further extracts feature information from the feature sequence obtained from the convolutional layer. Since the BiLSTM network is fused by forward and backward LSTMs, it can capture front and back information features. In order to obtain the correlation information between electricity consumption data, BiLSTM is used to capture the electricity consumption time series features. The input of BiLSTM is the output vector of the Flatten layer, denoted as y t =(y1, y2, y3, …, y n ), and each dimension is (None, y1, 1, 144). The internal update of BiLSTM is as follows:
[0087] i t =Act(W i y t +U i h t-1 +bia i ),
[0088] f t =Act(W f y t +U f h t-1 +bia f ),
[0089] o t =Act(W o y t +U o h t-1 +bia o ),
[0090] The above three formulas screen and retain the information of the features and provide it to formula C t Retain the screened features.
[0091] C t = f t * C t-1 + i t * tanh(W c y t + U c h t-1 + bia c ),
[0092] h t = o t * tanh(C t ),
[0093]
[0094] After passing through the activation function tanh in formulas h t and H t the final feature information is obtained.
[0095] where * represents element-wise multiplication, x i represents the input, Act(x) is the activation function, i t and f t and o t respectively represent the input gate, forget gate, and output gate of the LSTM, C t respectively represent the memory cell of the LSTM, h t , respectively represent the hidden state of the LSTM, the hidden state of the forward LSTM, and the hidden state of the backward LSTM, and W and U are weight matrices, bia f , bia o , bia c and bia i are bias vectors, H t represents the output of the LSTM hidden state.
[0096] S133: Reassign weights to the global feature sequence using the multi-head attention mechanism constructed by the self-attention model, and perform weighted merging on the output features of each head in the multi-head attention mechanism to obtain the corresponding detection result.
[0097] In this implementation, the attention mechanism is used to reassign different weights to the output features of the BiLSTM. This embodiment adopts a multi-head attention mechanism composed of a series of self-attention models. With the same data input, Q, K, and V are three fixed values, which are respectively mapped through a Linear layer. There are 3 Linear layers. The attention scoring function used is Scaled Dot-ProductAttention. Having 3 means there are 3 heads. The scoring function is ρ(H t ) to learn and assign weights M = ρ(H t ) that signify the importance of time steps. Finally, the outputs of each head are concatenated together and then mapped through a Linear layer into an output similar to that of a single head. The expression of the self-attention mechanism is as follows:
[0098]
[0099]
[0100] Among them, W, W i q , represent the weight matrices of the linear layers. Q = K = V = H t . Each head is an attention, and the feature information filtered by each head is different, which is beneficial for the final model to achieve better results.
[0101] Finally, the fully connected layer is used to classify the weighted combined features to obtain the mapped classification label values, and the behavior types corresponding to the classification label values are output through the output layer. The fully connected layer acts as a classifier in the entire network model, mapping the learned power consumption features to the sample label space. A fully connected layer with a length of 1024 is added to change the shape to (1024), and then smaller fully connected layers are stacked below. Finally, since it is a binary classification problem, a fully connected layer with a sigmoid as the output layer is used to classify the target. Since there are only two categories, electricity theft users and normal users, the labels of electricity theft users and normal users in the dataset are defined as 1 and 0. Therefore, the output will judge whether an electricity theft behavior occurs according to the learned feature curve. If the output result of the output layer is 1, then it is considered that the user has committed an electricity theft behavior.
[0102] It can be seen that in the embodiment of the present application, the normal power consumption data and the abnormal power consumption data are first obtained, and the false abnormal power consumption data is generated by using the generator in the first model based on the abnormal power consumption data to obtain the target training set; wherein, the target training set includes the first sample data composed of the normal power consumption data and the second sample data composed of the abnormal power consumption data and the false abnormal power consumption data; the generator is a fully connected network; then the second model is trained by using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network and a multi-head attention mechanism; finally, the power consumption data to be detected is input into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network and the multi-head attention mechanism to obtain the corresponding detection result. In the embodiment of the present application, the power consumption data after class balance processing is used as the training set of the second model, that is, the detection model, to avoid the detection result of the detection model being biased towards the first sample class due to data imbalance and showing misleading to the second sample class. The trained second model integrates a convolutional neural network, a long short-term memory network and a multi-head attention mechanism, which can improve the detection accuracy of electricity theft behavior.
[0103] See Figure 5 As shown, the embodiment of the present application also correspondingly discloses a power consumption data detection device, including:
[0104] An acquisition and class balance module 11, configured to acquire normal power consumption data and abnormal power consumption data, and generate false abnormal power consumption data by using the generator in the first model based on the abnormal power consumption data to obtain a target training set; wherein, the target training set includes the first sample data composed of the normal power consumption data and the second sample data composed of the abnormal power consumption data and the false abnormal power consumption data; the generator is a fully connected network;
[0105] A second model training module 12, configured to train the second model by using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network and a multi-head attention mechanism;
[0106] A model detection module 13, configured to input the power consumption data to be detected into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network and the multi-head attention mechanism to obtain the corresponding detection result.
[0107] It can be seen that in the embodiment of the present application, the normal power consumption data and the abnormal power consumption data are first obtained, and based on the abnormal power consumption data, the generator in the first model is used to generate false abnormal power consumption data to obtain a target training set; wherein, the target training set includes first sample data composed of the normal power consumption data and second sample data composed of the abnormal power consumption data and the false abnormal power consumption data; the generator is a fully connected network; then the target training set is used to train the second model to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network and a multi-head attention mechanism; finally, the power consumption data to be detected is input into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network and the multi-head attention mechanism to obtain a corresponding detection result. In the embodiment of the present application, the power consumption data after class balance processing is used as the training set of the second model, that is, the detection model, to avoid the detection result of the detection model being biased towards the first sample class due to data imbalance and showing misleading to the second sample class. The trained second model integrates a convolutional neural network, a long short-term memory network and a multi-head attention mechanism, which can improve the detection accuracy of electricity theft behavior.
[0108] In some specific embodiments, the power consumption data detection device further includes:
[0109] A preprocessing module, configured to respectively perform missing value filling processing on the normal power consumption data and the abnormal power consumption data by using the Lagrange interpolation method to obtain the filled normal power consumption data and abnormal power consumption data;
[0110] A normalization module, configured to respectively perform normalization processing on the filled normal power consumption data and abnormal power consumption data by using the minimum-maximum scaling method to obtain the normalized normal power consumption data and abnormal power consumption data.
[0111] A first model training module, configured to input a noise variable that satisfies the distribution law of the abnormal power consumption data into the generator of the first model to obtain initial false abnormal power consumption data, and input the initial false abnormal power consumption data and the abnormal power consumption data into the discriminator of the first model; wherein, the discriminator is a stacked long short-term memory network; update the weight parameters of the generator according to the weight update situation corresponding to the loss result of the discriminator to obtain the optimal generator and discriminator, so as to generate the false abnormal power consumption data by using the optimal generator.
[0112] In some specific embodiments, the model detection module 13 specifically includes:
[0113] The first detection unit is configured to convert the dimension of the electricity consumption data to be detected into the input dimension of a convolutional neural network, and use the convolutional neural network to perform first feature extraction on the dimension-converted electricity consumption data to obtain a preliminary feature sequence;
[0114] The second detection unit is configured to perform second feature extraction on the preliminary feature sequence by using a long short-term memory network to obtain a global feature sequence that integrates front and back information features;
[0115] The third detection unit is configured to reassign weights to the global feature sequence by using a multi-head attention mechanism constructed by a self-attention model, and perform weighted combination on the output features of each head in the multi-head attention mechanism to obtain a corresponding detection result.
[0116] Furthermore, an embodiment of the present application also provides an electronic device. Figure 6 It is a structural diagram of an electronic device 20 shown according to an exemplary embodiment, and the content in the figure should not be considered as any limitation to the scope of use of the present application.
[0117] Figure 6 This is a schematic structural diagram of an electronic device 20 provided by an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the electricity consumption data detection method disclosed in any of the foregoing embodiments.
[0118] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows is any communication protocol applicable to the technical solution of the present application, and no specific limitation is imposed on it here; the input / output interface 25 is used to obtain external input data or output data to the outside, and its specific interface type can be selected according to specific application needs, and no specific limitation is made here.
[0119] In addition, as a carrier for resource storage, the memory 22 may be a read-only memory, a random access memory, a magnetic disk, or an optical disc, etc. The resources stored thereon may include an operating system 221, a computer program 222, and data 223, etc., and the storage method may be short-term storage or permanent storage.
[0120] Among them, the operating system 221 is used to manage and control each hardware device on the electronic device 20 and the computer program 222, so as to implement the operation and processing of the massive data 223 in the memory 22 by the processor 21. It can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program that can be used to complete the power consumption data detection method executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs that can be used to complete other specific tasks. The data 223 may include the power consumption data collected by the electronic device 20.
[0121] Furthermore, an embodiment of the present application also discloses a storage medium in which a computer program is stored. When the computer program is loaded and executed by a processor, the steps of the power consumption data detection method disclosed in any of the foregoing embodiments are implemented.
[0122] In this specification, the various embodiments are described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method part.
[0123] Finally, it should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.
[0124] The power consumption data detection method, device, equipment and storage medium provided by the present invention have been introduced in detail above. Specific examples are used in this article to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.
Claims
1. A method for detecting power consumption data, characterized in that Including: Obtain normal power consumption data and abnormal power consumption data, and generate false abnormal power consumption data by using the generator in the first model based on the abnormal power consumption data to obtain a target training set; wherein, the target training set includes first sample data composed of the normal power consumption data and second sample data composed of the abnormal power consumption data and the false abnormal power consumption data; the generator is a fully connected network; wherein, the discriminator of the first model is a stacked long short-term memory network, and by alternately iteratively training the generator and the discriminator, the data distribution of the generator gradually fits the true distribution of the abnormal power consumption data; Train a second model by using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism; Input the power consumption data to be detected into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network, and the multi-head attention mechanism to obtain corresponding detection results, including: converting the dimension of the power consumption data to be detected into the input dimension of the convolutional neural network, and using the convolutional neural network to perform first feature extraction on the detected power consumption data after dimension conversion to obtain a preliminary feature sequence; using the long short-term memory network to perform second feature extraction on the preliminary feature sequence to obtain a global feature sequence integrating front and back information features; using the multi-head attention mechanism constructed by the self-attention model to reassign weights to the global feature sequence, and performing weighted combination on the output features of each head in the multi-head attention mechanism to obtain the corresponding detection results; Before generating the false abnormal power consumption data by using the generator in the first model based on the abnormal power consumption data, it further includes: inputting a noise variable satisfying the distribution law of the abnormal power consumption data into the generator of the first model to obtain initial false abnormal power consumption data, and inputting the initial false abnormal power consumption data and the abnormal power consumption data into the discriminator of the first model; updating the weight parameters of the generator according to the weight update situation corresponding to the loss result of the discriminator to obtain the optimal generator and discriminator, so as to generate the false abnormal power consumption data by using the optimal generator.
2. The power consumption data detection method according to claim 1, wherein After obtaining the normal power consumption data and the abnormal power consumption data, it further includes: Adopt the Lagrange interpolation method to respectively perform missing value filling processing on the normal power consumption data and the abnormal power consumption data to obtain the filled normal power consumption data and the abnormal power consumption data; Adopt the min-max scaling method to respectively perform normalization processing on the filled normal power consumption data and the abnormal power consumption data to obtain the normalized normal power consumption data and the abnormal power consumption data.
3. The power consumption data detection method according to claim 1, wherein The generator is a fixed generator, and the discriminator is a fixed discriminator. When the loss function of the fixed generator is the smallest and the loss function of the fixed discriminator is the largest, the fixed generator and the fixed discriminator are optimal.
4. The power consumption data detection method according to claim 1, characterized in that Before the second feature extraction of the preliminary feature sequence using the long short-term memory network, the following steps are further included: Input the preliminary feature sequence into a Dropout layer for overfitting processing; Input the preliminary feature sequence after overfitting processing into a flattening layer to convert the dimension of the preliminary feature sequence after overfitting processing into the input dimension of the long short-term memory network through the flattening layer.
5. The power consumption data detection method according to claim 1, characterized in that, After the output features of each head in the multi-head attention mechanism are weighted and combined, the following steps are further included: Use a fully connected layer to classify the features after weighted combination to obtain the mapped classification label value, and output the corresponding behavior type through the output layer.
6. A power consumption data detection device, characterized in that, It includes: An acquisition and class balance module, which is used to acquire normal power consumption data and abnormal power consumption data, and generate false abnormal power consumption data based on the abnormal power consumption data using the generator in the first model to obtain a target training set; wherein, the target training set includes first sample data composed of the normal power consumption data and second sample data composed of the abnormal power consumption data and the false abnormal power consumption data; the generator is a fully connected network; wherein, the discriminator of the first model is a stacked long short-term memory network, and by alternately iteratively training the generator and the discriminator, the data distribution of the generator gradually fits the true distribution of the abnormal power consumption data; A second model training module, which is used to train the second model using the target training set to obtain the trained second model; wherein, the second model is composed of a convolutional neural network, a long short-term memory network, and a multi-head attention mechanism; A model detection module, which is used to input the power consumption data to be detected into the trained second model to sequentially pass through the convolutional neural network, the long short-term memory network, and the multi-head attention mechanism to obtain the corresponding detection result; The model detection module is specifically used to convert the dimension of the power consumption data to be detected into the input dimension of the convolutional neural network, and use the convolutional neural network to perform first feature extraction on the detected power consumption data after dimension conversion to obtain a preliminary feature sequence; use the long short-term memory network to perform second feature extraction on the preliminary feature sequence to obtain a global feature sequence integrating front and back information features; use the multi-head attention mechanism constructed by the self-attention model to reassign weights to the global feature sequence, and perform weighted combination on the output features of each head in the multi-head attention mechanism to obtain the corresponding detection result; Before generating the false abnormal power consumption data by using the generator in the first model based on the abnormal power consumption data, the power consumption data detection device further includes a first model training module, which is configured to input a noise variable that meets the distribution law of the abnormal power consumption data into the generator of the first model to obtain initial false abnormal power consumption data, and input the initial false abnormal power consumption data and the abnormal power consumption data into the discriminator of the first model; wherein, the discriminator is a stacked long short-term memory network; the weight parameters of the generator are updated according to the weight update situation corresponding to the loss result of the discriminator to obtain the optimal generator and discriminator, so as to generate the false abnormal power consumption data by using the optimal generator.
7. An electronic device, characterized in that, The electronic device includes a processor and a memory; wherein the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the power consumption data detection method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, For storing computer-executable instructions, when the computer-executable instructions are loaded and executed by a processor, the power consumption data detection method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Electrocardiosignal identification method based on generative adversarial networks and convolution recurrent neural networks
CN111990989A
User electricity stealing detection method based on improved generative adversarial network
CN113780402A
Data poisoning attack-oriented electricity stealing detection method
CN114239725A