A model online learning method based on historical data
Through the model online learning method based on historical data, model parameters are updated in real time and concept drift is detected, which solves the problem of gradual model failure in the existing technology and achieves efficient adaptation to large-scale data and real-time prediction.
Patent Information
- Application Number
- CN202411103666.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-08-13
AI Technical Summary
The prior art has shortcomings in processing large-scale data and adapting to data changes, resulting in the model gradually failing over time and making accurate predictions of data flows in real time.
A model online learning method based on historical data is used to read and process historical data through a time series database, initialize model parameters, and update model parameters in real time when receiving new data, continuously monitor model performance, and perform concept drift detection and adaptation in a timely manner.
It improves the model's processing efficiency and adaptability to massive historical data, ensures the accuracy and real-time nature of predictions, and is suitable for fields such as finance, energy management, and traffic flow prediction.
Smart Images

Figure CN118643348B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine learning, and in particular to an online learning method of a model based on historical data. Background Art
[0002] With the advent of the big data era, the processing and analysis of massive data has become a major challenge in the field of machine learning. Traditional offline learning methods face problems such as high consumption of computing resources and long training time when processing large-scale data. At the same time, due to the dynamic changes of data, offline learning models often have difficulty adapting to new data distributions, resulting in reduced prediction or classification accuracy. Learning deep neural networks also faces many challenges, including gradient vanishing, reduced feature reuse, local minima, a large number of parameter and hyperparameter adjustments, changes in internal covariates during training, and the choice of regularization methods. Although there have been some promising advances, they are all designed to solve specific problems encountered in optimizing deep neural networks. Most of these methods assume that deep neural networks are trained in a batch learning setting, which requires all training data sets to be prepared before the learning task begins, which is impossible for many tasks in reality where data arrives in a stream.
[0003] How to learn deep neural networks from data streams in an online setting is an open problem in online deep learning. The main difficulty of online deep learning is that the settings of model capacity, complexity, etc. are very inflexible, that is, the model is static, while the data stream is dynamic. Dynamic learning makes online learning more scalable and memory-efficient. However, most existing online learning algorithms are designed to learn shallow models (such as linear methods or kernel methods) using online convex optimization, which cannot learn nonlinear functions in complex application scenarios. One possible way to learn online deep learning is to directly apply standard back-propagation training on only a single data sample in each round of online training. Although this method is simple, it will quickly fail for some key reasons. A key challenge is how to choose the right model capacity and network depth before starting online deep learning. If the model is too complex or the network is too deep, the learning process will converge very slowly (gradient vanishing and gradually reduced feature reuse), thus losing the advantages of online learning. At the other extreme, if the model is too simple, the learning ability will be particularly limited, and it will be difficult to learn complex patterns without depth. In batch learning, the way to solve this problem is usually to do model selection on the validation data. However, it is not practical to set validation data in an online setting, so it is not practical to use traditional model selection methods in online learning scenarios.
[0004] For example, publication number CN117077885A discloses a method, system and storage medium for evaluating the power generation capacity of a thermal power plant based on natural gradient boosting (NGBoost). The invention uses NGBoost as the core algorithm of the evaluation model, uses massive historical data from multiple thermal power plants to train the model, and regularly uses new historical power generation data for online learning of the evaluation model, updates the evaluation model parameters, and then constructs a power generation capacity evaluation model with certain parameter adaptability. The evaluation has high accuracy, fast speed, good effect, can process large-scale data, supports custom loss functions, and can evaluate the power generation capacity of thermal power plants online.
[0005] The above scheme has the following disadvantages: 1) This scheme uses natural gradient boosting (NGBoost) in the field of deep learning as the core algorithm, which has the advantages of processing large-scale data and supporting custom loss functions. However, this algorithm may not be good at capturing the inherent uncertainty and dynamic changes of load demand. 2) This scheme mainly focuses on the evaluation of power generation capacity and may give less consideration to forecast uncertainty. In the energy field, forecast uncertainty is an important consideration and is crucial for decision-making and risk management. 3) The flexibility and adaptability of online learning and model parameters of this scheme may not be strong.
[0006] Publication No. CN110381524B discloses a method, system and storage medium for online prediction of large-scale mobile traffic based on a bidirectional long short-term memory neural network (Bi-LSTM). The invention uses Bi-LSTM as the core algorithm of the prediction model, uses a large amount of historical traffic data in multiple scenarios to train the model, and uses transfer learning technology to transfer the trained model to achieve online prediction and learning of mobile traffic in specific scenarios, and then constructs a prediction model with adaptive capabilities to perform online prediction of mobile traffic in various scenarios, and simultaneously achieves dual prediction of uplink and downlink traffic in one model, with high prediction accuracy and strong generalization ability, and can predict mobile network traffic online.
[0007] The above scheme has the following disadvantages: 1) The BiLSTM model used in this scheme has a complex structure and usually requires efficient computing resources to meet the needs of rapid response. It usually takes a long time to train the model using massive historical traffic data. Using transfer learning technology to build a prediction model with adaptive capabilities to achieve online prediction and learning in various scenarios is uncertain, which may prolong the model development and deployment cycle. 2) The prediction effect of this scheme is highly dependent on the quality and quantity of historical traffic data. If the data is noisy, missing or incomplete, it may affect the training effect and prediction accuracy of the model. 3) For the BiLSTM model, selecting appropriate parameters can be a tedious and time-consuming process that requires rich experience and expertise.
[0008] Publication No. CN111325230B discloses an online learning method for a vehicle lane-changing decision model, including: in a manual driving mode, collecting traffic scene data and user driving data at preset time intervals; analyzing the traffic scene data and user driving data to determine the label data of each frame of data; generating a training data set, wherein a training data set includes traffic scene data, user driving data and corresponding label data obtained at a sampling time; storing the generated training data set in a user driving behavior database configured for the vehicle; and when the preset conditions are met, using the user driving behavior database to train the vehicle lane-changing decision model under each driving task type, and updating each vehicle lane-changing decision model. Based on the technical solution disclosed in the invention, the lane-changing behavior of the vehicle is more in line with the user's driving habits, so that the lane-changing behavior of the vehicle is more in line with the user's expectations, thereby improving the user's driving experience.
[0009] The above scheme has the following disadvantages: 1) Although this scheme can make the model better adapt to the driving habits of specific users through online learning, it may also cause the model to perform poorly when facing new and unseen traffic scenes. The generalization ability of the model is a problem that needs to be weighed. Over-reliance on the driving data of specific users may cause the model to lack versatility. 2) Integrating this method into the existing vehicle control system may require certain technical implementation difficulties, which involves multiple links such as data collection, processing, storage, transmission, and model training and deployment. It is necessary to ensure the coordination of each link and the consistency of data.
[0010] Publication No. CN107229970B discloses a method for adaptive dynamic self-learning online monitoring of shared direct drinking water quality, including: establishing a neural network input sample set; establishing a neural network output sample set; obtaining a normalized sample set; constructing a three-layer BP neural network model based on the normalized sample set; using the UKF algorithm to dynamically adjust the network weight threshold based on the three-layer BP neural network; using the UKFNN algorithm to model the massive data accumulated on the cloud server and obtain neural network parameters; achieving real-time prediction of the influencing factors of the water quality in the constant water tank that changes in real time; and achieving adaptive dynamic self-learning online monitoring of the shared direct drinking water quality based on the real-time prediction of the water quality in the constant water tank. The invention provides a method and system for dynamic self-learning online monitoring of the shared direct drinking water quality, which has the following technical effects or advantages: changing the traditional way of drinking water, providing users with a fast, healthy and convenient way of drinking water, and meeting the people's fast-paced living standards and high-quality living standards.
[0011] The above scheme has the following disadvantages: 1) This scheme uses neural networks and UKF algorithms for water quality prediction and model adjustment, which usually requires a lot of computing resources. If the computing power of the cloud server is limited, it may not be able to process a large amount of data in real time, resulting in delayed or inaccurate prediction results. 2) Since the neural network model needs to be updated and adjusted in real time to adapt to changes in water quality, professional technicians may be required to maintain and optimize the model. Without sufficient maintenance, the model may gradually lose accuracy. 3) This invention is mainly aimed at predicting and monitoring water quality in a constant water tank, and may not be suitable for scenarios where water quality changes are very frequent or unpredictable.
[0012] Currently, no effective solution has been proposed for the problems in the related technologies. Summary of the invention
[0013] In view of this, the present invention provides an online learning method for a model based on historical data to address the deficiencies of the offline learning method in the above-mentioned prior art in processing large-scale data and adapting to data changes, and to address the problem that the model gradually becomes ineffective over time, that is, the model's prediction accuracy for real-time data streams continues to decline.
[0014] In order to solve the above problems, the specific technical solutions adopted by the present invention are as follows:
[0015] A historical data-based model online learning method, the historical data-based model online learning method comprising the following steps:
[0016] S1. Based on the pre-set time series database, read the historical data and perform data processing before the model online learning to obtain the learning data set;
[0017] S2, initialize model parameters, train and test the model by learning the data set, and evaluate the model performance by calculating the error;
[0018] S3, receiving new data based on the time series database, and using the new data to update model parameters in real time based on the online learning mechanism;
[0019] S4: Use the updated model to make predictions and continue to monitor the model performance. If the model performance deteriorates, repeat step S3 to continue updating the model parameters.
[0020] Preferably, based on a preset time series database, reading historical data and performing data processing before model online learning to obtain a learning data set includes the following steps:
[0021] S11. Perform data cleaning on the acquired historical data to remove duplicate, erroneous and incomplete data;
[0022] S12. Use the random forest algorithm to predict and fill in missing values in the historical data after data cleaning;
[0023] S13, using the isolation forest algorithm to detect and process outliers in the historical data after missing value filling, to obtain a standard data set;
[0024] S14, extracting features from the standard data set based on a hybrid algorithm to obtain a feature data set;
[0025] S15. Use a sliding window method to group the obtained feature data set to obtain a learning data set.
[0026] Preferably, using the random forest algorithm to predict missing values in historical data after data cleaning and filling in missing values includes the following steps:
[0027] S121, selecting complete data from the historical data after data cleaning as a training set;
[0028] S122. Build a random forest model, and train the random forest model using the complete data in the training set;
[0029] S123, using the trained random forest model to predict missing values in the historical data after data cleaning, to obtain predicted missing values;
[0030] S124. Fill the missing positions corresponding to the historical data after data cleaning with the predicted missing values to obtain complete historical data.
[0031] Preferably, using the isolation forest algorithm to detect and process outliers in the historical data after missing value filling to obtain a standard data set includes the following steps:
[0032] S131, initializing the isolation forest model, and using the complete historical data to train the isolation forest model; constructing multiple isolation trees by randomly selecting features and cutting points, wherein the paths that do not meet the path length threshold represent outliers;
[0033] S132, predicting each sample in the complete historical data through the trained isolation forest model, calculating the outlier score for each sample, and setting a score threshold to distinguish normal values from outliers based on the score;
[0034] S133, identifying outliers in the complete historical data according to the set score threshold and outlier score, and deleting or replacing the outliers to obtain a standard data set;
[0035] S134, evaluating the effect of outlier processing, and adjusting the parameters of the isolation forest model according to the evaluation results, and repeating outlier detection and processing until the preset outlier detection performance index is reached.
[0036] Preferably, extracting features from a standard data set based on a hybrid algorithm to obtain a feature data set includes the following steps:
[0037] S141, extracting periodic features from the standard data set using a wavelet transform method to obtain periodic features;
[0038] S142, extracting trend features from the standard data set using a moving average method and an exponential smoothing method to obtain trend features;
[0039] S143, extracting seasonal features from the standard data set using a seasonal analysis method to obtain seasonal features;
[0040] S144. Combining the periodic features, trend features and seasonal features to form a complete feature data set.
[0041] Preferably, initializing model parameters, training and testing the model by learning the data set, and evaluating the model performance by calculating the error include the following steps:
[0042] S21. Create a class for storing parameters of the probability prediction model, the class includes Theta and Gamma, and stores initial covariance matrix parameters and mean vector parameters for the Theta class, and stores initial regularization parameters and standard deviation parameters for the Gamma class;
[0043] S22, dividing the learning data set into a training set, a test set and a validation set in a random manner;
[0044] S23, training the model using the training set, and recursively updating the model parameters through a dynamic programming method;
[0045] S24, using the test set to test the trained model, and calculating the error between the predicted value and the true value;
[0046] S25. Evaluate model performance. Evaluate the prediction effect of the model based on the error calculation results, and use the validation set for further model validation and parameter adjustment.
[0047] Preferably, receiving new data based on a time series database and updating model parameters in real time using the new data based on an online learning mechanism includes the following steps:
[0048] S31, receiving newly arrived data from the time series database in real time and using it as a new training sample;
[0049] S32, using new training samples, updating model parameters according to the online learning mechanism, and calculating prediction values and error values;
[0050] S33, performing concept drift detection on the updated model, and if the model detects concept drift, adjusting and updating the parameters of the model;
[0051] S34. Continue to receive new data in real time and repeat steps S31 to S33 to continuously update and optimize the model.
[0052] Preferably, updating the model parameters according to the online learning mechanism includes updating the covariance matrix, regularization parameters, standard deviation and mean;
[0053] Among them, the calculation formula for covariance matrix update is:
[0054] ;
[0055] The calculation formula for regularization parameter update is:
[0056] ;
[0057] The calculation formula for standard deviation update is:
[0058] ;
[0059] The calculation formula for mean update is:
[0060] ;
[0061] Where P new , γ new , σ new and η new They represent the updated covariance matrix, regularization parameter, standard deviation and mean respectively; P, γ, σ and η represent the updated covariance matrix, regularization parameter, standard deviation and mean respectively; l represents the learning rate; u represents the observation vector; u T represents the transpose of the observation vector; s represents the observation value.
[0062] Preferably, the calculation formula of the predicted value is:
[0063] ;
[0064] In the formula, represents the predicted value; u d represents the observation vector; represents the conditional mean vector corresponding to the marginal conditions; represents the conditional variance under observation conditions; It is used to indicate the conditional probability distribution under the observation condition; represents the conditional mean vector corresponding to the observation condition; represents the conditional variance under marginal conditions; represents the part of the conditional mean vector under marginal conditions that is related to the observation error; represents the error value at the previous moment; T represents the transposed matrix.
[0065] Preferably, the calculation formula of the error value is:
[0066] ;
[0067] In the formula, Indicates the error value at the current moment; represents the conditional variance under observation conditions; represents the conditional variance under marginal conditions; represents the part of the conditional mean vector under marginal conditions that is related to the observation error; Indicates the error value at the previous moment.
[0068] The beneficial effects of the present invention are:
[0069] 1. The present invention utilizes a high-performance time series library to store and read data, as well as reasonable data preprocessing and grouping strategies, which greatly improves the efficiency of model training and can process massive amounts of historical data. Through the online learning mechanism, the model can adapt well to data changes, update parameters in real time according to new data and online prediction results, and perform concept drift detection and adaptation in a timely manner, thereby ensuring the accuracy and real-time nature of the prediction.
[0070] 2. The present invention has important practical value for processing large-scale data and adapting to data changes. It can be applied to finance, energy management, traffic flow forecasting, retail and e-commerce, etc. to improve forecasting accuracy, enhance decision-making support, optimize resource allocation, and achieve sustainable development. It can be promoted and applied in the power industry, such as power load forecasting, energy consumption analysis, fault prediction and maintenance, new energy access and optimization, etc., which will help power companies to grasp market demand more accurately, improve power production efficiency, improve the reliability, stability and intelligence level of the power system, promote the development of new energy, and promote the green transformation of the power industry. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0072] Figure 1 is a flow chart of a model online learning method based on historical data according to an embodiment of the present invention;
[0073] Figure 2 is a simplified flow chart of a model online learning method based on historical data according to an embodiment of the present invention;
[0074] Figure 3 is a schematic diagram of concept drift classification in an online learning method of a model based on historical data according to an embodiment of the present invention;
[0075] Figure 4 It is a schematic diagram of model fitting effect and accuracy before and after concept drift detection and adaptation in a model online learning method based on historical data according to an embodiment of the present invention;
[0076] Figure 5 This is a diagram of the overall fitting effect of online model learning based on power transformer data in an online model learning method based on historical data according to an embodiment of the present invention;
[0077] Figure 6 is an error calculation diagram of online learning of a model based on power transformer data in an online learning method of a model based on historical data according to an embodiment of the present invention;
[0078] Figure 7 This is a local fitting effect diagram of online model learning based on power transformer data in an online model learning method based on historical data according to an embodiment of the present invention;
[0079] Figure 8 This is a diagram of the overall fitting effect of online learning of a model based on power generation in an online model learning method based on historical data according to an embodiment of the present invention;
[0080] Fig. 9 is an error calculation diagram of online learning of a model based on power generation in an online learning method of a model based on historical data according to an embodiment of the present invention;
[0081] Fig.10 This is a local fitting effect diagram of online learning of a model based on power generation in an online model learning method based on historical data according to an embodiment of the present invention;
[0082] Fig.11 This is a diagram of the overall fitting effect of online learning of a model based on residential electricity consumption in an online learning method of a model based on historical data according to an embodiment of the present invention;
[0083] Fig.12is an error calculation diagram of online learning of a model based on residential electricity consumption in an online learning method of a model based on historical data according to an embodiment of the present invention;
[0084] Fig.13 This is a local fitting effect diagram of online learning of a model based on residential electricity consumption in an online learning method of a model based on historical data according to an embodiment of the present invention;
[0085] Fig.14 It is a schematic diagram of grouping by a sliding window in an online learning method of a model based on historical data according to an embodiment of the present invention. DETAILED DESCRIPTION
[0086] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0087] According to an embodiment of the present invention, a model online learning method based on historical data is provided.
[0088] The present invention is further described with reference to the accompanying drawings and specific embodiments. Figure 1-2 As shown, according to the online model learning method based on historical data according to an embodiment of the present invention, the online model learning method based on historical data includes the following steps:
[0089] S1. Based on the pre-set time series database, read the historical data and perform data processing before the model online learning to obtain the learning data set;
[0090] It should be noted that the pre-set time series database can be selected from high-performance time series libraries such as InfluxDB (Influx Database, a time series database) or IoTDB (Internet of Things Database) to achieve high-speed reading and writing and real-time analysis of massive data.
[0091] The specific real-time method of the time series library is to use the driver to connect to the database, create a data table to store data, and specify the name and data type for each column. For time series data, the timestamp is usually used as the automatically generated primary index, and other fields (such as the values and attributes of various records) are used as columns of the table; receive data from the real-time data stream and use the INSERT statement to insert a row of data into the data table; use the SELECT statement to query the data in the data table by time range, field, aggregate query, etc.
[0092] As a preferred implementation, based on a preset time series database, historical data is read and data processing is performed before model online learning to obtain a learning data set, including the following steps:
[0093] S11. Perform data cleaning on the acquired historical data to remove duplicate, erroneous and incomplete data;
[0094] S12. Use the random forest algorithm to predict and fill in missing values in the historical data after data cleaning;
[0095] It should be noted that for missing values, in addition to common mean interpolation and similar mean interpolation methods, the Random Forest algorithm of the machine learning model can be used to predict missing values. The specific steps of the Random Forest algorithm are as follows:
[0096] 1) Data preparation: Split the data set into training set and test set;
[0097] 2) Build a Random Forest Model: Use the complete data (features with no missing values) from the training set to train a Random Forest model. Random Forest works by building multiple decision trees and averaging their predictions, which helps reduce overfitting and improves prediction performance.
[0098] 3) Use the model to predict missing values: For features with missing values, you can use the random forest model to predict these missing values. For each instance with missing values, use all other features except the missing features as input and make predictions through the random forest model. The predicted values can be used as estimates of the missing features.
[0099] 4) Evaluate the prediction effect: Use a test set or known true values to evaluate the accuracy of predicting missing values; use indicators such as mean squared error and mean absolute error to evaluate.
[0100] 5) Data filling: Use the values predicted by the random forest model to fill in the missing values in the original data set; after replacing the original missing values, the data set can be used for further analysis or modeling. If the prediction effect is not ideal, you can adjust the parameters of the random forest model (such as the number of trees, maximum depth, etc.) to optimize the performance.
[0101] As a preferred implementation, using the random forest algorithm to predict missing values in historical data after data cleaning and filling in missing values includes the following steps:
[0102] S121, selecting complete data from the historical data after data cleaning as a training set;
[0103] S122. Build a random forest model, and train the random forest model using the complete data in the training set;
[0104] S123, using the trained random forest model to predict missing values in the historical data after data cleaning, to obtain predicted missing values;
[0105] S124. Fill the missing positions corresponding to the historical data after data cleaning with the predicted missing values to obtain complete historical data.
[0106] S13, using the isolation forest algorithm to detect and process outliers in the historical data after missing value filling, to obtain a standard data set;
[0107] It should be noted that, for outliers, in addition to deletion or replacement, you can consider using algorithms such as Isolation Forest to detect and process them. The specific steps of the Isolation Forest algorithm are as follows:
[0108] 1) Data preparation: Load the dataset, encode categorical variables, and use the random forest algorithm to handle missing values.
[0109] 2) Training Isolation Forest Model: Initialize the Isolation Forest model. Isolation Forest consists of multiple isolation trees (IsolationTrees). Use the entire dataset (no need to split it into training and test sets, because Isolation Forest is an unsupervised learning algorithm) to train the Isolation Forest model. Isolation Forest builds isolation trees by randomly selecting features and cut points. Shorter paths usually represent outliers.
[0110] 3) Outlier detection: Each sample in the dataset is predicted by the trained isolation forest model. The model returns an outlier score (usually called anomaly score or path length) for each sample, which reflects the average path length of the sample in the isolation tree. A threshold is set based on the anomaly score to distinguish between normal values and outliers. Usually, the anomaly score of an outlier is higher than that of a normal value.
[0111] 4) Handling outliers: Identify outliers in the data set based on the anomaly score and the set threshold. You can choose to delete, replace, or perform other special processing on outliers. For example, you can use the mean, median, or other appropriate statistics to replace outliers, or decide how to handle these outliers based on business logic.
[0112] 5) Evaluation and iteration: Adjust the parameters of the isolation forest model (such as the number of trees, subsample size, etc.) to optimize the effect of anomaly detection. Repeat outlier detection and processing until satisfactory results are achieved.
[0113] As a preferred implementation, using the isolation forest algorithm to detect and process outliers in the historical data after missing value filling to obtain a standard data set includes the following steps:
[0114] S131, initializing the isolation forest model, and using the complete historical data to train the isolation forest model; constructing multiple isolation trees by randomly selecting features and cutting points, wherein the paths that do not meet the path length threshold represent outliers;
[0115] S132, predicting each sample in the complete historical data through the trained isolation forest model, calculating the outlier score for each sample, and setting a score threshold to distinguish normal values from outliers based on the score;
[0116] S133, identifying outliers in the complete historical data according to the set score threshold and outlier score, and deleting or replacing the outliers to obtain a standard data set;
[0117] S134, evaluating the effect of outlier processing, and adjusting the parameters of the isolation forest model according to the evaluation results, and repeating outlier detection and processing until the preset outlier detection performance index is reached.
[0118] Extract features from the standard data set based on a hybrid algorithm to obtain a feature data set;
[0119] Specifically, feature extraction is divided into periodic feature extraction and trend feature extraction.
[0120] If there are obvious periodic characteristics in the influencing factors such as seasonal changes, economic indicators, machine operating status, equipment failure cycle, etc., the wavelet transform method can be used to decompose the time series data into multiple wavelet coefficients of different frequencies, and the periodic characteristics can be extracted by analyzing the distribution and changes of these wavelet coefficients.
[0121] If the data shows long-term rising, falling or fluctuating trend characteristics over a long period of time, such as stock prices, temperature changes, population growth, etc., the moving average method and exponential smoothing method can be used to approximate the overall trend of the data.
[0122] Of course, the extraction of periodic and trend features is not isolated. Sometimes the data may contain both periodic and trend components. In this case, methods such as seasonal decomposition can be used to decompose the time series data into three parts: trend, season, and residual, so as to better capture the periodic and trend characteristics in the data.
[0123] As a preferred implementation, extracting features from a standard data set based on a hybrid algorithm to obtain a feature data set includes the following steps:
[0124] S141, extracting periodic features from the standard data set using a wavelet transform method to obtain periodic features;
[0125] It should be noted that the wavelet transform method can effectively extract the periodic characteristics in time series data, especially when there are multiple periodic factors (such as seasonal changes, economic indicators, machine operation status, equipment failure cycle, etc.). The specific implementation steps are as follows:
[0126] 1) Select the appropriate wavelet basis function: The wavelet basis function determines the characteristics of the wavelet transform, and different basis functions are suitable for different application scenarios. Common basis functions include Haar, Daubechies, Morlet, etc. Considering the complex periodicity of the data that requires fine analysis, the wavelet basis function Daubechies with good regularity and frequency resolution is selected.
[0127] 2) Determine the number of decomposition layers: Wavelet transform can decompose the original signal into multiple sub-signals (or wavelet coefficients) of different frequencies. The number of decomposition layers determines the number of sub-signals and their corresponding frequency ranges. Considering the periodic characteristics of the data and computational efficiency issues, a lower number of decomposition layers is selected, which can be set to 1 or 2.
[0128] 3) Perform wavelet transform: Use the selected wavelet basis function and decomposition level to perform wavelet transform on the time series data. This will produce a series of wavelet coefficients that represent the characteristics of the original data at different frequencies and time scales.
[0129] 4) Analyze wavelet coefficients: Draw graphs or images of wavelet coefficients, observe their distribution and changes, and identify periodic features in the data. Analyze the amplitude and phase information of wavelet coefficients to understand the intensity and time position of different frequency components in the time series.
[0130] 5) Extract periodic features: Based on the analysis results of the wavelet coefficients, the wavelet coefficients related to the periodic features are extracted by setting thresholds, identifying peaks, etc.
[0131] S142, extracting trend features from the standard data set using a moving average method and an exponential smoothing method to obtain trend features;
[0132] It should be noted that the moving average method is a simple time series smoothing technique that eliminates random fluctuations by averaging data within a certain period of time, thereby revealing the long-term trend of the data. The specific steps are as follows:
[0133] 1) Select a moving average window size (e.g., 24 periods, 48 periods, etc.).
[0134] 2) For each time point, calculate the average of the data at that time point and the data at the previous time points.
[0135] 3) Take these averages as a new time series, which is usually smoother than the original series and better reflects the overall trend.
[0136] Exponential smoothing is a weighted moving average method that gives more weight to recent data and less weight to distant data. This method can better capture recent changes in data. The specific steps are as follows:
[0137] 1) Select a smoothing factor (value range is between 0 and 1).
[0138] 2) For each time point, calculate the exponential smoothing value of that point, which is the weighted average of the exponential smoothing value of the previous time point and the current data point.
[0139] 3) Repeat this process until the entire time series is smoothed.
[0140] S143, extracting seasonal features from the standard data set using a seasonal analysis method to obtain seasonal features;
[0141] It should be noted that the seasonal decomposition method decomposes time series data into three parts: trend, season, and residual, and captures the periodicity and trend characteristics in the data. The principle is as follows:
[0142] 1) Trend decomposition: Capturing the long-term changes or overall trend of the time series by fitting a smooth curve, such as using smoothing techniques such as moving average.
[0143] 2) Seasonal decomposition: To identify and quantify periodic changes in time series, such periodic changes are usually fixed and repeat at a fixed frequency, such as the seven days of a week, the four seasons of a year, etc. Seasonal effects are obtained by calculating the mean (or median, depending on whether the decomposition model is additive or multiplicative) of each time point, which is calculated based on all observations within the periodic interval (such as month, quarter, etc.).
[0144] 3) Residual decomposition: The residual is what remains after subtracting the trend and seasonal components from the original time series. In theory, if the trend and seasonal components are correctly extracted, the residual should be random and contain no systematic patterns. The residual can be used to check the rationality of the decomposition and to assess other potential unmodeled effects.
[0145] You can choose to use an additive model or a multiplicative model based on the characteristics of your data. An additive model assumes that the trend, seasonality, and residuals are additive, while a multiplicative model assumes that they are multiplicative. For example, if the seasonal effect changes with the level of the trend (i.e., the seasonal effect is larger at higher trend levels), then a multiplicative model may be more appropriate.
[0146] The specific steps for implementing seasonal decomposition are as follows:
[0147] 1) Loading data: Load time series data to obtain a DataFrame or Series.
[0148] 2) Perform seasonal decomposition: Use the seasonal_decompose function to decompose the data. You can choose different model parameters, such as model='additive' or model='multiplicative', depending on whether the data is an additive model or a multiplicative model.
[0149] 3) View the results and further analyze: The seasonal_decompose function returns a seasonal decomposition result object, which contains three parts: trend, season, and residual. These parts can be visualized using the drawing method to obtain a chart containing three parts (trend, season, and residual). The trend part shows the long-term changes in the data, the season part shows the cyclical changes in the data, and the residual part is the remaining part after subtracting the trend and season parts from the original data. You can further use the trend part to predict future data points, or use the season part to understand the cyclical pattern of the data.
[0150] S144. Combining the periodic features, trend features and seasonal features to form a complete feature data set.
[0151] S15. Use a sliding window method to group the obtained feature data set to obtain a learning data set.
[0152] It should be noted that the method of grouping the obtained feature data set is as follows:
[0153] 1) You can define batches of different sizes based on the periodic pattern of the time series data to group the data non-uniformly. 2) You can use the clustering algorithm K-means to divide the data into groups with similar characteristics, and then batch them according to these groups. 3) You can use the sliding window method to group the data, with each window containing a fixed number of data points or data within a time range.
[0154] The data is grouped and trained using a sliding window-based method. The specific steps are as follows:
[0155] Step 1: Store the data in the time series database at hourly intervals;
[0156] Step 2: Group the data into batches of a certain size based on real-time requirements. For example, if you want to achieve ultra-short-term predictions of 4-6 hours, you can group 4-6 frames of data into a group; if you want to achieve short-term predictions of 24 hours, you can group 24 frames of data into a group.
[0157] Step 3: Use sliding window to group, feed the two sets of data into model training, and predict the next set of data, such as Fig.14 shown.
[0158] S2, initialize model parameters, train and test the model by learning the data set, and evaluate the model performance by calculating the error;
[0159] As a preferred embodiment, initializing model parameters, training and testing the model by learning data sets, and evaluating model performance by calculating errors include the following steps:
[0160] S21. Create a class for storing parameters of the probability prediction model, the class includes Theta and Gamma, and stores initial covariance matrix parameters and mean vector parameters for the Theta class, and stores initial regularization parameters and standard deviation parameters for the Gamma class;
[0161] It should be noted that some parameters and variables of the online learning model are initialized by defining a function initialize. The input parameters of the function are defined as C and R, which represent the number of states and observations of the hidden Markov model respectively. Their actual physical meanings are the length of the calendar information and the length of the characteristic vector of the observation value. For example, the input parameters can be set to C=48 and R=3, which means that the input of each training of the online learning model is 48 hours of data, including 3 features. Taking power generation prediction as an example, the temperature, humidity and wind speed data collected every hour can be used as features.
[0162] Two classes, Theta and Gamma, and some initialized variables are defined inside the function. The function returns the initialized Theta and Gamma class instances for subsequent calculations. The variables in the Theta class mainly represent the parameters of the state conditional probability distribution, including the conditional probability distribution under edge and observation conditions. The variables in the Gamma class represent the parameters of the transition probability distribution between the state and the observation. The variables that need to be initialized in these two classes are:
[0163] 1) Initialize the variables in the Theta class, including the probability distribution, weights, and probability distribution under edge conditions, the probability distribution under observation conditions, and the weights and probability distribution under observation conditions.
[0164] 2) Initialize the variables in the Gamma class, including the conditional probability distribution under edge conditions, the conditional probability distribution under observation conditions, and the transition probability distribution. At the same time, initialize the transition probability distribution matrix and the observation probability distribution matrix.
[0165] The implementation principle of the model parameter update method is the learning and updating algorithm of the double-layer Bayesian classifier. Specifically, it is a Bayesian classifier of Gaussian mixture model, which can be used to classify data. The model update is implemented by defining the update_model function. Three parameter updates are performed in the model update function, namely:
[0166] 1) Use the dynamic programming method to recursively update the parameters of each classifier. In each iteration, the weight, variance, and covariance matrices of the current classifier are calculated and updated into Theta and Gamma.
[0167] 2) Calculate the conditional probability distribution under the marginal conditions of the current classifier and update it into Theta and Gamma.
[0168] 3) Calculate the conditional probability distribution under the current classifier observation conditions and update it into Theta and Gamma.
[0169] Finally, the updated Theta and Gamma are returned.
[0170] These three updates are actually implemented by calling the model parameter update function update_parameters, but different entry parameters are set according to the variables and matrices initialized in the Theta and Gamma classes. Model parameter update is to update the parameters used in the particle swarm optimization algorithm, including the covariance matrix, regularization parameter, standard deviation and mean.
[0171] S22, dividing the learning data set into a training set, a test set and a validation set in a random manner;
[0172] S23, training the model using the training set, and recursively updating the model parameters through a dynamic programming method;
[0173] S24, using the test set to test the trained model, and calculating the error between the predicted value and the true value;
[0174] It should be noted that in order to verify the effectiveness and accuracy of the method of the present invention, based on the massive historical data of three types of power generation, residential power consumption, and power transformers, the fitting effect and error calculation results of the model online learning are as follows: Figure 5-13 As shown in the figure, there are many data points. When the two lines are closer, the fitting effect is better and the prediction result is more accurate.
[0175] S25. Evaluate model performance. Evaluate the prediction effect of the model based on the error calculation results, and use the validation set for further model validation and parameter adjustment.
[0176] It should be noted that the method of evaluating model performance is to calculate the error between the prediction results (predictions) and the true value (groundtruth), including MAPE (mean absolute percentage error) and RMSE (root mean square error), in order to verify the model fitting effect. The calculation formulas of MAPE and RMSE are:
[0177] ;
[0178] ;
[0179] Where MAPE and RMSE represent mean absolute percentage error and root mean square error, respectively; N represents the size of the dataset; t represents the timestamp; predictions t Represents the predicted value, groundtruth t Represents the true value.
[0180] S3, receiving new data based on the time series database, and using the new data to update model parameters in real time based on the online learning mechanism;
[0181] It should be noted that using online learning mechanism to update model parameters is actually to update predictions through continuous online learning during the prediction process of the model. The implementation principle is a prediction function of a support vector machine (SVM). SVM is a binary classification model that represents data points as feature vectors and maps these vectors to a separating hyperplane. This separating hyperplane can be used to classify new input data.
[0182] By defining the prediction function, the prediction update is realized. The input parameters include:
[0183] 1) The parameter matrix of the SVM model, including the weight matrix, activation function, and bias.
[0184] 2) : A list containing the input data feature vectors, where is the label of the sample, is the eigenvector.
[0185] 3) : A list containing the input data feature vectors, where is the class of the feature vector.
[0186] The main implementation steps of the function include:
[0187] 1) Initialize the prediction value matrix and the error matrix ;
[0188] 2) For each feature vector, calculate the activation function according to its category c and ;
[0189] in, ;
[0190] 3) Calculation ,in It is a package that contains 1, and Array of;
[0191] Among them, u r =[1,α1,α2] T ; That is, convert the one-dimensional array into a column vector.
[0192] 4) Calculate the predicted value and error according to the formula and return the predicted value matrix and the error matrix .
[0193] As a preferred implementation, receiving new data based on a time series database and updating model parameters in real time using the new data based on an online learning mechanism include the following steps:
[0194] S31, receiving newly arrived data from the time series database in real time and using it as a new training sample;
[0195] S32, using new training samples, updating model parameters according to the online learning mechanism, and calculating prediction values and error values;
[0196] Specifically, the model parameters including covariance matrix, regularization parameter, standard deviation and mean update are updated according to the online learning mechanism;
[0197] Among them, the calculation formula for covariance matrix update is:
[0198] ;
[0199] The calculation formula for regularization parameter update is:
[0200] ;
[0201] The calculation formula for standard deviation update is:
[0202] ;
[0203] The calculation formula for mean update is:
[0204] ;
[0205] Where P new , γ new , σ new and η new They represent the updated covariance matrix, regularization parameter, standard deviation and mean respectively; P, γ, σ and η represent the updated covariance matrix, regularization parameter, standard deviation and mean respectively; l represents the learning rate; u represents the observation vector; u T represents the transpose of the observation vector; s represents the observation value.
[0206] Specifically, the calculation formula for the predicted value is:
[0207] ;
[0208] In the formula, represents the predicted value; u d represents the observation vector; represents the conditional mean vector corresponding to the marginal conditions; represents the conditional variance under observation conditions; It is used to indicate the conditional probability distribution under the observation condition; represents the conditional mean vector corresponding to the observation condition; represents the conditional variance under marginal conditions; represents the part of the conditional mean vector under marginal conditions that is related to the observation error; represents the error value at the previous moment; T represents the transposed matrix.
[0209] The error value is calculated as follows:
[0210] ;
[0211] In the formula, Indicates the error value at the current moment; represents the conditional variance under observation conditions; represents the conditional variance under marginal conditions; represents the part of the conditional mean vector under marginal conditions that is related to the observation error; Indicates the error value at the previous moment.
[0212] S33, performing concept drift detection on the updated model, and if the model detects concept drift, adjusting and updating the parameters of the model;
[0213] It should be noted that the distribution or nature of massive historical data may change over time, resulting in the inability of previously learned models to accurately adapt to new data. This means that when an online learning model receives new data samples, its prediction performance may decline due to changes in data characteristics, resulting in concept drift or even catastrophic forgetting. Concept drift can occur in different ways, such as Figure 3 shown.
[0214] Concept drift detection can be performed based on data distribution and error rate. The model can be rebuilt or partially adjusted to adapt to concept drift, or a more comprehensive base classifier performance metric can be designed through ensemble learning to adapt to scenarios with mixed or arbitrary evolution types of concept drift. The model fitting effect and accuracy before and after concept drift detection and adaptation are shown in Figure 2. Figure 4 shown.
[0215] Specifically, statistical tests are used to detect changes in the data distribution. For example, statistical properties of two windows (time periods) in a data stream are calculated, and tests such as the Hoeffding Bound are used to determine whether these statistical properties have changed significantly. When comparing a reference window and a recent window, in addition to the mean, other metrics can be compared, such as estimating whether they are generated by the same distribution. To estimate the distribution, different methods can sometimes be applied to longer and shorter time windows. If the accuracy of the recent window is higher than the accuracy of the longer window, concept drift may have occurred, because if the concept remains unchanged, the longer window should be more accurate.
[0216] Error rate based methods for concept drift detection. Monitor the performance of the prediction metric and if the performance changes, concept drift may have occurred. For example, if the error rate of the model suddenly increases, this may be a sign of concept drift.
[0217] S34. Continue to receive new data in real time and repeat steps S31 to S33 to continuously update and optimize the model.
[0218] S4: Use the updated model to make predictions and continue to monitor the model performance. If the model performance deteriorates, repeat step S3 to continue updating the model parameters.
[0219] In summary, with the help of the above technical scheme of the present invention, the present invention uses a high-performance time series library to store and read data, as well as reasonable data preprocessing and grouping strategies, so that the efficiency of model training is greatly improved, and it can process massive historical data. Through the online learning mechanism, the model can adapt well to data changes, update parameters in real time according to new data and online prediction results, and timely perform concept drift detection and adaptation, so as to ensure the accuracy and real-time performance of the prediction; the present invention has important practical value for processing large-scale data and adapting to data changes, and can be applied to finance, energy management, traffic flow prediction, retail and e-commerce and other fields to improve prediction accuracy, enhance decision support, optimize resource allocation, and achieve sustainable development. It can be promoted and applied in the power industry, such as power load forecasting, energy consumption analysis, fault prediction and maintenance, new energy access and optimization, etc., which will help power companies to grasp market demand more accurately, improve power production efficiency, improve the reliability, stability and intelligence level of the power system, promote the development of new energy, and promote the green transformation of the power industry.
[0220] It should be understood by those skilled in the art that the embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program code.
[0221] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A model online learning method based on historical data, characterized in that: The online learning method of the model based on historical data includes the following steps: S1. Based on the pre-set time series database, read the historical data and perform data processing before the model online learning to obtain the learning data set; The historical data is at least one of generated power, residential power consumption and power transformers; S2, initializing model parameters, training and testing the model using the learning data set, and evaluating model performance by calculating errors; S3, receiving new data based on the time series database, and using the new data to update model parameters in real time based on the online learning mechanism; S4, using the updated model to make predictions and continuously monitoring the model performance, if the model performance deteriorates, repeating step S3 to continue updating the model parameters; The method of reading historical data based on a preset time series database and performing data processing before online model learning to obtain a learning data set includes the following steps: S11. Perform data cleaning on the acquired historical data to remove duplicate, erroneous and incomplete data; S12. Use the random forest algorithm to predict and fill in missing values in the historical data after data cleaning; S13, using the isolation forest algorithm to detect and process outliers in the historical data after missing value filling, to obtain a standard data set; S14, extracting features from the standard data set based on a hybrid algorithm to obtain a feature data set; S15, grouping the obtained feature data set using a sliding window method to obtain a learning data set; The feature extraction of the standard data set based on the hybrid algorithm to obtain the feature data set includes the following steps: S141, extracting periodic features from the standard data set using a wavelet transform method to obtain periodic features; S142, extracting trend features from the standard data set using a moving average method and an exponential smoothing method to obtain trend features; S143, extracting seasonal features from the standard data set using a seasonal analysis method to obtain seasonal features; S144, combining the periodicity feature, the trend feature and the seasonality feature to form a complete feature data set; Receiving new data based on the time series database and updating model parameters in real time using the new data based on the online learning mechanism includes the following steps: S31, receiving newly arrived data from the time series database in real time and using it as a new training sample; S32, using new training samples, updating model parameters according to the online learning mechanism, and calculating prediction values and error values; S33, performing concept drift detection on the updated model, and if the model detects concept drift, adjusting and updating the parameters of the model; S34, continue to receive new data in real time, and repeat steps S31 to S33 to continuously update and optimize the model; The updating of model parameters according to the online learning mechanism includes updating of covariance matrix, regularization parameter, standard deviation and mean; Wherein, the calculation formula for updating the covariance matrix is: The calculation formula for updating the regularization parameter is: c new =1+lγ; The calculation formula for the standard deviation update is: The calculation formula for the mean update is: Where P new , γ new , σ new and η new They represent the updated covariance matrix, regularization parameter, standard deviation and mean respectively; P, γ, σ and η represent the updated covariance matrix, regularization parameter, standard deviation and mean respectively; l represents the learning rate; u represents the observation vector; u T represents the transpose of the observation vector; s represents the observation value.
2. The online learning method of a model based on historical data according to claim 1, characterized in that: The method of using the random forest algorithm to predict missing values in the historical data after data cleaning and filling includes the following steps: S121, selecting complete data from the historical data after data cleaning as a training set; S122. Build a random forest model, and train the random forest model using the complete data in the training set; S123, using the trained random forest model to predict missing values in the historical data after data cleaning, to obtain predicted missing values; S124. Fill the missing positions corresponding to the historical data after data cleaning with the predicted missing values to obtain complete historical data.
3. The online learning method of a model based on historical data according to claim 2, characterized in that: The method of using the isolation forest algorithm to detect and process outliers in the historical data after missing value filling to obtain a standard data set includes the following steps: S131, initializing the isolation forest model, and using the complete historical data to train the isolation forest model; constructing multiple isolation trees by randomly selecting features and cutting points, wherein the paths that do not meet the path length threshold represent outliers; S132, predicting each sample in the complete historical data through the trained isolation forest model, calculating the outlier score for each sample, and setting a score threshold to distinguish normal values from outliers based on the score; S133, identifying outliers in the complete historical data according to the set score threshold and outlier score, and deleting or replacing the outliers to obtain a standard data set; S134, evaluating the effect of outlier processing, and adjusting the parameters of the isolation forest model according to the evaluation results, and repeating outlier detection and processing until the preset outlier detection performance index is reached.
4. The online learning method of a model based on historical data according to claim 1, characterized in that: Initializing the model parameters, training and testing the model using the learning data set, and evaluating the model performance by calculating the error include the following steps: S21, creating a class for storing parameters of the probability prediction model, the class includes Theta and Gamma, and stores initial covariance matrix parameters and mean vector parameters for the Theta class, and stores initial regularization parameters and standard deviation parameters for the Gamma class; S22, dividing the learning data set into a training set, a test set and a validation set in a random manner; S23, training the model using the training set, and recursively updating the model parameters through a dynamic programming method; S24, using the test set to test the trained model, and calculating the error between the predicted value and the true value; S25. Evaluate model performance. Evaluate the prediction effect of the model based on the error calculation results, and use the validation set for further model validation and parameter adjustment.
5. The online learning method of a model based on historical data according to claim 4, characterized in that: The calculation formula of the predicted value is: Where pred_s i+1 represents the predicted value; u d represents the observation vector; represents the conditional mean vector corresponding to the marginal conditions; represents the conditional variance under observation conditions; u r It is used to indicate the conditional probability distribution under the observation condition; represents the conditional mean vector corresponding to the observation condition; represents the conditional variance under marginal conditions; represents the part of the conditional mean vector under marginal conditions that is related to the observation error; e i represents the error value at the previous moment; T represents the transposed matrix.
6. The online learning method of a model based on historical data according to claim 5, characterized in that: The calculation formula of the error value is: In the formula, e i+1 Indicates the error value at the current moment; represents the conditional variance under observation conditions; represents the conditional variance under marginal conditions; represents the part of the conditional mean vector under marginal conditions that is related to the observation error; e i Indicates the error value at the previous moment.
Citation Information
Patent Citations
Shared direct drinking water quality adaptive dynamic self-learning online monitoring system
CN107229970B
A Bi-LSTM-based method, system, and storage medium for large-scale mobile traffic online prediction.
CN110381524B
Online learning methods and devices for vehicle lane-changing decision models
CN111325230B
Thermal power plant power generation capability evaluation method and system based on NGBoost, and storage medium
CN117077885A
Short-term reactive load prediction method and device based on ensemble empirical mode
CN112163710A