Regional electricity consumption prediction method and system based on feature and model optimization
Through feature engineering and model optimization methods, combined with particle swarm optimization algorithm to optimize the XGBoost regression model, the problem of few historical samples and non-numerical data in regional power consumption prediction is solved, and the accuracy and robustness of the prediction are improved.
Patent Information
- Application Number
- CN202510333933.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-20
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2045-03-20
AI Technical Summary
When the existing regional power consumption prediction method faces non-numerical data with few historical samples and long-tail distribution, the model is prone to overfitting, resulting in poor generalization performance. The traditional method fails to effectively utilize external influencing factors, and the prediction effect is poor.
Through the combination of feature engineering and model optimization methods, including data preprocessing, feature selection and compression, model hyperparameter optimization, the XGBoost regression model is iteratively optimized by using particle swarm optimization algorithm to optimize feature and model hyperparameters to improve prediction effect.
With few historical samples, the generalization performance of the model is enhanced, the risk of overfitting sparse features is reduced, the robustness and reliability of predictions is improved, and the accuracy of prediction results is optimized.
Smart Images

Figure CN120258217B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electric power technology, and in particular to a method and system for predicting regional electricity consumption based on features and model optimization. Background Art
[0002] With the dual carbon goals, green and low-carbon development has become a key research topic, and digital approaches, represented by artificial intelligence (AI), are a powerful means of achieving them. In the process of low-carbon energy transition, accurately understanding regional electricity demand can more precisely manage and plan energy supply, optimize resource allocation, and ensure the stable operation of the power system. This will also play a vital role in promoting the development and implementation of new clean energy.
[0003] In real-world applications, social factors vary from year to year, and the availability of granular, accurate, and microscopic data on these factors is extremely limited. Furthermore, when faced with coarse-grained data in power grid systems, the amount of valuable historical data available is also limited. Currently, existing regional electricity consumption forecasting methods primarily include time series-based forecasting, gray prediction models, and machine learning methods based on artificial intelligence theory. Among these existing regional electricity consumption forecasting methods, traditional time series forecasting methods are limited in their effectiveness due to their inability to effectively model external influencing factors. Gray prediction models are suitable for scenarios with smaller amounts of data, but excel in scenarios where data exhibits certain regularities, and therefore cannot effectively address the aforementioned issues. Machine learning methods, on the other hand, primarily focus on model structure, with deep learning methods, such as neural networks, being the most common. However, these forecasting methods rely on large historical datasets and are less applicable when historical samples are limited. In addition, it is data that truly determines the upper limit of model learning. Existing regional electricity consumption prediction methods mostly start from the perspective of the model, thus ignoring the tuning value of the data itself. Especially when the overall sample size is small and there is non-numeric data with a long-tail distribution, the model is extremely prone to overfitting on the sparse features after digitization, which will ultimately affect the generalization performance of the model and damage the actual prediction indicators. Summary of the Invention
[0004] The present invention aims to solve, at least to some extent, one of the technical problems in the related art. To this end, one purpose of the present invention is to propose a regional electricity consumption prediction method based on feature and model optimization. Starting from both the data and model levels, the method considers the impact of the combination of different feature subsets, the compression and merging of different features, and the model hyperparameter values on the model learning effect. This method combines different processing methods for feature data and different possible values of model hyperparameters, and comprehensively considers the impact of the data and model itself on the prediction effect.
[0005] In a first aspect, the present invention proposes a method for predicting regional electricity consumption based on features and model optimization, the method comprising the following steps:
[0006] S1: Obtaining raw data consisting of historical electricity consumption data and meteorological attribute data;
[0007] S2: Apply the original data obtained in step S1, connect and integrate the historical electricity consumption data and meteorological attribute data according to time, generate a source data set, and perform data preprocessing on the source data set;
[0008] S3: Apply the source data set obtained in step S2 after data preprocessing, process the source data set using feature engineering methods, and generate training samples and test samples for model input;
[0009] S4: Construct a regression model for electricity consumption prediction;
[0010] S5: Apply the training sample obtained in step S3 and the power consumption prediction regression model obtained in step S4, input the training sample into the power consumption prediction regression model, and train the power consumption prediction regression model;
[0011] S6: Apply the test sample obtained in step S3 and the power consumption prediction regression model trained in step S5, input the test sample into the trained power consumption prediction regression model, predict the power consumption of the test sample, and output the prediction result.
[0012] Preferably, in step S1:
[0013] Historical electricity consumption data includes daily granularity historical total electricity consumption data and corresponding date information within a specified area;
[0014] Meteorological attribute data include historical meteorological attribute data and meteorological forecast data consisting of minimum temperature, maximum temperature, weather conditions, wind direction, wind speed, air quality and corresponding date information in a specified area.
[0015] Preferably, in step S2:
[0016] S21: Connect and integrate the historical electricity consumption data and meteorological attribute data according to the date to obtain the source data set after integrating the historical electricity consumption data and meteorological attribute data, which is expressed as:
[0017]
[0018] Among them, x i,j (1≤i≤m,1≤j≤n) is the specific data information, i represents the number corresponding to the date consisting of year, month, and day, j represents the number corresponding to the time data, historical power consumption data, and meteorological attribute data, m represents the total number of days collected, and n represents the total number of all attributes;
[0019] S22: x i,j Traverse and judge x i,j Execute step S23 for historical power consumption data; determine x i,j For numerical data in meteorological attribute data, execute step S24; determine x i,j If the meteorological attribute data is non-numeric data, execute step S25; determine x i,j For time attribute information, execute step S3;
[0020] S23: x i,j Perform smoothing processing as follows:
[0021] x i ' ,j =ln(1+x i,j )
[0022] Among them, x i ' ,j To smooth the power consumption information, x i ' ,j Assign to x i,j , update the source dataset X;
[0023] The outlier identification is performed on the electricity consumption information in the updated source dataset X. The identification method is as follows:
[0024] The normal power consumption value interval is set to [mean-n×std, mean+n×std], where mean represents the mean of the historical power consumption after smoothing, std represents the standard deviation of the historical power consumption after smoothing, and n is the predetermined power consumption abnormality judgment parameter. i,j Whether it falls within the normal power consumption value range, if so, it is considered normal power consumption data, otherwise it is considered abnormal power consumption data;
[0025] Update the source dataset X after correcting the abnormal power consumption data;
[0026] S24: x i,j Perform filling processing, if x i-1,j and x i+1,j Not missing, x i,j If it is missing, then x i-1,j and x i+1,j The mean of the two data is assigned to x i,j If x i-1,j Not missing, x i,j and x i+1,j If it is missing, then x i-1,j The value of data is assigned to x i,j If x i-1,j If missing, the distance x i,j The most recent non-missing x i+k,j (1≤k≤mi) is assigned to x i,j ;After the filling process is completed, update the source dataset X;
[0027] S25: x i,j Perform missing data marking processing, if x i,j If data is missing, then x i,j Mark as missing data. After the missing data marking process is completed, update the source dataset X.
[0028] Preferably, the method steps for correcting abnormal power consumption data in step S23 are as follows:
[0029] S231: Determine x1′ separately ,j and x′ m,j Is it abnormal power consumption data? Assign mean to x1′ ,j and x′ m,j If the value is determined to be abnormal power consumption data, then step S232 is executed after the determination is completed;
[0030] S232: by x1′ ,j Start traversing downwards in the same column;
[0031] If x i ' -1,j and x i ' +1,j Both data are normal power consumption data, x i ' ,j If it is abnormal power consumption data, then x i ' -1,j and x i ' +1,j The mean of the two data is assigned to x i ' ,j ;
[0032] If x i '-1,j The data is normal power consumption data, x i ' +1,j If the data is abnormal power consumption data, then x i ' -1,j The value of data is assigned to x i ' ,j ;
[0033] Traverse to x′ m,j termination.
[0034] Preferably, in step S3:
[0035] S31: Apply the numerical data x in the meteorological attribute data obtained in step S24 i,j ;
[0036] Perform adjacent multi-scale time window processing as follows:
[0037]
[0038] Among them, m1 represents the length of the delayed time series, and m2 represents the length of the leading time series;
[0039] S32: Apply the non-numeric data x in the meteorological attribute data obtained in step S25 i,j ;
[0040] Perform numerical vectorization processing and use One-Hot encoding to generate a vector consisting of a series of 0s and 1s with a dimension equal to the number of attribute values;
[0041] S33: Processing the time attribute information to generate time dimension derivative information, performing numerical vectorization on the non-numeric data in the time dimension derivative information, and using One-Hot encoding to generate a vector consisting of a series of 0s and 1s with a dimension equal to the number of attribute values;
[0042] S34: Select the historical electricity consumption data after correction of the abnormal electricity consumption data in step S23, the numerical type data in the meteorological attribute data after filling in step S24, the numerical type data in the meteorological attribute data after the multi-scale time window is generated in step S31, the vector obtained by numerical processing of the non-numerical type data of the meteorological attribute data in step S32, and the time dimension derivative data in step S33, and divide them into training samples generated based on historical real data and test samples generated based on future meteorological forecast data, wherein the meteorological attribute data and time dimension derivative data based on historical real data are the input of the training samples, the historical electricity consumption data based on historical real data are the target output of the training samples, and the future meteorological forecast data and future time dimension derivative data are the input of the test samples, and the prediction model outputs future electricity consumption data.
[0043] Preferably, in step S4:
[0044] Construction of a power consumption prediction regression model: Initialize feasible solutions for feature selection, feature compression and merging, and model hyperparameter optimization, and iteratively optimize the feasible solution of the XGBoost regression model for power consumption prediction based on the particle swarm optimization algorithm;
[0045] S41: Determine the value range of the feature selection part and its particle corresponding dimension, apply the time dimension derivative data of step S33, the numerical type data in the meteorological attribute data filled in step S24, and the numerical type data in the meteorological attribute data of step S31, and set the value range of the particle corresponding dimension component to the interval [-r1, r2], where r1 and r2 are preset positive real numbers, and r1 and r2 are both 5;
[0046] S42: Determine the value range of the feature merging part and its particle corresponding dimension: Apply the non-numeric data in the meteorological attribute data in step S32, and set the value range of the particle corresponding dimension component to the interval [0, k), where k is a preset positive integer and is 10;
[0047] S43: Model hyperparameters and their particle corresponding dimension value ranges: specifically, the number of weak learners n_estimators required for XGBoost regression model training, the contribution of weak learners to the model learning_rate, the maximum depth of the tree max_depth, the sample sampling ratio subsample, the feature sampling ratio of each tree colsample_bytree, the constraint coefficient gamma that controls the number of leaves in the tree, the L2 regularization term weight lambda, and the L1 regularization term weight alpha;
[0048] parameter Code value range n_estimators [100,400] learning_rate [0.01,0.15] max_depth [5,10] subsample [0.6,1.0] colsample_bytree [0.6,1.0] gamma [0,10] lambda [0,1] alpha [0,1]
[0049] S44: applying the vectors obtained in step S41, step S42, and step S43 to concatenate and form an optimized vector that can be iteratively updated;
[0050] S45: Optimize the features and model hyperparameters based on the optimization vector and particle swarm optimization algorithm, so as to find the global optimal solution within the range of feasible solutions based on the target value. The parameters that need to be set for the particle swarm optimization algorithm include the number of particles n_particles, the maximum number of iterations max_iteration, the inertia weight inertia_weight, the cognitive learning coefficient cognitive_weight and the social learning coefficient social_weight.
[0051]
[0052]
[0053] Preferably, in step S5:
[0054] During the target value calculation process, for the value of the feature selection part of the particle, the real number input function corresponding to each feature position of the feature selection part is converted into 0 or 1 to determine whether to retain the feature at that position to participate in the model training in the next process. When the value calculated by the function is greater than or equal to 0.3, it is 1, otherwise it is 0. 0 means discarding the feature, and 1 means retaining the feature;
[0055] The function is expressed as:
[0056]
[0057] For the value of the feature merging part, [0, k] is divided into k buckets with equal distance. The feature values that fall into the same bucket are added together to obtain a new feature field, and the merged attributes are discarded;
[0058] For the values of the model hyperparameters, they can be directly used to set the model properties to participate in the training process;
[0059] The training set is divided into R folds to perform cross-validation based on the mean square error value, and the mean of the R-fold mean square error values is calculated as the target value in the iterative process until all the set number of iterations are completed to obtain the solution vector for feature and model hyperparameter optimization.
[0060] In a second aspect, the regional electricity consumption forecasting system based on feature and model optimization proposed by the present invention includes any one of the above-mentioned regional electricity consumption forecasting methods based on feature and model optimization, and the regional electricity consumption forecasting system based on feature and model optimization includes:
[0061] Data generation module: used to obtain historical meteorological data, weather forecast data, and power data for input and one-click extraction, and then connect meteorological data and power data according to time key values to form fused data;
[0062] Data processing module: It includes two parts: data preprocessing and feature engineering. Data preprocessing is the operation of filling or labeling the original attribute data and smoothing the electricity consumption data; feature engineering is the process of processing the original data into the part for model input training;
[0063] Target optimization module: a parameter optimization module based on the optimization algorithm, which supports parameter configuration of feasible solution segments, with options for optimization algorithm, number of parameters, value type and value range.
[0064] Model training module: includes model parameter settings, whether to connect to the target optimization module for optimization training switch and parameter settings. After the settings are completed, the model can be trained with one click. After the model training is completed, it will be saved in the set directory in the format of model name plus optimization algorithm and training completion time;
[0065] Model service module: used to select the model retained in the system to predict electricity consumption within a specified time range;
[0066] Data visualization module: The first part is a visual display of the original data, including time, weather, and holiday information; the second part uses time as the horizontal axis and temperature and electricity consumption data as the vertical axes on both sides, and uses different colors to visualize the actual electricity consumption data, predicted electricity consumption data, and minimum and maximum temperature data; the third part is a line graph showing the historical online predicted electricity consumption data and actual electricity consumption data with time as the horizontal axis and electricity consumption data as the vertical axis, and also displays the calculated prediction effect indicators RMSE and MAPE.
[0067] The beneficial effects of the present invention are:
[0068] (1) In scenarios with fewer historical samples, with the goal of optimizing the generalization performance of the model, different data processing methods and model hyperparameter value adjustments are effectively integrated. Specifically, sparse features are merged and compressed to reduce the risk of overfitting on sparse features and enhance the generalization performance of the model; all candidate feature sets are effectively selected to identify feature subsets that are beneficial to the overall prediction effect; and the hyperparameter values of the model are adjusted to enable the model to better approach the prediction upper limit after the above two parts of optimized data.
[0069] (2) During the model training process, the optimization target after cross-validation is optimized from the above three dimensions, so that the data processing methods and parameter values of the three dimensions are continuously iterated and updated in the process of solving the optimization target.
[0070] (3) It makes up for the shortcomings of existing solutions that mainly rely on adjusting model structure and deep learning to rely on a large number of historical samples, greatly taps the value of original available data, and improves the robustness, reliability and superiority of prediction services. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In the attached figure:
[0072] Figure 1 This is a flow chart of the regional electricity consumption prediction method based on feature and model optimization proposed by the present invention;
[0073] Figure 2 A comparison chart of the relative errors caused by applying the method proposed in this invention and the original XGBoost method;
[0074] Figure 3 This is a block diagram of the regional electricity consumption prediction system based on feature and model optimization proposed by the present invention. DETAILED DESCRIPTION
[0075] Reference Figure 1 A regional electricity consumption prediction method based on feature and model optimization is provided, wherein the steps of the method are as follows:
[0076] S1: Obtain raw data consisting of historical electricity consumption data and meteorological attribute data, and save these two parts of raw data into a specific file according to the row structure composed of time and the column structure composed of other attributes, so that subsequent programs can read the data and extract the required relevant information;
[0077] In this embodiment:
[0078] Historical electricity consumption data includes daily granularity (in units of days) of historical total electricity consumption data within a specified area and the corresponding date information;
[0079] Meteorological attribute data include historical meteorological attribute data and meteorological forecast data consisting of minimum temperature, maximum temperature, weather conditions, wind direction, wind speed, air quality and corresponding date information in a specified area.
[0080] Meteorological attribute data include historical meteorological data and meteorological forecast data in a specified area, consisting of minimum temperature (in degrees Celsius), maximum temperature (in degrees Celsius), weather conditions (70 types including sunny, cloudy, light rain, overcast to cloudy), wind direction (10 types including east wind, south wind, west wind, north wind, southeast wind), wind force (in levels), air quality (6 types including excellent, good, light pollution, moderate pollution, heavy pollution, and severe pollution), etc., and corresponding date information.
[0081] S2: Apply the raw data obtained in step S1 to connect and integrate the historical electricity consumption data and meteorological attribute data according to time to generate a source data set, and perform data preprocessing on the source data set, fill in missing numerical attributes among all attributes, mark missing non-numerical attributes, smooth the target value historical electricity consumption data, and then identify outliers and further correct them;
[0082] In this embodiment:
[0083] S21: Connect and integrate the historical electricity consumption data and meteorological attribute data according to the date to obtain the source data set after integrating the historical electricity consumption data and meteorological attribute data, which is expressed as:
[0084]
[0085] Among them, x i,j (1≤i≤m,1≤j≤n) is the specific data information, i represents the number corresponding to the date consisting of year, month, and day, j represents the number corresponding to the time data, historical power consumption data, and meteorological attribute data, m represents the total number of days collected, and n represents the total number of all attributes;
[0086] S22: x i,j Traverse and judge x i,j Execute step S23 for historical power consumption data; determine x i,j For numerical data in meteorological attribute data, execute step S24; determine x i,j If the meteorological attribute data is non-numeric data, execute step S25; determine x i,j For time attribute information, execute step S3;
[0087] S23: x i,j Perform smoothing processing as follows:
[0088] x i ' ,j =ln(1+x i,j )
[0089] Among them, x i ' ,j To smooth the power consumption information, x i ' ,j Assign to x i,j , update the source dataset X;
[0090] The outlier identification is performed on the electricity consumption information in the updated source dataset X. The identification method is as follows:
[0091] The normal power consumption value interval is set to [mean-n×std, mean+n×std], where mean represents the mean of the historical power consumption after smoothing, std represents the standard deviation of the historical power consumption after smoothing, and n is a predetermined power consumption abnormality judgment parameter. In this embodiment, n is 3. The smoothed x i,j Whether it falls within the normal power consumption value range, if so, it is considered normal power consumption data, otherwise it is considered abnormal power consumption data;
[0092] Update the source dataset X after correcting the abnormal power consumption data;
[0093] Specifically:
[0094] The method steps for correcting abnormal power consumption data in step S23 are as follows:
[0095] S231: Determine x1′ separately ,j and x′ m,j Is it abnormal power consumption data? Assign mean to x1′ ,j and x′ m,j If the value is determined to be abnormal power consumption data, then step S232 is executed after the determination is completed;
[0096] S232: by x1′ ,j Start traversing downwards in the same column;
[0097] If x i ' -1,j and x i ' +1,j Both data are normal power consumption data, x i ' ,j If it is abnormal power consumption data, then x i ' -1,j and x i ' +1,j The mean of the two data is assigned to x i ' ,j ;
[0098] If x i ' -1,j The data is normal power consumption data, x i ' +1,j If the data is abnormal power consumption data, then x i ' -1,j The value of data is assigned to x i ' ,j ;
[0099] Traverse to x′ m,j termination.
[0100] S24: x i,j Perform filling processing, if x i-1,j and x i+1,j Not missing, x i,j If it is missing, then x i-1,j and x i+1,j The mean of the two data is assigned to x i,j If x i-1,j Not missing, x i,j and x i+1,j If it is missing, then x i-1,j The value of data is assigned to x i,j If x i-1,j If missing, the distance x i,j The most recent non-missing x i+k,j (1≤k≤mi) is assigned to x i,j ;After the filling process is completed, update the source dataset X;
[0101] S25: x i,j Perform missing data marking processing, if x i,j If data is missing, then x i,j Data marked as missing are placed alongside other non-missing normal values to form an exclusive category. After the missing data marking process is completed, the source dataset X is updated.
[0102] S3: Apply the source data set obtained in step S2 after data preprocessing, process the source data set using feature engineering methods, and generate training samples and test samples for model input;
[0103] In this embodiment:
[0104] S31: Apply the numerical data x in the meteorological attribute data obtained in step S24 i,j ;
[0105] Perform adjacent multi-scale time window processing as follows:
[0106]
[0107] Wherein, m1 represents the length of the delayed time series, and m2 represents the length of the leading time series. In this embodiment, m1 and m2 are respectively 1, 2, 3, and 7, and when m1 is 0, m2 is respectively 2, 3, 5, and 7 to generate relevant statistical data;
[0108] S32: Apply the non-numeric data x in the meteorological attribute data obtained in step S25 i,j ;
[0109] Perform numerical vectorization processing and use One-Hot encoding to generate a vector consisting of a series of 0s and 1s with a dimension equal to the number of attribute values;
[0110] Specifically, for the meteorological attribute of air quality, there are six value types: excellent, good, lightly polluted, moderately polluted, heavily polluted, and severely polluted. The original non-numeric data can be One-Hot encoded to generate the following results:
[0111] Good: [1,0,0,0,0,0]
[0112] Good: [0,1,0,0,0,0]
[0113] Light pollution: [0,0,1,0,0,0]
[0114] Moderate pollution: [0,0,0,1,0,0]
[0115] Heavy pollution: [0,0,0,0,1,0]
[0116] Severe pollution: [0,0,0,0,0,1];
[0117] S33: Processing the time attribute information to generate time dimension derivative information, performing numerical vectorization on the non-numeric data in the time dimension derivative information, and using One-Hot encoding to generate a vector consisting of a series of 0s and 1s with a dimension equal to the number of attribute values;
[0118] S34: Select the historical electricity consumption data after correction of the abnormal electricity consumption data in step S23, the numerical type data in the meteorological attribute data after filling in step S24, the numerical type data in the meteorological attribute data after the multi-scale time window is generated in step S31, the vector obtained by numerical processing of the non-numerical type data of the meteorological attribute data in step S32, and the time dimension derivative data in step S33, and divide them into training samples generated based on historical real data and test samples generated based on future meteorological forecast data, wherein the meteorological attribute data and time dimension derivative data based on historical real data are the input of the training samples, the historical electricity consumption data based on historical real data are the target output of the training samples, and the future meteorological forecast data and future time dimension derivative data are the input of the test samples, and the prediction model outputs future electricity consumption data.
[0119] S4: Construct a regression model for electricity consumption prediction;
[0120] In this embodiment:
[0121] Construction of a power consumption prediction regression model: Initialize feasible solutions for feature selection, feature compression and merging, and model hyperparameter optimization, and iteratively optimize the feasible solution of the XGBoost regression model for power consumption prediction based on the particle swarm optimization algorithm;
[0122] S41: Determine the value range of the feature selection part and its particle corresponding dimension, apply the time dimension derivative data of step S33, the numerical type data in the meteorological attribute data filled in step S24, and the numerical type data in the meteorological attribute data of step S31, and set the value range of the particle corresponding dimension component to the interval [-r1, r2], where r1 and r2 are preset positive real numbers, and r1 and r2 are both 5;
[0123] S42: Determine the value range of the feature merging part and its particle corresponding dimension: Apply the non-numeric data in the meteorological attribute data in step S32, and set the value range of the particle corresponding dimension component to the interval [0, k), where k is a preset positive integer representing the number of weather condition types that have actual impact on electricity consumption, and the value is 10;
[0124] S43: Model hyperparameters and their particle corresponding dimension value ranges: specifically, the number of weak learners n_estimators required for XGBoost regression model training, the contribution of weak learners to the model learning_rate, the maximum depth of the tree max_depth, the sample sampling ratio subsample, the feature sampling ratio of each tree colsample_bytree, the constraint coefficient gamma controlling the number of leaves in the tree, the L2 regularization term weight lambda, and the L1 regularization term weight alpha, as shown in Table 1;
[0125] Table 1 Schematic diagram of XGBoost hyperparameters for prediction model
[0126] parameter Code value range n_estimators [100,400] learning_rate [0.01,0.15] max_depth [5,10] subsample [0.6,1.0] colsample_bytree [0.6,1.0] gamma [0,10] lambda [0,1] alpha [0,1]
[0127] S44: applying the vectors obtained in step S41, step S42, and step S43 to concatenate and form an optimized vector that can be iteratively updated;
[0128] S45: Optimize the features and model hyperparameters based on the optimization vector and particle swarm optimization algorithm, so as to find the global optimal solution within the feasible solution range based on the target value. The parameters that need to be set for the particle swarm optimization algorithm include the number of particles n_particles, the maximum number of iterations max_iteration, the inertia weight inertia_weight, the cognitive learning coefficient cognitive_weight and the social learning coefficient social_weight, as shown in Table 2.
[0129] Table 2 Schematic diagram of optimization algorithm hyperparameters
[0130] parameter Setting value n_particles 100 max_iteration 30 inertia_weight 0.5 cognitive_weight 1.5 social_weight 2.0
[0131] During the iterations of the optimization algorithm, it's necessary to constrain the range of values for the corresponding dimensions of the updated particle velocity and position. Specifically, if a dimension's value exceeds the minimum (maximum) range boundary, the updated value is set to the minimum (maximum) value. If the range corresponding to a dimension isn't a closed interval, and the minimum (maximum) value doesn't reach the corresponding interval endpoint, the updated value is set to the endpoint plus (minus) a small positive real number. This ensures that each value of the particle velocity and position remains within the preset range during the iterations. Here, this small positive real number is set to 0.001.
[0132] S5: Apply the training samples obtained in step S3 and the power consumption prediction regression model obtained in step S4, input the training samples into the power consumption prediction regression model, train the power consumption prediction regression model, and persist the trained model to the specified model directory on the disk;
[0133] In this embodiment:
[0134] During the target value calculation process, for the value of the feature selection part of the particle, the real number input function corresponding to each feature position of the feature selection part is converted into 0 or 1 to determine whether to retain the feature at that position to participate in the model training in the next process. When the value calculated by the function is greater than or equal to 0.3, it is 1, otherwise it is 0. 0 means discarding the feature, and 1 means retaining the feature;
[0135] The function is expressed as:
[0136]
[0137] For the value of the feature merging part, [0, k] is divided into k buckets with equal distance. In this embodiment, k is 10. The feature values that fall into the same bucket are added together to obtain a new feature field, and the merged attributes are discarded;
[0138] For the values of the model hyperparameters, they can be directly used to set the model properties to participate in the training process;
[0139] The training set is divided into R folds to perform cross-validation based on the mean square error value, and the mean of the R-fold mean square error values is calculated as the target value in the iterative process. In this embodiment, R is 5, and the solution vector for feature and model hyperparameter optimization is obtained until all the set number of iterations are completed.
[0140] S6: Apply the test sample obtained in step S3 and the power consumption prediction regression model trained in step S5, input the test sample into the trained power consumption prediction regression model, predict the power consumption of the test sample, and output the prediction result.
[0141] When it comes to the scenario of actually predicting the electricity consumption of a certain area, the test samples only have feature values but no label values. In the offline evaluation phase of the model before being put into the real production environment, the test set takes the real samples contained in a certain historical time window for model prediction. The predicted value and the real value are used as input to calculate the model prediction effect indicators, such as RMSE, MAPE, etc. t -1 converts the model prediction value into the actual power consumption value, where t is the model prediction value.
[0142] In a specific embodiment:
[0143] like Figure 2As shown in the figure, the electricity consumption of a certain area over a week (7 days) is compared using this method and the commonly used original XGBoost prediction method that is not based on feature and model optimization. It can be seen that the prediction results of this method are closer to the true value at each prediction time, and the error is more stable. Compared with the prediction method without optimized features and models, it shows better prediction effect and robustness.
[0144] In addition, the comparison data between this method and the original XGBoost method are listed in Table 3 below.
[0145] Table 3 Comparison of prediction effect indicators
[0146] index Original XGBoost The method of the present invention (based on feature and model optimization) RMSE 22.17 4.17 MAPE 0.0411 0.0072
[0147] In the above table, RMSE stands for Root Mean Square Error, which is used to measure the numerical deviation between the model's predicted value and the actual value. When the RMSE index value calculated based on the test set is smaller, the prediction deviation is smaller, that is, the model prediction effect is better. MAPE stands for Mean Absolute Percent Error, which is also used to evaluate the numerical deviation between the model's predicted value and the actual value. However, unlike RMSE, it can reflect the relative error between the predicted value and the actual value, and is not affected by the absolute value. The value range is 0 to 1. When the MAPE index value calculated based on the test set is smaller, the prediction deviation is smaller, that is, the model prediction effect is better. MAPE is usually used to measure the accuracy of electricity consumption forecasts. Based on the above two indicators, the prediction results of the method of the present invention are compared with the results given by the prediction method whose features and models have not been optimized, and the error has been greatly optimized.
[0148] As another embodiment of the present application, refer to Figure 3 This embodiment proposes a regional electricity consumption prediction system based on feature and model optimization, which includes any of the above-mentioned regional electricity consumption prediction methods based on feature and model optimization. The regional electricity consumption prediction system based on feature and model optimization includes:
[0149] Data generation module: used to obtain historical meteorological data, weather forecast data, and power data for input and one-click extraction, and then connect meteorological data and power data according to time key values to form fused data;
[0150] Data processing module: It includes two parts: data preprocessing and feature engineering. Data preprocessing is the operation of filling or labeling the original attribute data and smoothing the electricity consumption data. Feature engineering is to process the original data into the part for model input training. It is optional to retain this intermediate data for data quality verification.
[0151] Target optimization module: a parameter optimization module based on the optimization algorithm, which supports parameter configuration of feasible solution segments, with options for optimization algorithm, number of parameters, value type and value range.
[0152] Model training module: includes model parameter settings, whether to connect to the target optimization module for optimization training switch and parameter settings. After the settings are completed, the model can be trained with one click. After the model training is completed, it will be saved in the set directory in the format of model name plus optimization algorithm and training completion time;
[0153] Model service module: used to select the model retained in the system to predict electricity consumption within a specified time range;
[0154] Data visualization module: The first part is a visual display of the original data, including time, weather, and holiday information; the second part uses time as the horizontal axis and temperature and electricity consumption data as the vertical axes on both sides, and uses different colors to visualize the actual electricity consumption data, predicted electricity consumption data, and minimum and maximum temperature data; the third part is a line graph showing the historical online predicted electricity consumption data and actual electricity consumption data with time as the horizontal axis and electricity consumption data as the vertical axis, and also displays the calculated prediction effect indicators RMSE and MAPE.
Claims
1. A regional electricity consumption prediction method based on feature and model optimization, characterized in that: The method steps are as follows: S1: Obtaining raw data consisting of historical electricity consumption data and meteorological attribute data; S2: Apply the original data obtained in step S1, connect and integrate the historical electricity consumption data and meteorological attribute data according to time, generate a source data set, and perform data preprocessing on the source data set; S3: Apply the source data set obtained in step S2 after data preprocessing, process the source data set using feature engineering methods, and generate training samples and test samples for model input; S4: Construct a regression model for electricity consumption prediction; S5: Apply the training sample obtained in step S3 and the power consumption prediction regression model obtained in step S4, input the training sample into the power consumption prediction regression model, and train the power consumption prediction regression model; S6: Apply the test sample obtained in step S3 and the power consumption prediction regression model trained in step S5, input the test sample into the trained power consumption prediction regression model, predict the power consumption of the test sample, and output the prediction result; In step S2: S21: Connect and integrate the historical electricity consumption data and meteorological attribute data according to the date to obtain the source data set after integrating the historical electricity consumption data and meteorological attribute data, which is expressed as: Among them, x i,j (1≤i≤m,1≤j≤n) is the specific data information, i represents the number corresponding to the date consisting of year, month, and day, j represents the number corresponding to the time data, historical power consumption data, and meteorological attribute data, m represents the total number of days collected, and n represents the total number of all attributes; S22: x i,j Traverse and judge x i,j Execute step S23 for historical power consumption data; determine x i,j For numerical data in meteorological attribute data, execute step S24; determine x i,j If the meteorological attribute data is non-numeric data, execute step S25; determine x i,j For time attribute information, execute step S3; S23: x i,j Perform smoothing processing as follows: x′ i,j =ln(1+x i,j ) Where x′ i,j To smooth the power consumption information, x′ i,j Assign to x i,j , update the source dataset X; The outlier identification is performed on the electricity consumption information in the updated source dataset X. The identification method is as follows: The normal power consumption value interval is set to [mean-z×std,mean+z×std], where mean represents the mean of the historical power consumption after smoothing, std represents the standard deviation of the historical power consumption after smoothing, and z is the predetermined power consumption abnormality judgment parameter. i,j Whether it falls within the normal power consumption value range, if so, it is considered normal power consumption data, otherwise it is considered abnormal power consumption data; Update the source dataset X after correcting the abnormal power consumption data; S24: x i,j Perform filling processing, if x i-1,j and x i+1,j Not missing, x i,j If it is missing, then x i-1,j and x i+1,j The mean of the two data is assigned to x i,j If x i-1,j Not missing, x i,j and x i+1,j If it is missing, then x i-1,j The value of data is assigned to x i,j If x i-1,j If missing, the distance x i,j The most recent non-missing x i+k,j (1≤k≤mi) is assigned to x i,j ;After the filling process is completed, update the source dataset X; S25: x i,j Perform missing data marking processing, if x i,j If data is missing, then x i,j Mark as missing data. After the missing data marking process is completed, update the source dataset X.
2. The method for predicting regional electricity consumption based on features and model optimization according to claim 1, characterized in that: In step S1: Historical electricity consumption data includes daily granularity historical total electricity consumption data and corresponding date information within a specified area; Meteorological attribute data include historical meteorological attribute data and meteorological forecast data consisting of minimum temperature, maximum temperature, weather conditions, wind direction, wind speed, air quality and corresponding date information in a specified area.
3. The method for predicting regional electricity consumption based on features and model optimization according to claim 1, characterized in that: The method steps for correcting abnormal power consumption data in step S23 are as follows: S231: Determine x' respectively 1,j and x′ m,j Is it abnormal power consumption data? Assign mean to x′ 1,j and x′ m,j If the value is determined to be abnormal power consumption data, then step S232 is executed after the determination is completed; S232: By x′ 1,j Start traversing downwards in the same column; If x′ i-1,j and x′ i+1,j Both data are normal power consumption data, x′ i,j If x′ is abnormal power consumption data, i-1,j and x′ i+1,j The mean of the two data is assigned to x′ i,j ; If x′ i-1,j The data is normal power consumption data, x′ i+1,j If the data is abnormal power consumption data, then x′ i-1,j The value of data is assigned to x′ i,j ; Traverse to x′ m,j termination.
4. The method for predicting regional electricity consumption based on features and model optimization according to claim 1, characterized in that: In step S3: S31: Apply the numerical data x in the meteorological attribute data obtained in step S24 i,j ; Perform adjacent multi-scale time window processing as follows: Among them, m1 represents the length of the delayed time series, and m2 represents the length of the leading time series; S32: Apply the non-numeric data x in the meteorological attribute data obtained in step S25 i,j ; Perform numerical vectorization processing and use One-Hot encoding to generate a vector consisting of a series of 0s and 1s with a dimension equal to the number of attribute values; S33: Processing the time attribute information to generate time dimension derivative information, performing numerical vectorization on the non-numeric data in the time dimension derivative information, and using One-Hot encoding to generate a vector consisting of a series of 0s and 1s with a dimension equal to the number of attribute values; S34: Select the historical electricity consumption data after correction of the abnormal electricity consumption data in step S23, the numerical type data in the meteorological attribute data after filling in step S24, the numerical type data in the meteorological attribute data after the multi-scale time window is generated in step S31, the vector obtained by numerical processing of the non-numerical type data of the meteorological attribute data in step S32, and the time dimension derivative data in step S33, and divide them into training samples generated based on historical real data and test samples generated based on future meteorological forecast data, wherein the meteorological attribute data and time dimension derivative data based on historical real data are the input of the training samples, the historical electricity consumption data based on historical real data are the target output of the training samples, and the future meteorological forecast data and future time dimension derivative data are the input of the test samples, and the prediction model outputs future electricity consumption data.
5. The method for predicting regional electricity consumption based on features and model optimization according to claim 1 is characterized in that: In step S4: Construction of a power consumption prediction regression model: Initialize feasible solutions for feature selection, feature compression and merging, and model hyperparameter optimization, and iteratively optimize the feasible solution of the XGBoost regression model for power consumption prediction based on the particle swarm optimization algorithm; S41: Determine the value range of the feature selection part and its particle corresponding dimension, apply the time dimension derivative data of step S33, the numerical type data in the meteorological attribute data filled in step S24, and the numerical type data in the meteorological attribute data of step S31, and set the value range of the particle corresponding dimension component to the interval [-r1, r2], where r1 and r2 are preset positive real numbers, and r1 and r2 are both 5; S42: Determine the value range of the feature merging part and its particle corresponding dimension: Apply the non-numeric data in the meteorological attribute data in step S32, and set the value range of the particle corresponding dimension component to the interval [0, k), where k is a preset positive integer and is 10; S43: Model hyperparameters and their particle corresponding dimension value ranges: specifically, the number of weak learners n_estimators required for XGBoost regression model training, the value range is [100,400], the contribution of weak learners to the model learning_rate, the value range is [0.01,0.15], the maximum depth of the tree max_depth, the value range is [5,10], the sample sampling ratio subsample, the value range is [0.6,1.0], the feature sampling ratio of each tree colsample_bytree, the value range is [0.6,1.0], the constraint coefficient gamma that controls the number of tree leaves, the value range is [0,10], the L2 regularization item weight lambda, the value range is [0,1], the L1 regularization item weight alpha, the value range is [0,1]; S44: applying the vectors obtained in step S41, step S42, and step S43 to concatenate and form an optimized vector that can be iteratively updated; S45: Optimize the features and model hyperparameters based on the optimization vector and particle swarm optimization algorithm, so as to find the global optimal solution within the range of feasible solutions based on the target value. The parameters that need to be set for the particle swarm optimization algorithm are the number of particles n_particles, set to 100, the maximum number of iterations max_iteration, set to 30, the inertia weight inertia_weight, set to 0.5, the cognitive learning coefficient cognitive_weight, set to 1.5 and the social learning coefficient social_weight, set to 2.
0.
6. The method for predicting regional electricity consumption based on features and model optimization according to claim 1, characterized in that: In step S5: During the target value calculation process, for the value of the feature selection part of the particle, the real number input function corresponding to each feature position of the feature selection part is converted into 0 or 1 to determine whether to retain the feature at that position to participate in the model training in the next process. When the value calculated by the function is greater than or equal to 0.3, it is 1, otherwise it is 0. 0 means discarding the feature, and 1 means retaining the feature; The function is expressed as: For the value of the feature merging part, [0, k] is divided into k buckets with equal distance. The feature values that fall into the same bucket are added together to obtain a new feature field, and the merged attributes are discarded; For the values of the model hyperparameters, they can be directly used to set the model properties to participate in the training process; The training set is divided into R folds to perform cross-validation based on the mean square error value, and the mean of the R-fold mean square error values is calculated as the target value in the iterative process until all the set number of iterations are completed to obtain the solution vector for feature and model hyperparameter optimization.
7. A regional electricity consumption prediction system based on feature and model optimization, characterized in that: The method for predicting regional electricity consumption based on features and model optimization according to any one of claims 1 to 6, wherein the regional electricity consumption prediction system based on features and model optimization comprises: Data generation module: used to obtain historical meteorological data, weather forecast data, and power data for input and one-click extraction, and then connect meteorological data and power data according to time key values to form fused data; Data processing module: It includes two parts: data preprocessing and feature engineering. Data preprocessing is the operation of filling or labeling the original attribute data and smoothing the electricity consumption data; feature engineering is the process of processing the original data into the part for model input training; Target optimization module: a parameter optimization module based on the optimization algorithm, which supports parameter configuration of feasible solution segments, with options for optimization algorithm, number of parameters, value type and value range. Model training module: includes model parameter settings, whether to connect to the target optimization module for optimization training switch and parameter settings. After the settings are completed, the model can be trained with one click. After the model training is completed, it will be saved in the set directory in the format of model name plus optimization algorithm and training completion time; Model service module: used to select the model retained in the system to predict electricity consumption for a specified time range; data visualization module: the first part is to visualize the original data, including time, weather, and holiday information; the second part is to use time as the horizontal axis and temperature and electricity consumption data as the vertical axes on both sides, and use different colors to visualize the actual electricity consumption data and predicted electricity consumption data as well as the minimum temperature and maximum temperature data; the third part is to display the historical online predicted electricity consumption data and actual electricity consumption data line graph with time as the horizontal axis and electricity consumption data as the vertical axis, and at the same time display the calculated prediction effect indicators RMSE and MAPE.
Citation Information
Patent Citations
Photovoltaic power generation prediction method and device
CN118760888A
Method and apparatus for estimating weather-sensitive load power
WO2019238096A1