Disclosure of Invention
The invention aims to provide a method, a system, a terminal device and a storage medium for identifying electricity stealing behavior, so as to solve the technical problems of strong limitation and inaccurate identification result in the existing method for identifying electricity stealing behavior.
In order to overcome the defects in the prior art, the invention provides an electricity stealing behavior identification method, which comprises the following steps:
the method comprises the steps of collecting historical electricity utilization data of a user to be tested, and dividing the historical electricity utilization data into a first training sample and a test sample according to a first preset proportion;
performing dimensionality reduction on the first training sample, and training a DBN model by using the training sample subjected to dimensionality reduction to obtain a target DBN model and a first output result;
weighting the first output result to obtain an abnormal detection threshold value;
inputting the test sample into the target DBN model to obtain a second output result, and determining a target detection value of the electricity consumption behavior of the user to be detected by using the second output result;
judging whether the target detection value is larger than the abnormal detection threshold value; if so, the current electricity utilization behavior of the user to be tested is normal; and if not, the current electricity utilization behavior of the user to be tested is abnormal.
Further, the training the DBN model by using the training sample after the dimension reduction to obtain a target DBN model includes:
extracting a sample with a second preset proportion from the dimensionality reduced training sample by using a Sampling algorithm to serve as a second training sample, and taking the rest dimensionality reduced training samples as third training samples;
inputting the second training samples into a plurality of first DBN models for unsupervised pre-training to obtain a plurality of second DBN models and corresponding network parameters;
and inputting the third training sample to any one second DBN model for fine adjustment according to the plurality of second DBN models, and determining a target DBN model by using the fine-adjusted network parameters.
Further, before inputting the second training samples to a plurality of first DBN models for unsupervised pre-training, further comprising:
and carrying out global optimization on the network parameters of the original DBN model by using an AG algorithm, and taking an optimization result as the network parameters of the first DBN model.
Further, the first output result comprises: and outputting results after the second training sample is input into a plurality of first DBN models, and outputting results after the third training sample is input into any one second DBN model.
Further, the LASSO is used for conducting thinning weighting processing on the first output result, and an anomaly detection threshold value is obtained.
Further, the first training sample is subjected to dimensionality reduction processing by utilizing a PCA algorithm.
Further, the determining a target detection value of the power consumption behavior of the user to be detected by using the second output result includes:
calculating the detection rate and the false detection rate of the second output result;
and establishing an ROC curve by taking the detection rate as an abscissa and the false detection rate as an ordinate, and taking a point closest to the coordinates (0,1) as a target detection value.
The invention also provides a system for identifying electricity stealing behavior, which comprises:
the data acquisition unit is used for acquiring historical electricity utilization data of a user to be tested and dividing the historical electricity utilization data into a first training sample and a test sample according to a first preset proportion;
the pre-training unit is used for carrying out dimensionality reduction on the first training sample, and training the DBN model by using the training sample subjected to dimensionality reduction to obtain a target DBN model and a first output result;
the weighting processing unit is used for weighting the first output result to obtain an abnormal detection threshold value;
the target detection value determining unit is used for inputting the test sample to the target DBN model to obtain a second output result, and determining a target detection value of the power consumption behavior of the user to be detected by using the second output result;
the power utilization behavior judging unit is used for judging whether the target detection value is larger than the abnormal detection threshold value or not; if so, the current electricity utilization behavior of the user to be tested is normal; and if not, the current electricity utilization behavior of the user to be tested is abnormal.
The present invention also provides a terminal device, including: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, the processor implementing the electricity stealing behavior identification method as in any one of the above when executing the computer program.
The present invention also provides a computer-readable storage medium having stored thereon a computer program for execution by a processor to implement the electricity stealing behavior identification method according to any one of the above.
Compared with the prior art, the invention has the beneficial effects that:
the method performs dimensionality reduction on a sample to be trained by utilizing a PCA algorithm, so as to reduce the calculation difficulty for subsequent training; unsupervised training is carried out on the data subjected to dimensionality reduction by using a DBN model, and meanwhile, an AG algorithm is used for providing optimal network parameters for a DBN, so that the training requirements of the DBN are met, and the optimal anomaly detection threshold value of a user to be detected is output; and finally, performing simulated dynamic detection on the sample to be detected to output an intuitive ROC curve, and judging whether the relation between the target detection value and the abnormal detection threshold value of the user to be detected accords with normal power utilization behaviors. The method and the device can improve the accuracy of identifying the electricity stealing behavior of the user, further enhance the safety and reliability of the power supply system, and have the advantages of low cost, high accuracy and strong applicability.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be understood that the step numbers used herein are for convenience of description only and are not used as limitations on the order in which the steps are performed.
It is to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
The terms "comprises" and "comprising" indicate the presence of the described features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The term "and/or" refers to and includes any and all possible combinations of one or more of the associated listed items.
In a first aspect:
referring to fig. 1, an embodiment of the present invention provides a method for identifying electricity stealing behavior, including the following steps:
s10, collecting historical electricity utilization data of a user to be tested, and dividing the historical electricity utilization data into a first training sample and a test sample according to a first preset proportion.
In the step, firstly, collecting the hourly power consumption data of a user to be measured in a preset time range (last 1 year) as original reference data as historical power consumption data; it should be noted that, the data of the power consumption in the past 1 year is only a preferable mode of data acquisition in this embodiment, and in practical applications, data in other time ranges may be selected as needed, which is not limited herein.
Further, after the historical electricity utilization data are obtained, the historical electricity utilization data are divided into a first training sample and a test sample according to a first preset proportion, and the first preset proportion can be set to be 7:3 or 8: 2. Similarly, in practical applications, other ratios can be selected as the first preset ratio according to environmental requirements, and no limitation is made herein.
Specifically, the first training sample in this embodiment is set to X
RThe test sample is set to X
J. Then, for the first training sample X
RCarrying out scale division according to a certain rule to obtain a classified first training sample: for example, for the first training sample X
RThe power consumption data of the users contained in the database are divided according to the time scale of continuous 30 days to obtain X
J=(x
1,x
2,…,x
720),
S20, performing dimensionality reduction on the first training sample, and training the DBN model by using the dimensionality reduced training sample to obtain a target DBN model and a first output result;
in this step, based on the training sample X obtained in step S10JFor the training sample XJPerforming dimensionality reduction treatment toAnd obtaining a training sample with higher quality, and then training the DBN model by using the sample with higher quality. It should be noted that, the DBN model is a deep confidence network model, where the hidden layer of each layer represents an intermediate representation of the input pattern, each neuron represents a feature of the input data, the connection relationship between the neuron and the neuron represents the connection between the features, and the combination of the features and the connection relationship constitutes an abstract representation of the input data. The DBN model performs feature extraction and reconstruction layer by layer, the higher the layer number is, the fewer the number of neuron nodes in the hidden layer is, and the simpler the input mode is represented, so that a complex input mode can be simplified by adopting the method, and a simple output is finally obtained.
In one embodiment, the dimensionality reduction processing of the first training sample uses a principal component analysis algorithm, i.e., a PCA algorithm. It should be noted that the PCA algorithm is a commonly used data analysis method. PCA transforms raw data into a set of linearly independent representations of dimensions by linear transformation, which can be used to extract the principal feature components of data, which is often used for dimensionality reduction of high-dimensional data.
Specifically, the dimensionality reduction processing by using the PCA algorithm comprises the following steps:
1.1) computing the n-dimensional sample XJIs calculated from the projection data variance σ2Obtaining a sample XJDegree of dispersion of (c):
where v is a projection unit vector, vTIs the transposed vector of v, and N is the number of samples.
σ2=vTCXv
1.2) modeling the optimization problem of PCA dimension reduction:
1.3) solving an optimized value by utilizing a Lagrange equation to obtain:
f(v,λ)=vTCXv-λ(‖v‖-1)=vTCXv-λ(vTv-1)
in the formula, λ is a lagrange multiplier.
The differential solution is performed on f (v, λ) to obtain:
therefore, max σ2=max vTCXv=max vTλv=maxλ
Computing projection data pairs XJContribution ratio of (a):
when r tends to 1, it is shown that there are k (k ≦ n) sets of projection data that can fully characterize the original sample data, i.e., X by PCAJObtaining X after dimensionality reduction treatmentF=(xf1,xf2,…,xfk)。
Further, in this embodiment, the DBN model is trained by using the training samples after the dimension reduction, so as to obtain a target DBN model and a first output result.
In a certain embodiment, the training the DBN model by using the training samples after the dimension reduction to obtain the target DBN model includes:
and 2.1) extracting a sample with a second preset proportion from the training sample after dimensionality reduction by using a Sampling algorithm to serve as a second training sample, and taking the rest training sample after dimensionality reduction as a third training sample.
Wherein the Sampling algorithm is utilized to obtain the data from X
RCyclically extracting a small amount of samples according to a second preset proportion to obtain
2.2) inputting the second training samples into a plurality of first DBN models for unsupervised pre-training to obtain a plurality of second DBN models and corresponding network parameters.
In one embodiment, before inputting the second training samples to the plurality of first DBN models for unsupervised pre-training, the method further comprises:
and carrying out global optimization on the network parameters of the original DBN model by using an AG algorithm, and taking an optimization result as the network parameters of the first DBN model.
It should be noted that the ant colony Algorithm (AG) is a simulation optimization algorithm for simulating foraging behavior of ants, and the basic principle thereof includes: a) ants release pheromone on the path; b) and randomly selecting a path to walk when the crossing which is not walked is touched. At the same time, the pheromone related to the path length is released; c) pheromone concentration is inversely proportional to the path length. When the following ants touch the intersection again, selecting a path with higher pheromone concentration; d) the concentration of pheromones on the optimal path is increased; e) and finally finding the optimal food searching path by the ant colony.
Specifically, the process of global optimization by the AG algorithm in this embodiment includes:
A) calculating the change probability of the network parameter theta of the original DBN model at a certain moment:
wherein n is equal to JS(m),JS(m) is a set formed by the trend of the variation of the network parameter theta, taumn(t) pheromone concentration in the trend, γmnAnd (t) is heuristic information, namely information of an original network parameter theta, alpha is an enlightenment factor of pheromone concentration, beta is an expected value of the enlightenment factor, m and n are respectively a change starting point and a change ending point, and s is each parameter value in the network parameter theta.
B) Updating the pheromone concentration, and calculating the updated change probability:
τmn(t+1)=(1-ρ)τmn(t)+Δτmn(t)
in the formula (I), the compound is shown in the specification,
Δτ
mn(t) is the pheromone delta value,
is the residual pheromone value, Q is the pheromone intensity value, L
sρ is the pheromone volatility factor for the length of the change path.
C) When updated, the change probability of the network parameter theta
When the concentration of the pheromone is less than or equal to the preset threshold value, taking the concentration of the pheromone at the moment as the optimal result A of the network parameter
1. Wherein, w
ijAs a weight, representing the relationship between the input layer and the hidden layer in the DBN model, b
iIs a bias vector of the input layer, c
jIs the bias vector of the hidden layer.
Further, step 2.2) is executed, that is, the second training samples are input to the plurality of first DBN models for unsupervised pre-training, so as to obtain a plurality of second DBN models and corresponding network parameters.
Specifically, in step 2.2), setting parameter values in the first DBN model, specifically: the number of neurons of the input layer is 40, the number of neurons of the first hidden layer is 50, the number of neurons of the second hidden layer is 20, the number of neurons of the output layer is 1, the learning rate is 0.3, the momentum term is 0.3, the batch processing amount is 10, the iteration number is 20, and the target error value is 0.0001.
Then, normalization processing is carried out on the initial training sample, the processed sample is input into a first DBN model to be trained, and an output result is obtained. Specifically, the normalization process is:
wherein X is a normalized value, XminIs the minimum value of sample data, xmaxIs the maximum value of the sample data, and x is the initial data.
Further, according to the output result, calculating the error of the output result of the trained first DBN model;
then, the error value E is used to match the weight value wijAnd (5) correcting:
where η is the learning rate.
Finally, the corrected w is utilizedijAdjustment bi、cjOutputting the trained network parameter A2. I.e. the network parameter of the second DBN model is a2。
2.3) inputting the third training sample into any one second DBN model for fine adjustment according to the plurality of second DBN models, and determining a target DBN model by using the fine-adjusted network parameters.
Specifically, the mth second DBN model is selected from the n second DBN models to
To train the sample, and the network parameter A in the mth second DBN model
2Fine tuning to A
3。
It should be noted that, in this embodiment, a first output result needs to be obtained, where the first output result is an output result obtained by inputting the second training sample to the plurality of first DBN models, and an output result obtained by inputting the third training sample to any one of the second DBN models. Namely the first DBN model and the second DBN model are used for training the sample XRIs transported byThe output value Y is (Y)ij)k×n。
And S30, weighting the first output result to obtain an abnormal detection threshold value.
In this step, the weak classifier is mainly thinned by using LASSO to obtain an external weight value β ═ β
1,β
2,…,β
nWeighting the weak classifier to obtain the output of the model
To be provided with
As the abnormal detection threshold of the model to the single time point of the ith user to be detected.
In one embodiment, step S30 further includes the following sub-steps:
3.1) thinning the weak classifier by using LASSO to obtain an external weight value;
wherein the calculation formula of the LASSO algorithm is as follows:
in the formula, betajIs the outer weight of the jth weak classifier, λ ∈ [0, + ∞) is the penalty factor, liIs labeled for the ith training sample.
And 3.2) weighting the output value of the weak classifier by using the external weight value.
Specifically, the external weight β ═ β of the weak classifier is obtained
1,β
2,…,β
nWeighting the output of each weak classifier to obtain the output of the model
S40, inputting the test sample into the target DBN model to obtain a second output result, and determining a target detection value of the electricity consumption behavior of the user to be detected by using the second output result;
specifically, first, a test sample X is testedTFor simulating dynamic detection, using the second output result and the sample label LTDrawing an ROC curve of the model to a second output result; and secondly, acquiring an optimal critical point on the ROC curve, and taking the point as a target detection value for determining the electricity utilization behavior of the user to be detected.
Specifically, step S40 includes the following substeps:
4.1) calculating the detection rate and the false detection rate of the second output result;
it should be noted that if the target detection value is selected too low, it tends to determine that the false detection rate is increased due to abnormal power consumption data; if the target detection value is selected too high, the detection rate is prone to being reduced due to the fact that the electricity consumption data are normal. The selection of the target detection value will determine the quality of the detection of electricity stealing behavior.
Specifically, the calculation formula of the detection rate is as follows:
TPR=TP/(TP+FN)
in the formula, TPNumber of samples for which abnormal power consumption data has been detected as abnormal, FNThe abnormal power consumption data is the number of samples detected as normal.
The calculation formula for calculating the false detection rate is as follows:
FPR=FP/(FP+TN)
in the formula, FPNumber of samples, T, detected as abnormal for normal power usage dataNThe normal power consumption data is the number of samples detected to be normal.
And 4.2) establishing an ROC curve by taking the detection rate as an abscissa and the false detection rate as an ordinate, and taking a point closest to the coordinates (0,1) as a target detection value.
To test a sample XTThe detection rate of the detection result is an abscissa, and the test sample XTThe false detection rate of the detection result is that an ROC curve is established for the vertical coordinate, a point (0,1) is defined as a perfect detection point, and the distance point (0,1) on the ROC curve is selected to be the most distant pointNear point, and using the detection result corresponding to the point as the target detection value y0。
S50, judging whether the target detection value is larger than the abnormal detection threshold value; if so, the current electricity utilization behavior of the user to be tested is normal; and if not, the current electricity utilization behavior of the user to be tested is abnormal.
In this step, the target detection value y is judged0Whether the current time is greater than the abnormal detection threshold of the ith user to be detected; if so, judging that the electricity utilization behavior of the ith user to be tested is normal; if not, judging that the electricity utilization behavior of the ith user is abnormal.
According to the electricity stealing behavior identification method provided by the embodiment of the invention, the Principal Component Analysis (PCA) algorithm is utilized to perform dimensionality reduction on a sample to be trained, so that the calculation difficulty is reduced for subsequent training; providing optimal network parameters for the DBN by using an ant colony algorithm AG to output an optimal anomaly detection threshold value of a user to be detected; and finally, performing simulated dynamic detection on the sample to be detected to output an intuitive ROC curve, thereby accurately judging the power utilization behavior of the user. The embodiment of the invention can improve the accuracy of identifying the electricity stealing behavior of the user, enhance the safety and reliability of the power supply system, and has low cost and strong applicability.
In a second aspect:
referring to fig. 2, in an embodiment of the present invention, a system for identifying electricity stealing behavior is further provided, including:
the data acquisition unit 01 is used for acquiring historical electricity consumption data of a user to be tested, and dividing the historical electricity consumption data into a first training sample and a test sample according to a first preset proportion;
the pre-training unit 02 is used for performing dimensionality reduction on the first training sample, and training the DBN model by using the training sample subjected to dimensionality reduction to obtain a target DBN model and a first output result;
the weighting processing unit 03 is configured to weight the first output result to obtain an anomaly detection threshold;
the target detection value determining unit 04 is configured to input the test sample to the target DBN model to obtain a second output result, and determine a target detection value of the power consumption behavior of the user to be detected by using the second output result;
an electricity consumption behavior determination unit 05 configured to determine whether the target detection value is greater than the abnormality detection threshold value; if so, the current electricity utilization behavior of the user to be tested is normal; and if not, the current electricity utilization behavior of the user to be tested is abnormal.
The electric larceny behavior recognition system provided by the embodiment of the invention is used for executing the electric larceny behavior recognition method in the first aspect, the method performs dimensionality reduction on a to-be-trained sample by utilizing a Principal Component Analysis (PCA) algorithm, and the calculation difficulty is reduced for subsequent training; providing optimal network parameters for the DBN by using an ant colony algorithm AG to output an optimal anomaly detection threshold value of a user to be detected; and finally, performing simulated dynamic detection on the sample to be detected to output an intuitive ROC curve, thereby accurately judging the power utilization behavior of the user. The embodiment of the invention can improve the accuracy of identifying the electricity stealing behavior of the user, enhance the safety and reliability of the power supply system, and has low cost and strong applicability.
Third aspect of the invention
Referring to fig. 3, an embodiment of the present invention further provides a terminal device, where the terminal device includes:
a processor, a memory, and a bus;
the bus is used for connecting the processor and the memory;
the memory is used for storing operation instructions;
the processor is configured to call the operation instruction, and the executable instruction enables the processor to perform an operation corresponding to the electricity stealing behavior identification method according to the first aspect of the application.
In an alternative embodiment, there is provided a terminal device, as shown in fig. 3, the terminal device shown in fig. 3 includes: a processor 001 and a memory 003. Where processor 001 is coupled to memory 003, such as by bus 002. Optionally, the terminal device may also include a transceiver 004. It should be noted that the transceiver 004 is not limited to one in practical application, and the structure of the terminal device does not constitute a limitation to the embodiments of the present application.
The processor 001 may be a CPU, general purpose processor, DSP, ASIC, FPGA or other programmable logic device, transistor logic device, hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor 001 may also be a combination that performs computing functions, including for example, one or more microprocessors, a combination of DSPs and microprocessors, and the like.
Bus 002 may include a path to transfer information between the aforementioned components. The bus 002 may be a PCI bus or an EISA bus, etc. The bus 002 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 3, but this does not mean only one bus or one type of bus.
The memory 003 can be, but is not limited to, a ROM or other type of static storage device that can store static information and instructions, a RAM or other type of dynamic storage device that can store information and instructions, an EEPROM, a CD-ROM or other optical disk storage, optical disk storage (including compact disk, laser disk, optical disk, digital versatile disk, blu-ray disk, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer.
The memory 003 is used for storing application program codes for performing the present solution and is controlled in execution by the processor 001. Processor 001 is configured to execute application code stored in memory 003 to implement any of the method embodiments described above.
Wherein, the terminal device includes but is not limited to: mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like.
Yet another embodiment of the present application provides a computer-readable storage medium having stored thereon a computer program, which, when run on a computer, causes the computer to perform the respective ones of the aforementioned method embodiments.
While the foregoing is directed to the preferred embodiment of the present invention, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention.