Multi-level feature sewage treatment plant electricity consumption machine learning prediction method
Through multi -level features of machine learning prediction methods and combined with the XGBOOST model, the problem of weak generalization capabilities of sewage treatment plants for power consumption models is weak, and higher prediction accuracy and applicability are achieved.
Patent Information
- Application Number
- CN202411364542.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-01-21
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing wastewater treatment plant power consumption prediction model cannot fully consider external factors such as the impact of weather conditions and urban development on energy consumption, and the model generalization ability is weak and it is difficult to apply on a large scale.
A multi-level feature machine learning prediction method is adopted, including data preprocessing, feature sorting, model selection and parameter tuning, and the XGBoost model is used to predict the electricity consumption of sewage treatment plants.
This method can effectively consider the factors of different cities and weather changes, improve the predicted accuracy and model's generalization capabilities, and apply to sewage treatment plants in different technologies and regions.
Smart Images

Figure CN119337085A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a machine learning model for electricity consumption in a sewage treatment plant, and belongs to the technical field of sewage treatment. Background Art
[0002] Against the backdrop of increasingly severe global climate change, organizations are committed to reducing greenhouse gas emissions, especially carbon dioxide emissions. As energy-intensive facilities, the electricity consumption of sewage treatment plants is directly related to the level of carbon emissions. According to statistics from the International Energy Agency (IEA), the energy consumption of global sewage treatment plants accounts for 2% to 3% of the total urban energy consumption, and this proportion may rise further as the demand for sewage treatment continues to grow. Therefore, optimizing the electricity efficiency of sewage treatment plants is not only necessary to improve operating cost-effectiveness, but also a key measure to respond to global climate change and fulfill carbon reduction commitments.
[0003] The energy conservation and emission reduction measures of existing sewage treatment plants are mainly concentrated in process optimization, equipment upgrades, and resource recycling. However, predicting the electricity demand of sewage treatment plants and adopting appropriate control strategies is also one of the important ways to achieve carbon emission reduction. By accurately predicting electricity consumption, equipment operation can be better optimized, energy waste can be avoided, and carbon emissions can be reduced. For example: The publication number is CN118324289A, and the name of the invention is a sewage treatment technology. Its technical solution uses a machine learning model based on the principle of saving electricity to predict the electricity consumption of the blower, and combines the automatic control system to optimize the operation of the blower in the sewage treatment technology. The purpose is to optimize the operation of the sewage treatment plant. Traditional sewage treatment plant electricity consumption prediction models usually rely on historical data and process parameters within the plant, such as water inlet flow, pollutant loads, etc., and have the following problems:
[0004] (1) It is unable to fully consider the impact of external factors such as weather conditions and urban development on the energy consumption of sewage treatment plants, which is insufficient when predicting the carbon emissions of sewage treatment plants under different urban development levels and climate conditions;
[0005] (2) Models that rely only on operating data from individual plants for training have weak generalization capabilities. Such models often only have high prediction accuracy for individual sewage treatment plants, but cannot be applied on a large scale.
[0006] Therefore, it is urgent to propose a machine learning prediction method for electricity consumption in sewage treatment plants with multi-level features to solve the above technical problems. Summary of the invention
[0007] In order to solve the above problems, a machine learning prediction method for electricity consumption of sewage treatment plants with multi-level features is provided. A brief overview of the present invention is given below to provide a basic understanding of certain aspects of the present invention. It should be understood that this overview is not an exhaustive overview of the present invention. It is not intended to determine the key or important parts of the present invention, nor is it intended to limit the scope of the present invention.
[0008] The technical solution of the present invention:
[0009] A machine learning prediction method for electricity consumption of a sewage treatment plant with multi-level features, comprising the following steps:
[0010] Step 1: Data preprocessing;
[0011] Step 2: Divide the training set and test set;
[0012] Step 3: Model selection;
[0013] Step 4: Optimal model.
[0014] Preferably: Step 1 includes feature combing, encoding text type features, and filling missing values, wherein the LabelEncoder algorithm is used to encode text type features, and the random forest algorithm is used to fill missing values of each feature.
[0015] Preferred: The feature combing in step 1 includes regional development characteristics, precipitation characteristics and sewage treatment plant related characteristics; regional development characteristics include annual per capita water consumption of sewage treatment plants (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), recycled water utilization (m 3 ), the ratio of industrial water consumption to domestic water consumption; the precipitation characteristic is annual precipitation (mm); the relevant characteristics of the sewage treatment plant include sewage treatment volume (10,000 tons), sewage treatment technology, and the reduction of each pollutant (mg / L).
[0016] Preferably: the encoded text type feature in step 1 uses the LabelEncoder algorithm to encode the sewage treatment technology (classified data); sewage treatment technology includes A / O process, A 2 / O process, improved A 2 / O process, Biolake process, biofilter process, CASS process, Carrousel oxidation ditch process, Orbel oxidation ditch process, oxidation ditch process, and other processes.
[0017] Preferably: in step 2, the data set is divided into training, validation and test sets with the same distribution for multiple training;
[0018] Division ratio: The ratio of the test set is 25%, and the remaining 75% is used for the training set and the validation set to ensure that the test set has the same distribution as the training set, thereby avoiding data leakage;
[0019] Multiple training: After dividing the training set and the test set, use multiple training methods to further improve the generalization ability of the model.
[0020] Preferably, step three includes the following steps:
[0021] Model selection and training: Four machine learning algorithms (models) were selected, including XGBoost, LightGBM, CatBoost, and Random Forest, for training. During the training process, the k-fold cross-validation (Stratified k-fold CV) method was used to ensure the generalization ability of the model. At the same time, the GridSearchCV method (grid search cross-validation) was used to tune the hyperparameters to find the optimal combination of model parameters and improve the prediction and generalization capabilities of the model.
[0022] Feature screening: For each model, the recursive feature elimination (RFE) method is used to screen out the feature sequence with the best performance;
[0023] Model evaluation: Use R2 score and mean absolute error (MAE) to evaluate the performance of the regression model;
[0024] Model comparison: Four models were compared and the best performing model was selected based on its performance in terms of R2 score and mean absolute error (MAE).
[0025] Preferably, step 4 includes the following steps:
[0026] Model selection and sequence: The optimal model XGBoost was selected as the machine learning model for predicting the electricity consumption of sewage treatment plants; the present invention can process various types of data and has excellent performance in processing missing values, outliers, etc.; the optimal feature sequence that has a significant impact on predicting the electricity consumption of sewage treatment plants is: sewage treatment volume (10,000 tons), sewage treatment technology, per capita water consumption (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), annual precipitation (mm);
[0027] Model parameter settings: The optimal parameter settings include: 'booster':['gbtree'], 'gamma':[0.5], 'reg_alpha':[0.63], 'reg_lambda':[0.77], 'max_depth':[4], 'min_child_weight':[1], 'subsample':[0.76], 'colsample_bytree':[0.6], 'n_estimators':
[246] , 'learning_rate':[0.05], 'random_st ate':
[42] , 'max_bin':[2], 'verbosity':[0]; by tuning, the R of the model on the training set is 2 The value reaches 0.996, and the MAE value is 343377;
[0028] Model evaluation: R of the model on the training set 2 Value; Cross-validated R 2 Score; MAE value of the model;
[0029] Model application: The final generated pkl format file is used by the front-end prediction software to ensure the deployability and practicality of the model;
[0030] Preferred: In step 4, the XGBoost model used is an optimized distributed gradient boosting model, whose goal is to establish N regression trees so that the predicted value of the tree group is as close to the true value as possible and has the greatest generalization ability; that is, given a number of training samples (x1, y1), (x2, y2) .... (xn, yn) consisting of an input vector x and an output vector y, the goal is to find an approximate function So that the loss function The loss value is the smallest, among which It is the predicted value, and its objective function is basically expressed as follows:
[0031]
[0032] Among them, the regularization term
[0033] The present invention has the following beneficial effects:
[0034] (1) The sewage treatment plant electricity consumption prediction model based on multi-level characteristics of the present invention can cope with different urban development and weather changes, and is convenient for practitioners to use the model for prediction when designing and optimizing sewage treatment plants in different cities (regions) and different climates.
[0035] (2) The present invention has high prediction accuracy for sewage treatment plants of different technologies and regions, and has high generalization ability for predicting electricity consumption of sewage treatment plants.
[0036] (3) The present invention designs a front-end webpage software for the model, which is convenient for practitioners to use for prediction, is simple to operate, and is suitable for promotion. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 This is an interface diagram of a machine learning prediction method for electricity consumption in a sewage treatment plant with multi-level features.
[0038] Figure 2 This is a method diagram of Example 1. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention is described below by the specific embodiments shown in the accompanying drawings. However, it should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. In addition, in the following description, the description of well-known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present invention.
[0040] Specific implementation method 1: Combination Figure 1-2 This embodiment describes a method for predicting electricity consumption of a sewage treatment plant using machine learning with multi-level features, including the following steps:
[0041] Step 1: Data preprocessing;
[0042] Step 1 includes feature combing, encoding text type features, and filling missing values. The LabelEncoder algorithm is used to encode text type features, and the random forest algorithm is used to fill missing values of each feature.
[0043] Feature combing: First, comb the data features and identify text features;
[0044] The characteristics sorted out in step 1 include regional development characteristics, precipitation characteristics and sewage treatment plant related characteristics; regional development characteristics include the per capita water consumption (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), recycled water utilization (m 3 ), the ratio of industrial water consumption to domestic water consumption; the precipitation characteristic is the annual precipitation (mm); the sewage treatment plant related characteristics include sewage treatment volume (10,000 tons), sewage treatment technology, and the reduction of each pollutant (mg / L); the per capita water consumption (m 3 ) and water consumption per 10,000 yuan of GDP (m 3 ) The forecast value shall be based on the data reported in the water resources bulletin and yearbook of the prefecture-level city in the previous year;
[0045] Encoding text type features: Use the LabelEncoder algorithm to encode text type features; LabelEncoder maps each category to a unique integer, thereby converting categorical data into numerical types;
[0046] In order to build a machine learning prediction model, the encoded text type features in step 1 were encoded using the LabelEncoder algorithm for sewage treatment technology (classified data); sewage treatment technology includes A / O process, A 2 / O process, improved A 2 / O process, Baileke process, biological filter process, CASS process, Carrousel oxidation ditch process, Orbel oxidation ditch process, oxidation ditch process, other processes, the coding results corresponding to the processes in the sewage treatment technology are "0, 1, 6, 2, 3, 4, 5, 7, 9, 8"; the LabelEncoder algorithm in the present invention successfully converts the text type of sewage treatment technology features into numerical types, which facilitates the subsequent machine learning prediction model processing, analysis, training, and prediction;
[0047] Filling missing values: The random forest algorithm is used to fill the missing values of each feature to obtain a data set; random forest is an ensemble learning method that improves prediction accuracy by building multiple decision trees and combining their prediction results; the present invention effectively handles missing values and text type features, and uses the random forest algorithm for efficient training and evaluation;
[0048] Step 2: Divide the training set and test set;
[0049] In step 2, the dataset is divided into training, validation, and test sets with the same distribution for multiple training;
[0050] Division ratio: The ratio of the test set is 25%, and the remaining 75% is used for the training set and the validation set to ensure that the test set has the same distribution as the training set, thereby avoiding data leakage;
[0051] Multiple training: After dividing the training set and the test set, use multiple training methods to further improve the generalization ability of the model; multiple training usually includes cross-validation, which ensures that the model performs stably on different data subsets by dividing the training set and the validation set multiple times;
[0052] Step 3: Model selection;
[0053] Step three includes the following steps:
[0054] Model selection and training: Four machine learning algorithms (models) were selected, including XGBoost, LightGBM, CatBoost, and Random Forest, for training. During the training process, the k-fold cross-validation (Stratified k-fold CV) method was used to ensure the generalization ability of the model. At the same time, the GridSearchCV method (grid search cross-validation) was used to tune the hyperparameters to find the optimal combination of model parameters and improve the prediction and generalization capabilities of the model.
[0055] Feature screening: For each model, the recursive feature elimination (RFE) method is used to screen out the feature sequence with the best performance;
[0056] Model evaluation: R2 score and mean absolute error (MAE) were used to evaluate the performance of the regression model; the results showed that the XGBoost model performed best in both R2 score and MAE;
[0057] Model comparison: The four models were compared and the best performing model was selected based on their performance in R2 score and mean absolute error (MAE). The XGBoost model was compared with the LightGBM, CatBoost, and Random Forest models. The results showed that the XGBoost model outperformed the other three models in terms of R2 score and mean absolute error (MAE).
[0058] Through the above steps, the XGBoost model was successfully selected and its superior performance in the regression task was verified;
[0059] Step 4: Use the optimal model;
[0060] In step 4, a machine learning application based on the XGBoost model is used to predict the electricity consumption of the sewage treatment plant; the model selects a specific feature sequence and parameter combination to achieve the best prediction performance, including the following steps:
[0061] Model selection and sequence: The optimal model XGBoost was selected as the machine learning model for predicting the electricity consumption of sewage treatment plants; the present invention can process various types of data and has excellent performance in processing missing values, outliers, etc.; the optimal feature sequence that has a significant impact on predicting the electricity consumption of sewage treatment plants is: sewage treatment volume (10,000 tons), sewage treatment technology, per capita water consumption (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), annual precipitation (mm);
[0062] Model parameter settings: The optimal parameter settings include: 'booster':['gbtree'], 'gamma':[0.5], 'reg_alpha':[0.63], 'reg_lambda':[0.77], 'max_depth':[4], 'min_child_weight':[1], 'subsample':[0.76], 'colsample_bytree':[0.6], 'n_estimators':
[246] , 'learning_rate':[0.05], 'random_st ate':
[42] ,'max_bin':[2],'verbosity':[0]; booster specifies the weak classifier to be used; gamma is the penalty term for model complexity, the higher the value, the more conservative the model; reg_alpha is the L1 regularization term (the absolute value of the weights), which reduces overfitting by penalizing the complexity of the model; reg_lambda is the L2 regularization term (the sum of squared weights), which is a regularization method that penalizes features with large weights; max_depth controls the maximum depth of the tree, the deeper the tree, the more complex the model, and the easier it is to overfit; min_child_weight Controls the minimum sample weight and required for splitting leaf nodes; subsample controls the sample ratio used when training each tree; colsample_bytree controls the feature ratio used when training each tree; the n_estimators parameter indicates the number of weak estimators in the ensemble; learning_rate controls the step size of each update; random_state is used to ensure that the results of model training are reproducible; max_bin is used to discretize the maximum number of boxes for continuous features in the histogram approximation; verbosity controls whether to print the results of each training; through parameter tuning, the R of the model on the training set is improved. 2 The value reaches 0.996, and the MAE value is 343377;
[0063] Model evaluation: R of the model on the training set 2 The value is 0.996, indicating that the model fits the data very well; the cross-validated R 2 The score is 0.817, indicating that the model performs relatively stably on different data subsets; the MAE value of the model is 343377, which further verifies the prediction accuracy of the model;
[0064] Model application: The pkl format file finally generated is used by the front-end prediction software, ensuring the deployability and practicality of the model; by selecting and optimizing the XGBoost model to predict the electricity consumption of the waterless treatment plant, and through rigorous evaluation to ensure the performance and practicality of the model, the XGBoost model can meet the needs of electricity consumption prediction of the sewage treatment plant, and achieves high-precision prediction results by optimizing feature selection and parameter settings;
[0065] In step 4, the XGBoost model used is an optimized distributed gradient boosting model. Its goal is to build N regression trees so that the predicted value of the tree group is as close to the true value as possible and has the greatest generalization ability; that is, given a number of training samples (x1, y1), (x2, y2) .... (xn, yn) consisting of an input vector x and an output vector y, the goal is to find an approximate function So that the loss function The loss value is the smallest, among which It is the predicted value, and its objective function is basically expressed as follows:
[0066]
[0067] Among them, the regularization term
[0068] Among them, the loss function part F(x) is the output of the prediction model, n is the number of samples, is the loss function, representing the true value y i and predicted values The difference between them; the regularization term part t is the number of trees in the current iteration (i.e., the index of the tree in the model), Ω(f) is the regularization term of the kth tree, which is used to control the model complexity and prevent overfitting, γ is the tree complexity penalty parameter, which controls the minimum loss reduction of each tree, T is the number of leaf nodes in the current tree, λ is the L2 regularization parameter of the weight, ||w|| 2 is the sum of the squares of the weights and represents the L2 norm of all weights in the model.
[0069] The present invention predicts the electricity consumption of the entire sewage treatment process from the perspective of reducing carbon emissions from sewage treatment plants. The advantage of the present invention is that it can be used to predict the production electricity consumption of the entire sewage treatment plant before the new construction or renovation, so that the electricity consumption can be macro-controlled before production. The prediction performance has a broad spectrum and can adapt to the prediction needs of sewage treatment plants in areas with different levels of development and different climates.
[0070] Embodiment 1:
[0071] like Figure 1 As shown, and use Figure 2The method includes the following steps, all of which are implemented by Python 3.0 and above:
[0072] ①Install the required packages for app.py and run all the codes in app.py. This code uses the Flask framework to create a simple web application. Users can submit form data through the web page and call the trained model (loaded by pickle) for prediction based on the submitted data. The specific details of the code are as follows:
[0073] I. Model loading: Use the pickle library to load the trained model;
[0074] II. Route settings: This route handles two types of requests: GET and POST. When it is a GET request, a web page (Web.html) will be presented, which contains a form for the user to enter data. When it is a POST request, the data in the form will be submitted, and the code will extract the data and pass it to the machine learning model for prediction.
[0075] III. Get form data: Use the request.form.get() method to extract the values from the web form; get the values entered by the user and assign them to various variables according to the field names of the form;
[0076] IV. Data preprocessing and prediction: Collect the form data entered by the user into a list and convert the data type to floating point type, then convert it into a NumPy array and use the loaded model to predict the user input;
[0077] V. Result output: pass the prediction result back to the web page and display it in the template;
[0078] ②Click the local loopback address in the running area to open the web page;
[0079] ③ Collect the required data according to the characteristics, including per capita water consumption (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), annual precipitation (mm), sewage treatment volume (10,000 tons), sewage treatment technology;
[0080] ④Click the Prediction button;
[0081] ⑤Read the predicted electricity consumption.
[0082] It should be noted that in the above embodiments, as long as the technical solutions are not contradictory, they can be arranged and combined, and those skilled in the art can exhaust all possibilities based on the mathematical knowledge of arrangement and combination. Therefore, the present invention will no longer describe the technical solutions after arrangement and combination one by one, but it should be understood that the technical solutions after arrangement and combination have been disclosed by the present invention.
[0083] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A machine learning prediction method for electricity consumption in a sewage treatment plant based on multi-level features, characterized by: The following steps are involved: Step 1: Data preprocessing; Step 2: Divide the training set and test set; Step 3: Model selection; Step 4: Use the optimal model.
2. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 1 is characterized by: Step one includes feature combing, encoding text type features, and filling missing values. The LabelEncoder algorithm is used to encode text type features, and the random forest algorithm is used to fill missing values of each feature.
3. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 2 is characterized by: The characteristics in step 1 include regional development characteristics, precipitation characteristics, and sewage treatment plant related characteristics; Regional development characteristics include the per capita water consumption of sewage treatment plants in that year (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), recycled water utilization (m 3 ), the ratio of industrial water consumption to domestic water consumption; the precipitation characteristic is annual precipitation (mm); the relevant characteristics of the sewage treatment plant include sewage treatment volume (10,000 tons), sewage treatment technology, and the reduction of each pollutant (mg / L).
4. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 2 or 3, characterized in that: The encoded text type features in step 1 use the LabelEncoder algorithm to encode the sewage treatment technology; sewage treatment technology includes A / O process, A 2 / O process, improved A 2 / O process, Baileke process, biological filter process, CASS process, Carrousel oxidation ditch process, Orbel oxidation ditch process, oxidation ditch process, and other processes are coded.
5. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 1 is characterized by: In step 2, the dataset is divided into training, validation, and test sets with the same distribution for multiple training; Division ratio: 25% for the test set, and the remaining 75% for the training set and validation set; Multiple training: After dividing the training set and the test set, use multiple training methods to further improve the generalization ability of the model.
6. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 4 is characterized by: Step three includes the following steps: Model selection and training: Four machine learning algorithms, XGBoost, LightGBM, CatBoost, and Random Forest, were selected for training. During the training process, the k-fold cross-validation method was used to ensure the generalization ability of the model. At the same time, the GridSearchCV method was used to tune the hyperparameters. Feature screening: For each model, a recursive feature screening method is used to screen out the feature sequence with the best performance; Model evaluation: Use R2 score and mean absolute error to evaluate the performance of the regression model; Model comparison: Four models were compared and the best performing model was selected based on its performance in terms of R2 score and mean absolute error (MAE).
7. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 6 is characterized by: Step 4 includes the following steps: Model selection and sequence: The optimal model was selected as the machine learning model for predicting the electricity consumption of sewage treatment plants; the optimal feature sequence was: sewage treatment volume (10,000 tons), sewage treatment technology, per capita water consumption (m 3 ), water consumption per 10,000 yuan of GDP (m 3 ), annual precipitation (mm); Model parameter settings: The optimal parameter settings include: 'booster':['gbtree'], 'gamma':[0.5], 'reg_alpha':[0.63], 'reg_lambda':[0.77], 'max_depth':[4], 'min_child_weight':[1], 'subsample':[0.76], 'colsample_bytree':[0.6], 'n_estimators':[246], 'learning_rate':[0.05], 'random_state':[42], 'max_bin':[2], 'verbosity':[0]; Model evaluation: R of the model on the training set 2 Value; Cross-validated R 2 Score; MAE value of the model; Model application: The final generated pkl format file is used by the front-end prediction software.
8. The method for predicting electricity consumption of a sewage treatment plant based on a multi-level feature machine learning method according to claim 7 is characterized by: In step 4, the XGBoost model used is an optimized distributed gradient boosting model. Given a number of training samples (x1, y1), (x2, y2) .... (xn, yn) consisting of an input vector x and an output vector y, the goal is to find an approximate function So that the loss function The loss value is the smallest, among which It is the predicted value, and its objective function is basically expressed as follows: Among them, the regularization term
Citation Information
Patent Citations
Sewage prediction system and sewage prediction method in production
CN110188945A
Sewage treatment technology
CN118324289A
Cited By
Municipal sludge yield prediction method and system based on multi-dimensional data driving
CN121303449A
Operation specification form template implementation method considering artificial intelligence utilization
CN122242473A