A power stealing detection method based on stacked sparse autoencoder and deep forest
By combining stacked sparse autoencoders and deep forest models, the 'curse of dimensionality' problem in high-dimensional electricity data processing is solved, improving the accuracy of electricity theft detection and reducing non-technical line losses.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- STATE GRID JIANGSU ELECTRIC POWER CO LTD RESEARCH INSTITUTE
- Filing Date
- 2022-12-19
- Publication Date
- 2026-05-29
Smart Images

Figure CN115827709B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of non-technical line loss reduction, and specifically relates to a method for detecting electricity theft based on stacked sparse autoencoders and deep forests. Background Technology
[0002] Actual line losses in power grid operation are divided into two parts: technical line losses and non-technical line losses. Technical line losses mainly consist of losses in lines and transformers, while non-technical line losses, also known as management line losses, are mainly caused by electricity theft by users. Electricity theft accounts for up to 6% of the total line losses in the State Grid, seriously affecting the economic operation of the grid. Furthermore, non-technical line losses can also affect the calculation of grid operating parameters, thus jeopardizing the stability of grid operation. Therefore, it is necessary to take relevant measures to identify electricity theft users to reduce non-technical line losses.
[0003] Research on electricity theft detection mainly includes high-dimensional data processing, handling class imbalance problems, and anomaly detection model improvement. High-dimensional data is prone to the "curse of dimensionality," severely impacting the accuracy of detection models. Common methods for processing high-dimensional data involve dimensionality reduction, but excessive dimensionality reduction can lead to significant loss of user electricity consumption information. Therefore, the key to solving the problem lies in preserving as much user electricity consumption information as possible while reducing dimensionality. Traditional approaches to high-dimensional data processing, such as machine learning algorithms, support vector machines, decision trees, and ensemble tree models, cannot achieve this goal. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a method for detecting electricity theft based on stacked sparse autoencoders and deep forests. The electricity theft model based on stacked sparse autoencoders and deep forests reduces the dimensionality of electricity consumption data, extracts effective information from high-dimensional electricity consumption data, and performs electricity theft detection. This solves the "curse of dimensionality" problem caused by high-dimensional electricity consumption data, improves the recognition accuracy of the electricity theft detection model, and thus more effectively reduces non-technical line losses.
[0005] The specific technical solution of the present invention is as follows:
[0006] A method for detecting electricity theft based on stacked sparse autoencoders and deep forests includes the following steps:
[0007] S1: Extract user electricity consumption data from the smart power distribution database and construct a user electricity consumption feature dataset;
[0008] S2: Divide the user electricity consumption feature dataset into a training set and a test set according to a certain proportion;
[0009] S3: Use the training set as input to train the electricity theft detection model;
[0010] S4: Test the electricity theft detection model trained in step S3 using the test set, and construct a confusion matrix based on the test results;
[0011] S5: Evaluate the test results of the electricity theft detection model using accuracy, recall, and F1 score respectively.
[0012] Preferably, in step S2, the user electricity consumption feature dataset is divided into a training set and a test set in a ratio of 7:3.
[0013] Preferably, the electricity theft model in S3 includes a stacked sparse autoencoder and a deep forest model, and the output of the stacked sparse autoencoder is the input of the deep forest model, wherein,
[0014] The stacked sparse autoencoder is composed of multiple sparse autoencoders stacked together, and the loss function L of each sparse autoencoder layer is as shown in formula (1):
[0015]
[0016] Where, x i Let i be the feature vector of the i-th real user electricity consumption. Let be the feature vector of the i-th user reconstructed by a single-layer sparse autoencoder, m be the number of input users, β be a constant factor, and Ω be the feature vector of the i-th user. sparse The sparsity constraint term is shown in formula (2):
[0017]
[0018] In equation (2), KL represents the KL divergence, ρ is a constant approaching zero, and S m ρ represents the number of hidden layer neurons in each sparse autoencoder layer. j Let be the activation level of the j-th neuron, as shown in formula (3):
[0019]
[0020] In equation (3), This is the vector encoded by the j-th neuron for the electricity consumption feature vector of the i-th user;
[0021] Preferably, the number of layers of the stacked sparse autoencoder is determined by constructing an objective function, wherein the objective function is shown in equation (4):
[0022]
[0023] Among them, E SSAE For the overall reconstruction error of stacked sparse autoencoders, L uLet be the reconstruction error of the u-th sparse autoencoder, and M be the number of layers of the stacked sparse autoencoder.
[0024] Preferably, the deep forest model includes a multi-granularity feature scanning module and a cascaded forest module, and the output of the stacked sparse autoencoder is the input of the multi-granularity feature scanning module, and the output of the multi-granularity feature scanning module is the input of the cascaded forest module.
[0025] Preferably, the specific training steps of the electricity theft detection model in S3 are as follows:
[0026] S3-1: Use stacked sparse autoencoders to extract features from user electricity consumption feature vectors in the training set. Use user electricity consumption feature vectors as input to the first layer of sparse autoencoders in the stacked sparse autoencoders. Use the hidden layer output feature vector of the first layer of sparse autoencoders as input to the second layer of sparse autoencoders. And so on, continuously compress the output feature vector of the hidden layer of the sparse autoencoders until the value of the objective function shown in formula (4) is less than the overall reconstruction error threshold, so as to output the feature vector h that best represents the user electricity consumption pattern.
[0027] S3-2: The multi-granularity feature scanning module of the deep forest algorithm scans the feature vector h output in step S3-1 to achieve multi-precision extraction of user features;
[0028] S3-3: The cascaded forest module using the deep forest algorithm enables deep fusion of user features and identification of electricity theft.
[0029] Preferably, the specific method for multi-precision extraction of user features by the multi-granularity feature scanning module in S3-2 is as follows:
[0030] The multi-granularity feature scanning module includes two channels, each of which uses a random forest and a fully random forest for feature extraction, respectively. Let the sliding vector used for feature extraction have dimension d and a sliding step size s. Let a user's feature vector h have dimension h. dim After single-granularity feature scanning, q vectors of length d are obtained. The formula for calculating q is shown in formula (5):
[0031]
[0032] Inputting q vectors into a fully random forest or a random forest will both result in q two-dimensional vectors. Concatenating 2q two-dimensional vectors vertically will yield a vector of length 4q.
[0033] Similarly, keeping the dimensions of the sliding vector constant, we set the sliding step matrix to S = [s1, s2, s3...s...]. lThe sliding vector uses multiple step sizes to achieve multi-granularity feature scanning of a single user's electricity consumption feature vector, specifically:
[0034] Let the step size of the first channel be s. l The scan vector is divided according to the step size s l The vector set obtained during the scan is denoted as matrix Q. l According to equation (5), Q can be known l The dimension is q l *d, similarly, Q will be in the first channel. l By inputting the data into a fully random forest and a random forest, and then performing vertical concatenation, a result of length 4q can be obtained. l The vector is the output feature vector v after the output feature vector h has undergone multi-granularity feature scanning. l Let the step size of the second channel be s. l-1 Then, the output feature vector v obtained after scanning the input feature vector h is... l-1 The dimension is 4q l-1 .
[0035] Preferably, the specific method for deep feature fusion and electricity theft behavior identification in the S3-3 cascaded forest module is as follows:
[0036] S3-31: Convert the output feature vector v of the first channel l If the input is fed into the first layer of a cascaded forest, the output vector dimension will be 2n. f1 , where n f1 Let v be the number of random forests and fully random forests contained in the first layer of the cascaded forest. Then, the output vector of the first layer of the cascaded forest is compared with the output feature vector v. l The first feature fusion is achieved by concatenating the features, resulting in a fused feature vector. Its dimension is 2n f1 +4q l ;
[0037] S3-32: Fusing feature vectors The input is fed into the second layer of the cascaded forest, and the output vector has a dimension of 2n. f2 , where n f2 Let v be the number of random forests and fully random forests contained in the second layer of the cascaded forest. Then, the output vector of the second layer of the cascaded forest is compared with the output feature vector v. l-1 The features are concatenated to achieve a second feature fusion, resulting in a fused feature vector. Dimension 2n f2 +4q l-1 ;
[0038] S3-33: Fusing feature vectors When the input is fed into the third layer of a cascaded forest, the output vector dimension is 2n.f3 , where n f3 Let v be the number of random forests and fully random forests contained in the third layer of the cascaded forest. Then, the output vector of the third layer of the cascaded forest is compared with the output feature vector v. l The feature vector is obtained by concatenating the features for the third time. Its dimension is 2n f3 +4q l ;
[0039] S3-34: Fuse the feature vector v l 2 The input is fed into the fourth layer of the cascaded forest, and the output vector has a dimension of 2n. f4 , where n f4 Let v be the number of random forests and fully random forests contained in the fourth layer of the cascaded forest. Then, the output vector of the fourth layer of the cascaded forest is compared with the output feature vector v. l-1 The features are concatenated to achieve the fourth feature fusion, resulting in a fused feature vector. Dimension 2n f4 +4q l-1 ;
[0040] S3-35: Fusing feature vectors The input is fed into the electricity theft detection layer, and the output is the electricity theft detection result for each random forest or fully random forest, denoted as p, with a dimension of 2n. f5 , where n f5 Let p be the number of random forests and fully random forests contained in the electricity theft detection layer. After averaging and taking the maximum and minimum values of p, the electricity theft detection results can be obtained.
[0041] Preferably, the confusion matrix content in S4 includes:
[0042] If a user in the test set is actually a normal user and is identified as a normal user, the count is TN; if the user is identified as an abnormal user, the count is FP.
[0043] If a user in the test set is actually an abnormal user but is identified as a normal user, the count is FN; if the user is identified as an abnormal user, the count is TP.
[0044] Preferably, in step S5,
[0045] The formula for calculating the accuracy is shown in equation (6):
[0046]
[0047] The formula for calculating the recall rate is shown in equation (7):
[0048]
[0049] The formula for calculating the accuracy is shown in equation (8):
[0050]
[0051] The F1 score is calculated based on accuracy, recall, and precision, as shown in formula (9):
[0052]
[0053] Beneficial effects: This invention discloses a method for detecting electricity theft based on stacked sparse autoencoders and deep forests, which solves the "curse of dimensionality" problem caused by high-dimensional electricity consumption data, improves the recognition accuracy of the electricity theft detection model, and thus more effectively reduces non-technical line losses. Attached Figure Description
[0054] Figure 1 This is a flowchart of the electricity theft detection model of the present invention;
[0055] Figure 2 This is a diagram of a stacked sparse autoencoder structure.
[0056] Figure 3 This is a diagram of a sparse autoencoder structure.
[0057] Figure 4 This is a diagram of the deep forest structure.
[0058] Figure 5 This refers to the reconstruction error of the first layer sparse autoencoder in Example 1;
[0059] Figure 6 This refers to the reconstruction error of the second-layer sparse autoencoder in Example 1. Detailed Implementation
[0060] The present invention will now be described with reference to the accompanying drawings, and these improvements and modifications should also be considered within the scope of protection of the present invention.
[0061] Example 1
[0062] A method for detecting electricity theft based on stacked sparse autoencoders and deep forests includes the following steps:
[0063] S1: Extract user electricity consumption data from the smart power distribution database to construct a user electricity consumption feature dataset. In this embodiment 1, the selected user electricity consumption dataset is provided by a power company. This dataset contains electricity consumption data for 4064 users, each marked as either using electricity normally or stealing electricity. Among them, there are 2030 normal users and 2034 users who steal electricity. The time span of each user's electricity consumption record is from February 2019 to September 2019, a total of 252 days.
[0064] S2: Divide the user electricity consumption feature dataset into a training set and a test set in a 7:3 ratio.
[0065] S3: Use the training set as input to the electricity theft detection model, according to... Figure 1 The flowchart shown illustrates the training of an electricity theft detection model. The electricity theft detection model includes a stacked sparse autoencoder and a deep forest model, and the output of the stacked sparse autoencoder is the input of the deep forest model. The stacked sparse autoencoder is composed of multiple sparse autoencoders stacked together, and the loss function L of each sparse autoencoder layer is shown in formula (1).
[0066]
[0067] Where, x i Let i be the feature vector of the i-th real user electricity consumption. Let be the feature vector of the i-th user reconstructed by a single-layer sparse autoencoder, b be the number of input users, β be a constant factor, and Ω be the feature vector of the i-th user. sparse The sparsity constraint term is shown in formula (2):
[0068]
[0069] In equation (2), KL represents the KL divergence, ρ is a constant approaching zero, and S m ρ represents the number of hidden layer neurons in each sparse autoencoder layer. j Let be the activation level of the j-th neuron, as shown in formula (3):
[0070]
[0071] In equation (3), This is the vector encoded by the j-th neuron for the electricity consumption feature vector of the i-th user;
[0072] The stacked sparse autoencoder determines the number of layers and the dimension of the latent feature vector by constructing an objective function, where the objective function is shown in Equation (4):
[0073] The objective function is shown in equation (4):
[0074]
[0075] Among them, E SSAE For the overall reconstruction error of stacked sparse autoencoders, L u Let be the reconstruction error of the u-th sparse autoencoder, and M be the number of layers of the stacked sparse autoencoder.
[0076] In this embodiment 1, the structure of the stacked sparse autoencoder is determined using a layer-by-layer method. First, consider the case of a single sparse autoencoder; as the dimension of the latent feature vector changes, E... SSAE The trend of change is as follows Figure 5 As shown, when the hidden layer output dimension (which is also the output feature vector dimension) is 60, an inflection point occurs, meaning that further increasing the dimension does not significantly improve the feature extraction effect. Therefore, the hidden layer feature vector dimension of this sparse autoencoder is set to 60. When the feature vector dimension is 60, E... SSAE The overall reconstruction error threshold is less than 0.2 (this can be set according to actual conditions). Therefore, another sparse autoencoder needs to be added, forming a stacked sparse autoencoder with the previous one. Similarly, the dimension of the hidden layer output feature vector and E can be plotted. SSAE Relationship diagram, such as Figure 6 As shown, when the dimension of the feature vector output by the hidden layer of the autoencoder is 45, the curve shows an inflection point, and at this time E SSAE The value is 0.195, which is less than the overall reconstruction error threshold of 0.2. Therefore, the number of layers of the stacked autoencoder is set to 2. The output dimension of the hidden layer of the first sparse autoencoder is 60, and the output dimension of the hidden layer of the second sparse autoencoder is 45, that is, the output feature vector h is 45.
[0077] In this embodiment 1, as Figure 4 As shown, the deep forest model includes a multi-granularity feature scanning module and a cascaded forest module, and the output of the stacked sparse autoencoder is the input of the multi-granularity feature scanning module, and the output of the multi-granularity feature scanning module is the input of the cascaded forest module.
[0078] The specific training steps for the electricity theft detection model in Example 1 are as follows:
[0079] S3-1: The user electricity consumption feature vector in the training set is extracted by using a stacked sparse autoencoder. The user electricity consumption feature vector is used as the input of the first layer of the stacked sparse autoencoder. The hidden layer output feature vector of the first layer of the sparse autoencoder is used as the input of the second layer of the sparse autoencoder. This process is repeated to continuously compress the output feature vector of the hidden layer of the sparse autoencoder until the value of the objective function shown in formula (4) is less than the overall reconstruction error threshold (the threshold is 0.2 in this embodiment). In this way, the feature vector h that best represents the user electricity consumption pattern is output.
[0080] S3-2: The multi-granularity feature scanning module of the deep forest algorithm scans the feature vector h output in step S3-1 to achieve multi-precision extraction of user features;
[0081] S3-3: The cascaded forest module using the deep forest algorithm enables deep fusion of user features and identification of electricity theft.
[0082] S3-2: The multi-granularity feature scanning module of the deep forest algorithm scans the feature vector h output in step S3-1 to achieve multi-precision extraction of user features. The specific method is as follows:
[0083] The multi-granularity feature scanning module includes two channels, each of which uses a random forest and a fully random forest for feature extraction, respectively. Let the sliding vector used for feature extraction have dimension d and a sliding step size s. Let a user's feature vector h have dimension h. dim After single-granularity feature scanning, q vectors of length d are obtained. The formula for calculating q is shown in formula (5):
[0084]
[0085] Inputting q vectors into a fully random forest or a random forest will both result in q two-dimensional vectors. Concatenating 2q two-dimensional vectors vertically will yield a vector of length 4q.
[0086] Similarly, keeping the dimensions of the sliding vector constant, we set the sliding step matrix to S = [s1, s2, s3...s...]. l The sliding vector uses multiple step sizes to achieve multi-granularity feature scanning of a single user's electricity consumption feature vector, specifically:
[0087] Let the step size of the first channel be s. l The scan vector is divided according to the step size s l The vector set obtained during the scan is denoted as matrix Q. l According to equation (5), Q can be known l The dimension is q l *d, similarly, Q will be in the first channel. l By inputting the data into a fully random forest and a random forest, and then performing vertical concatenation, a result of length 4q can be obtained. l The vector is the output feature vector v after the output feature vector h has undergone multi-granularity feature scanning. l Let the step size of the second channel be s. l-1 Then, the output feature vector v obtained after scanning the input feature vector h is... l-1 The dimension is 4q l-1 .
[0088] In this embodiment 1, by using different sliding step sizes, feature vectors of different lengths can be obtained, thereby achieving multi-precision extraction of user features.
[0089] S3-3: A cascaded forest module using the deep forest algorithm is employed to achieve deep fusion of user features and identification of electricity theft. The specific method is as follows:
[0090] S3-31: Convert the output feature vector v of the first channel l If the input is fed into the first layer of a cascaded forest, the output vector dimension will be 2n. f1 , where n f1 Let v be the number of random forests and fully random forests contained in the first layer of the cascaded forest. Then, the output vector of the first layer of the cascaded forest is compared with the output feature vector v. l The first feature fusion is achieved by concatenating the features, resulting in a fused feature vector. Its dimension is 2n f1 +4q l ;
[0091] S3-32: Fusing feature vectors The input is fed into the second layer of the cascaded forest, and the output vector has a dimension of 2n. f2 , where n f2 Let v be the number of random forests and fully random forests contained in the second layer of the cascaded forest. Then, the output vector of the second layer of the cascaded forest is compared with the output feature vector v. l-1 The features are concatenated to achieve a second feature fusion, resulting in a fused feature vector. Dimension 2n f2 +4q l-1 ;
[0092] S3-33: Fusing feature vectors When the input is fed into the third layer of a cascaded forest, the output vector dimension is 2n. f3 , where n f3 Let v be the number of random forests and fully random forests contained in the third layer of the cascaded forest. Then, the output vector of the third layer of the cascaded forest is compared with the output feature vector v. l The feature vector is obtained by concatenating the features for the third time. Its dimension is 2n f3 +4q l ;
[0093] S3-34: Fuse the feature vector v l 2 The input is fed into the fourth layer of the cascaded forest, and the output vector has a dimension of 2n. f4 , where n f4 Let v be the number of random forests and fully random forests contained in the fourth layer of the cascaded forest. Then, the output vector of the fourth layer of the cascaded forest is compared with the output feature vector v. l-1 The features are concatenated to achieve the fourth feature fusion, resulting in a fused feature vector. Dimension 2n f4 +4q l-1 ;
[0094] S3-35: Fusing feature vectors The input is fed into the electricity theft detection layer, and the output is the electricity theft detection result for each random forest or fully random forest, denoted as p, with a dimension of 2n. f5 , where n f5 Let p be the number of random forests and fully random forests contained in the electricity theft detection layer. After averaging and taking the maximum and minimum values of p, the electricity theft detection results can be obtained.
[0095] In this implementation 1, the hyperparameter settings of the constructed deep forest algorithm are shown in Table 1:
[0096] Table 1 Hyperparameter settings for the Deep Forest algorithm
[0097]
[0098] S4: Test the electricity theft detection model trained in step S3 using the test set, and construct the confusion matrix as shown in Table 2 based on the test results:
[0099] Table 2 Confusion Matrix
[0100] category Identified as a normal user Identified as an abnormal user Actually a normal user TN FP Actually an abnormal user FN TP
[0101] S5: Evaluate the test results of the electricity theft detection model using precision, recall, and F1 score, respectively.
[0102] The formula for calculating the accuracy is shown in equation (6):
[0103]
[0104] The formula for calculating the recall rate is shown in equation (7):
[0105]
[0106] The formula for calculating the accuracy is shown in equation (8):
[0107]
[0108] The F1 score is calculated based on accuracy, recall, and precision, as shown in formula (9):
[0109]
[0110] Model comparison test
[0111] The electricity theft detection models in Example 1 (SSAE + Deep Forest), Deep Forest, SSAE + Support Vector Machine, SSAE + Decision Tree, SSAE + Random Forest, and SSAE + XGBoost were tested respectively. The test results of each detection model were evaluated using the S4-S5 evaluation method, and the specific evaluation results are shown in Table 3.
[0112] Table 3 Evaluation results of different detection models
[0113] Detection model accuracy Recall rate F1 score SSAE+Deep Forest 0.821 0.800 0.817 Deep Forest 0.762 0.700 0.781 SSAE+ Support Vector Machine 0.700 0.738 0.712 SSAE+ Decision Tree 0.691 0.733 0.704 SSAE + Random Forest 0.747 0.758 0.750 SSAE+XGBoost 0.752 0.771 0.757
[0114] As shown in Table 3, compared with the single deep forest detection model, the electricity theft detection model (SSAE + deep forest) in this embodiment 1, which extracts features using a stacked sparse autoencoder (SSAE) and then performs deep forest electricity theft detection, shows improved performance in all test results. This is because the stacked sparse autoencoder (SSAE) solves the dimensionality curse problem to a certain extent, thus improving the accuracy of electricity theft detection.
[0115] Furthermore, as shown in Table 3, the electricity theft detection model (SSAE + Deep Forest) in Example 1 outperforms all the comparative detection models in terms of accuracy, recall, and F1 score. Specifically, compared to the comparative model (SSAE + XGBoost), the accuracy, recall, and F1 score of the electricity theft detection model (SSAE + Deep Forest) in Example 1 are improved by 9%, 4%, and 8%, respectively. This indicates that, compared to the comparative models, the electricity theft detection model (SSAE + Deep Forest) in Example 1 can more accurately identify normal users and electricity thieves, and has a lower false detection rate. This is because the Deep Forest model performs deep extraction of user electricity consumption characteristics in its multi-granularity feature scanning stage and improves detection accuracy through multi-layer random forest cascading.
[0116] The above description is merely an illustration of the present invention and represents a preferred embodiment. It should be noted that those skilled in the art can make various improvements and modifications without departing from the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for detecting electricity theft based on stacked sparse autoencoders and deep forests, characterized in that, Includes the following steps: S1: Extract user electricity consumption data from the smart power distribution database and construct a user electricity consumption feature dataset; S2: Divide the user electricity consumption feature dataset into a training set and a test set according to a certain proportion; S3: The training set is used as input to the electricity theft detection model to train the model; the electricity theft detection model in S3 includes a stacked sparse autoencoder and a deep forest model, and the output of the stacked sparse autoencoder is the input of the deep forest model, wherein... The stacked sparse autoencoder is composed of multiple sparse autoencoders stacked together, and the loss function L of each sparse autoencoder layer is as shown in formula (1): (1); in, Let i be the feature vector of the i-th real user electricity consumption. Let be the feature vector of the i-th user reconstructed by a single-layer sparse autoencoder, m be the number of input users, and β be a constant factor. The sparsity constraint term is shown in formula (2): (2); In equation (2), KL represents the KL divergence, ρ is a constant approaching zero, and S m ρ represents the number of hidden layer neurons in each sparse autoencoder layer. j Let be the activation level of the j-th neuron, as shown in formula (3): (3); In equation (3), This is the vector encoded by the j-th neuron for the electricity consumption feature vector of the i-th user; The stacked sparse autoencoder determines the number of layers by constructing an objective function, whereby the objective function is shown in equation (4): (4); in, The overall reconstruction error of the stacked sparse autoencoder, Let be the reconstruction error of the u-th sparse autoencoder, and M be the number of layers of the stacked sparse autoencoder; The specific training steps for the electricity theft detection model in S3 are as follows: S3-1: Use stacked sparse autoencoders to extract features from user electricity consumption feature vectors in the training set. Use user electricity consumption feature vectors as input to the first layer of sparse autoencoders in the stacked sparse autoencoders. Use the hidden layer output feature vector of the first layer of sparse autoencoders as input to the second layer of sparse autoencoders. And so on, continuously compress the output feature vector of the hidden layer of the sparse autoencoders until the value of the objective function shown in formula (4) is less than the overall reconstruction error threshold, so as to output the feature vector h that best represents the user electricity consumption pattern. S3-2: The multi-granularity feature scanning module of the deep forest algorithm scans the feature vector h output in step S3-1 to achieve multi-precision extraction of user features; the specific method is as follows: The multi-granularity feature scanning module includes two channels, each of which uses a random forest and a fully random forest for feature extraction, respectively. Let the sliding vector used for feature extraction have dimension d and a sliding step size s. Let a user's feature vector h have dimension h. dim After single-granularity feature scanning, q vectors of length d are obtained, and the formula for calculating q is shown in formula (5): (5); Inputting q vectors into a fully random forest or a random forest will both result in q two-dimensional vectors. Concatenating 2q two-dimensional vectors vertically will yield a vector of length 4q. Similarly, keeping the dimension of the sliding vector unchanged, we set the sliding step matrix as follows: The sliding vector uses multiple step sizes to achieve multi-granularity feature scanning of a single user's electricity consumption feature vector, specifically: Let the step size of the first channel be... The scan vector is arranged according to the step size. The vector set obtained during the scan is denoted as matrix Q. l According to equation (5), Q can be known l The dimension is Similarly, Q will be in the first channel. l Inputting the data into a fully random forest and a random forest, and then performing vertical concatenation, yields a result of length 4. The vector is the output feature vector h after multi-granularity feature scanning. Let the step size of the second channel be... The output feature vector obtained after scanning the input feature vector h is... Dimensions are 4 ; S3-3: A cascaded forest module using the deep forest algorithm is used to achieve deep fusion of user features and identification of electricity theft. S4: Test the electricity theft detection model trained in step S3 using the test set, and construct a confusion matrix based on the test results; S5: Evaluate the test results of the electricity theft detection model using accuracy, recall, and F1 score respectively.
2. The electricity theft detection method based on stacked sparse autoencoders and deep forests according to claim 1, characterized in that, In step S2, the user electricity consumption feature dataset is divided into a training set and a test set in a ratio of 7:
3.
3. The electricity theft detection method based on stacked sparse autoencoders and deep forests according to claim 1, characterized in that, The deep forest model includes a multi-granularity feature scanning module and a cascaded forest module, and the output of the stacked sparse autoencoder is the input of the multi-granularity feature scanning module, and the output of the multi-granularity feature scanning module is the input of the cascaded forest module.
4. The electricity theft detection method based on stacked sparse autoencoders and deep forests according to claim 1, characterized in that, The specific method for deep feature fusion and electricity theft behavior identification in the S3-3 cascaded forest module is as follows: S3-31: Convert the output feature vector of the first channel If the input is fed into the first layer of a cascaded forest, the output vector dimension will be 2. ,in, This represents the number of random forests and fully random forests contained in the first layer of the cascaded forest. Then, the output vector and output feature vector of the first layer of the cascaded forest are compared... The first feature fusion is achieved by concatenating the features, resulting in a fused feature vector. Its dimension is 2 +4 ; S3-32: Fusing feature vectors The input is fed into the second layer of the cascaded forest, and the output vector has a dimension of 2. ,in, This represents the number of random forests and fully random forests contained in the second layer of the cascaded forest. Then, the output vector and output feature vector of the second layer of the cascaded forest are compared... The features are concatenated to achieve a second feature fusion, resulting in a fused feature vector. Dimension 2 +4 ; S3-33: Fusing feature vectors If the input is fed into the third layer of a cascaded forest, the output vector dimension will be 2. ,in, This represents the number of random forests and fully random forests contained in the third layer of the cascaded forest. Then, the output vector and output feature vector of the third layer of the cascaded forest are compared... The feature vector is obtained by concatenating the features for the third time. Its dimension is 2 +4 ; S3-34: Fusing feature vectors The input is fed into the fourth layer of the cascaded forest, and the output vector has a dimension of 2. ,in, This represents the number of random forests and fully random forests contained in the fourth layer of the cascaded forest. Then, the output vector and output feature vector of the fourth layer of the cascaded forest are compared... The features are concatenated to achieve the fourth feature fusion, resulting in a fused feature vector. Dimension 2 +4 ; S3-35: Fusing feature vectors The input is fed into the electricity theft detection layer, and the output is the electricity theft detection result for each random forest or fully random forest, denoted as p, with a dimension of 2. ,in, Let p be the number of random forests and fully random forests contained in the electricity theft detection layer. After averaging and taking the maximum and minimum values of p, the electricity theft detection results can be obtained.
5. The electricity theft detection method based on stacked sparse autoencoders and deep forests according to claim 1, characterized in that, The confusion matrix in S4 includes: If a user in the test set is actually a normal user and is identified as a normal user, the count is TN; if the user is identified as an abnormal user, the count is FP. If a user in the test set is actually an abnormal user but is identified as a normal user, the count is FN; if the user is identified as an abnormal user, the count is TP.
6. The electricity theft detection method based on stacked sparse autoencoders and deep forests according to claim 5, characterized in that, In S5, The formula for calculating the accuracy is shown in equation (6): (6); The formula for calculating the recall rate is shown in equation (7): (7); The F1 score is calculated based on accuracy, recall, and precision, as shown in formula (9): (9); The formula for calculating the accuracy rate is shown in equation (8): (8)。