Time series prediction method and device, electronic equipment and storage medium

By introducing a trend prediction model and a double-loss training method into time series forecasting, the problem of trend inconsistency in deep learning forecasting is solved, and the numerical accuracy and trend consistency are improved simultaneously, meeting the needs for accurate forecasting of energy prices and financial markets.

CN122241076APending Publication Date: 2026-06-19XIAN JIAOTONG LIVERPOOL UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XIAN JIAOTONG LIVERPOOL UNIV
Filing Date
2026-03-16
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Existing deep learning prediction methods cannot guarantee that the trend of predicted values ​​is consistent with the actual trend in time series prediction. This leads to the problem that the predicted values ​​are correct but the direction is wrong in time series with strong volatility, resulting in low accuracy of prediction results.

Method used

By acquiring sample time frame data, the trend prediction results are output using a pre-trained trend prediction model. Combined with the time series prediction model, numerical error loss and trend consistency loss are calculated. The time series prediction model is trained using a dual-loss fusion method to ensure that numerical accuracy and trend consistency are improved simultaneously.

Benefits of technology

It enables accurate and controllable forecasting in areas such as energy prices and financial markets, avoiding the phenomenon of correct numerical values ​​but incorrect directions, and improving long-term forecasting performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122241076A_ABST
    Figure CN122241076A_ABST
Patent Text Reader

Abstract

This invention discloses a time series forecasting method, apparatus, electronic device, and storage medium. The method includes: acquiring sample time frame data, processing the sample time frame data using a pre-trained trend forecasting model, and outputting a trend forecasting result for the sample time frame data; inputting the sample time frame data into a time series forecasting model to be trained for processing, outputting a time series forecasting result, and calculating a numerical error loss based on the time series forecasting result and the true value of the sample time frame data; determining a trend consistency loss based on a preset trend consistency constraint loss function, according to the trend forecasting result and the time series forecasting result; determining a total loss based on the numerical error loss and the trend consistency loss, and adjusting the parameters of the time series forecasting model in reverse according to the total loss to train the time series forecasting model; and processing the time frame data to be predicted based on the trained time series forecasting model to output a time series forecasting result for a future time period.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a time series prediction method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the rapid development of artificial intelligence technology, time series forecasting has been widely used in fields such as energy price forecasting, financial market analysis, power load forecasting, and meteorological change modeling.

[0003] Existing deep learning prediction methods, such as Long Short-Term Memory (LSTM) networks, perform well in numerical fitting. However, they still have certain shortcomings: traditional models only minimize numerical errors and cannot guarantee that the predicted trend is consistent with the actual trend. This leads to the problem of numerically correct but directionally incorrect predictions in highly volatile time series, resulting in low accuracy. Therefore, a new time series prediction method is urgently needed. Summary of the Invention

[0004] This invention provides a time series forecasting method, apparatus, electronic device, storage medium, and computer program product.

[0005] According to one aspect of the present invention, a time series forecasting method is provided, comprising: Acquire sample time frame data, process the sample time frame data through a pre-trained trend prediction model, and output the trend prediction results of the sample time frame data. The sample time frame data is input into the time series prediction model to be trained for processing, and the time series prediction results are output. The numerical error loss is calculated based on the time series prediction results and the true values ​​of the sample time frame data. Based on the preset trend consistency constraint loss function, the trend consistency loss is determined according to the trend prediction results and time series prediction results. The total loss is determined based on the numerical error loss and the trend consistency loss, and the parameters of the time series prediction model are adjusted in reverse based on the total loss to achieve the training of the time series prediction model. Based on the trained time series prediction model, the data of the time frame to be predicted is processed, and the time series prediction results for the future time period are output.

[0006] According to another aspect of the present invention, a time series forecasting apparatus is provided, comprising: The trend prediction module is used to acquire sample time frame data, process the sample time frame data through a pre-trained trend prediction model, and output the trend prediction results of the sample time frame data. The training module is used to input sample time frame data into the time series prediction model to be trained, process it, output the time series prediction results, and calculate the numerical error loss based on the time series prediction results and the true values ​​of the sample time frame data. The first loss calculation module is used to determine the trend consistency loss based on the trend prediction results and time series prediction results, according to the preset trend consistency constraint loss function. The second loss calculation module is used to determine the total loss based on the numerical error loss and the trend consistency loss, and to adjust the parameters of the time series prediction model in reverse according to the total loss in order to train the time series prediction model. The time series prediction module is used to process the time frame data to be predicted based on the trained time series prediction model and output the time series prediction results for the future time period.

[0007] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory that is communicatively connected to at least one processor; wherein, The memory stores a computer program that can be executed by at least one processor, such that the at least one processor is able to perform the time series forecasting method of the present invention.

[0008] According to another aspect of the present invention, a computer-readable storage medium is provided, which stores computer instructions for causing a processor to execute and implement the time series prediction method of the embodiments of the present invention.

[0009] According to another aspect of the present invention, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the steps in the above-described method.

[0010] The technical solution of this invention addresses the lack of trend constraints through trend prior and the lack of model synergy through dual-loss fusion, overcoming the limitations of existing technologies and avoiding problems such as correct numerical values ​​but incorrect direction and long-term predictive performance degradation. Numerical error loss and trend consistency loss are fused through total loss, enabling the model to simultaneously improve both numerical accuracy and trend consistency, meeting the core needs of accurate and controllable predictions in energy prices, financial markets, and other sectors.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart illustrating the time series prediction method provided in an embodiment of the present invention; Figure 2 This is a flowchart illustrating another time series prediction method provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the time series prediction device provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of an electronic device that implements the time series prediction method of the present invention. Detailed Implementation

[0014] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0015] Example 1 Figure 1 This is a flowchart of a time series forecasting method provided in an embodiment of the present invention. This embodiment is applicable to time series forecasting scenarios, typically energy price forecasting, financial market analysis, power load forecasting, and meteorological change modeling. The method can be executed by a time series forecasting device, which can be implemented in hardware and / or software and can be configured in an electronic device.

[0016] like Figure 1 As shown, time series forecasting methods include: S101. Obtain sample time frame data, process the sample time frame data through a pre-trained trend prediction model, and output the trend prediction results of the sample time frame data.

[0017] The sample time frame data refers to the target time series segments and related feature data recorded continuously at fixed time intervals for training the time series prediction model, which must satisfy the requirements of temporal continuity and data integrity. The pre-trained trend prediction model refers to a model that has been trained using historical data and possesses the ability to judge trends, outputting the trend category (rising / falling / stable) and confidence level for each future segment of the time series. The trend prediction result refers to the trend labels (e.g., {+1,-1,0}) and corresponding trend accuracy output by the pre-trained trend prediction model after processing the sample time frame data, serving as the trend constraint basis for subsequent time series prediction models.

[0018] In some embodiments, this step mainly involves acquiring sample time frame data that meets the time series requirements through data acquisition tools, preprocessing it, and then inputting it into a pre-trained trend prediction model. The model outputs standardized trend results based on the mapping relationship between historical features and trends, providing clear prior trend information for the training of the time series prediction model. It is understood that the preprocessed sample data eliminates anomalies and missing data interference, ensuring the quality of model input and avoiding trend misjudgments caused by poor-quality data; the pre-trained trend prediction model outputs clear trend standards in advance, solving the problem of traditional time series models lacking trend guidance and being prone to directional errors, providing a reliable basis for subsequent trend constraints.

[0019] In some embodiments, the training process of the trend prediction model of the present invention includes step AC: Step A: Standardize and preprocess the acquired historical time series data, and divide the samples with a fixed window length to obtain several sample input sequences and their corresponding target ground truth sequences.

[0020] Historical time series data refers to target indicator data (such as daily coal price data for the past 5 years) and related feature data recorded continuously at fixed time intervals over a period of time. It is the basic data source for model training. Standardization preprocessing refers to converting raw data of different magnitudes and units into a uniform scale processing method (such as Z-score standardization and Min-Max standardization) to eliminate the interference of data dimensionality differences on model training.

[0021] A fixed window length is a uniform time span (e.g., 30 days, 60 days) set when dividing the samples, ensuring that the input sequence of each sample contains historical data of the same length, guaranteeing consistency in the model's input dimensions. The sample input sequence is a segment of historical data (e.g., coal prices over a 30-day period) extracted according to the fixed window, serving as the input features for model training. The target ground truth sequence is the real data for the corresponding future time period (e.g., if the sample input sequence is data from March 1st to 30th, the target ground truth sequence is real prices from April 1st to 15th), used as the basis for subsequent trend label construction.

[0022] In practice, historical time series data (such as the coal price index) and related feature data are collected to ensure that the data is continuous in time and covers a sufficient historical period to avoid underfitting of the model due to insufficient data. Historical time series data are standardized using Z-score. A window length (such as 30 days) is set, and samples are generated using a sliding window method: the first sample input sequence is the data from day 1 to 30, and the target true value sequence is the data from day 31 to 60; the second sample input sequence is the data from day 2 to 31, and the target true value sequence is the data from day 32 to 61, and so on, until all historical data are traversed to ensure that the input of each sample is continuous in time with the target sequence.

[0023] Understandably, standardization eliminates the magnitude differences between different features, preventing the model from biasing towards features with large magnitudes and improving training stability. Fixed window partitioning ensures that the input dimension of all samples is uniform, enabling the model to learn a consistent mapping relationship between historical data and future trends. At the same time, the sliding window method makes full use of historical data, improving sample utilization and reducing data waste. The preprocessed sample input sequences are sequentially continuous and formatted correctly, providing high-quality input for subsequent trend label construction and model training, reducing the interference of outlier data on training results.

[0024] Step B: Divide the prediction time interval corresponding to the target true value sequence into multiple consecutive time periods, calculate the mean difference between adjacent time periods, and generate trend labels for the sample input sequence based on the mean difference between adjacent time periods.

[0025] The prediction time interval refers to the future time period corresponding to the sample input sequence (i.e., the time range covered by the target ground truth sequence, such as April 1-30), and is the object of trend labeling. A continuous time period (block) refers to dividing the prediction time interval into several equal sub-intervals of the same length (e.g., a 30-day prediction interval divided into three 10-day blocks), used to capture macro-scale trend changes. The mean difference is the difference between the means of two adjacent consecutive time intervals, a core indicator for quantifying the direction and magnitude of trend changes (positive difference represents an increase, negative difference represents a decrease, and near 0 represents stagnation). Trend labels are standardized identifiers generated based on the mean difference, representing the trend direction of each segment within the prediction time interval (e.g., {+1, 0, -1} correspond to increase, stagnation, and decrease respectively), and are the target output of model training.

[0026] In practical implementation, based on the length of the prediction time interval and the trend characterization requirements, it is divided into k consecutive time periods (blocks) of equal length. Each block must contain a sufficient number of time points (e.g., at least 10 time points per block for daily data) to avoid distortion in mean calculation; for example, a 30-day prediction time interval is divided into three 10-day blocks, k=3. The arithmetic mean of the target true value sequence within each block is calculated; then the mean difference between adjacent blocks is calculated, such as block1 having a mean of 850 yuan / ton and block2 having a mean of 860 yuan / ton, the mean difference is +10 yuan / ton. A trend judgment threshold θ is set. If the mean difference is greater than the threshold θ, the trend label is +1 (rising); if the mean difference is less than the negative value of the threshold, the label is -1 (falling); if -θ≤mean difference≤θ, the label is 0 (flat); finally, a trend label sequence corresponding to the number of blocks is generated (e.g., when k=3, the label sequence is {+1,0,-1}).

[0027] This step, which divides continuous time intervals into blocks, transforms the continuous prediction range into quantifiable trend units, avoiding the interference of short-term fluctuations on the overall trend judgment and enabling more accurate capture of macro-trend changes. The mean difference calculation uses the interval mean rather than single-point data to characterize the trend, reducing the impact of single-point outliers and making trend judgments more robust. The generated standardized trend labels clearly define the model's training objectives, allowing the XGBoost classifier to directly learn the mapping relationship between historical features and trend direction, providing clear supervision signals for subsequent model training.

[0028] Step C: Use the XGBoost classifier to build the trend prediction model to be trained, and use the sample input sequence and its corresponding trend label to train the trend prediction model.

[0029] Among them, the XGBoost classifier is a strong classification model based on the gradient boosting tree algorithm. It excels at handling high-dimensional features and capturing nonlinear relationships, has a fast training speed and strong generalization ability, and is suitable for classification and prediction tasks in the direction of trends. The trend prediction model to be trained refers to the initial model built on the XGBoost classifier without parameter optimization, which needs to be iteratively trained with sample data to acquire trend prediction capabilities.

[0030] Model training: The process of inputting sample input sequences (features) and trend labels (targets) into the model to be trained, and adjusting the model parameters by optimizing the objective function, so that the model learns the mapping relationship between historical features and future trends.

[0031] In practice, the input sample sequence is organized into a two-dimensional feature matrix (shape: [number of samples, feature dimension], e.g., 1000 samples, 15 features), and the trend label sequence is organized into a two-dimensional target matrix (shape: [number of samples, k-1], where k is the number of blocks, e.g., 1000 samples, 2 labels). The training set and validation set are then divided chronologically in a 7:3 or 8:2 ratio (to avoid random shuffling that could disrupt the temporal sequence). The feature matrix and target matrix of the training set are input into the model to be trained, and iterative training is initiated. Every 10 epochs, the trend accuracy (ACC) of the model is evaluated using the validation set. If the ACC is below a threshold (e.g., 70%), the parameters are adjusted and retraining is performed. When the preset termination condition is met, the model training ends, and the completed trend prediction model is saved.

[0032] Having introduced the training of the trend prediction model, the implementation process of step S101 will be explained exemplarily through a specific application scenario: Example 1: The sample time frame data consists of daily historical coal price data and related feature data. The trend prediction process includes: First, determining the prediction interval and block division rules, for example, predicting the next 3 months, dividing it into 3 time period blocks (each block is 30 days). Second, sample data preprocessing, mainly performing Z-score standardization on the daily historical coal price data and related feature data to eliminate magnitude differences; inputting it into a pre-trained XGBoost model; the model input is the standardized 90-day sample data (feature dimension = 4: price + output + transportation volume + crude oil price), calling the learned historical feature and trend mapping relationship, and outputting the trend prediction results. The trend prediction results are the coal price trend and confidence level for the next 3 time period blocks, for example, block 1 (April) rises (+1, confidence level 0.86), block 2 (May) remains flat (0, confidence level 0.83), and block 3 (June) falls (-1, confidence level 0.81).

[0033] Example 2: The sample time frame data is hourly regional power load data for a certain area over a period of time. The trend prediction process includes: First, determining the prediction interval and block division rules, such as predicting the next 7 days (168 hours), dividing it into 4 blocks (each block is 42 hours, approximately 1.75 days). Sample data preprocessing mainly involves standardizing the regional power load data, while keeping the date type encoding unchanged. Inputting the data into a pre-trained XGBoost model. The model outputs the trend prediction results of the regional power load for the future time period. For example, the trend labels and confidence levels for the four time blocks in the future: Block 1 (hours 1-42) increases (+1, confidence level 0.88), Block 2 (hours 43-84) remains unchanged (0, confidence level 0.85), Block 3 (hours 85-126) increases (+1, confidence level 0.84), and Block 4 (hours 127-168) decreases (-1, confidence level 0.82).

[0034] S102. Input the sample time frame data into the time series prediction model to be trained for processing, output the time series prediction results, and calculate the numerical error loss based on the time series prediction results and the true values ​​of the sample time frame data.

[0035] The time-series prediction result refers to the specific numerical sequence of future time periods output by the time-series prediction model to be trained based on sample time frame data (such as the predicted value of coal prices for the next 90 days). The ground truth result is the actual value of the sample time frame data for the corresponding future time period (such as the actual coal price during that historical period), which serves as the benchmark for measuring the numerical prediction deviation. Numerical error loss: an indicator that quantifies the difference between the time-series prediction result and the ground truth result (mean squared error MSE in the document), reflecting the model's performance deficiencies in the numerical fitting dimension.

[0036] In some embodiments, the temporal prediction model is structured as a convolutional recurrent neural network; based on this, sample time frame data is input into the temporal prediction model to be trained for processing, and the temporal prediction result is output, including step AD: Step A: Input the sample time frame data into the convolutional recurrent neural network to be trained. The CNN layer in the convolutional recurrent neural network captures the local features of the input data, and the long short-term memory network layer captures the temporal dependencies to generate the temporal prediction results. Convolutional Recurrent Neural Network (CNN-LSTM) is a hybrid model that integrates Convolutional Neural Networks (CNN) and Long Short-Term Memory Networks (LSTM). It combines the advantages of CNN in capturing local features and LSTM in learning temporal dependencies, making it a core model for time-series numerical prediction. CNN Layer: The feature extraction layer in the CNN, capturing local fluctuations in data through sliding convolutional kernels. LSTM Layer: The temporal modeling layer in the CNN, learning long-term temporal dependencies through gating mechanisms (input gate, forget gate, output gate). Local Features: The feature patterns within short time windows in the sample time frame data, key to distinguishing local patterns in the data. Temporal Dependencies: The correlation patterns between different time points in the sample time frame data (e.g., the previous day's temperature affecting the next day's electricity load, the previous month's output affecting the next month's coal price), the core basis for time-series prediction. Time-Series Prediction Results: The specific numerical sequences of future time periods output by the model from the sample time frame data (e.g., the coal price for the next 90 days, the electricity load for the next 7 days), the direct result of the numerical prediction.

[0037] In practice, the sample time frame data is input into the built CNN-LSTM model, and then sequentially goes through the CNN layer convolution operation, pooling (optional, such as max pooling), LSTM layer gate calculation, and fully connected layer linear transformation, finally outputting the specific numerical sequence of each future time period (such as the average coal price of the next 3 blocks being 850 yuan / ton, 852 yuan / ton, and 840 yuan / ton, respectively), which is the time series prediction result.

[0038] Step B: Use the trend label corresponding to the sample time frame data as a priori basis to check whether the direction of the mean change of each time period in the time series prediction result is consistent with the trend label.

[0039] In practice, the trend label sequence corresponding to the current sample time frame data (e.g., the label sequence {+1,0,-1} for a 90-day prediction interval) is read from the preset label storage module, ensuring a one-to-one correspondence between the labels and the time periods of the prediction interval. The time series prediction results output from step A are then divided into a corresponding number of time period blocks according to the time period division rules of the trend labels (e.g., a 90-day prediction result is divided into three 30-day blocks), and the arithmetic mean of the predicted values ​​within each block is calculated. The mean difference between adjacent time period blocks is calculated to determine the direction of mean change. The direction of mean change is then compared one by one with the trend labels to generate a consistency verification result.

[0040] Step C: If the mean change direction of the time series forecast results is consistent with the trend label, then it is not necessary to calculate the trend consistency loss.

[0041] If the predicted direction of change in all time periods perfectly matches the trend label (e.g., label +1 corresponds to a predicted increase, label 0 corresponds to a predicted flatness, and label -1 corresponds to a predicted decrease), it is determined to be a consistent trend. The program branch logic is triggered, directly skipping the trend consistency loss calculation step, and only retaining the numerical error loss calculated in step S102 as the sole loss basis for subsequent model parameter adjustments.

[0042] Step D: If there is no consistency, execute the operation based on the preset trend consistency constraint loss function, and determine the trend consistency loss according to the trend prediction results and time series prediction results.

[0043] If there is a discrepancy, S103 needs to be executed to calculate the trend consistency loss.

[0044] Following the coal price scenario in S102, the preprocessed sample time frame data from January to March 2023 is input into the CNN-LSTM model to be trained, and the daily price prediction values ​​(time series prediction results) from April to June 2023 are output. These are compared with the actual prices from April to June 2023 (true values: average of RMB 848 / ton in April, RMB 855 / ton in May, and RMB 838 / ton in June). The numerical error loss is calculated according to the MSE formula to quantify the current numerical prediction deviation of the model.

[0045] In this embodiment of the invention, the hybrid structure of CNN-LSTM takes into account both local fluctuations and long-term dependencies, laying the foundation for subsequent numerical accuracy optimization and avoiding the problem of insufficient short-term feature capture by a single model (such as LSTM alone). The numerical error loss directly quantifies the numerical deviation of the model, clarifies the optimization direction that needs to reduce the difference between the predicted value and the true value, and prevents the model from only focusing on trends and ignoring the core numerical accuracy.

[0046] S103. Based on the preset trend consistency constraint loss function, determine the trend consistency loss according to the trend prediction results and time series prediction results.

[0047] This step mainly involves calling the preset trend consistency constraint loss function, inputting the trend prediction result of S101 and the time series prediction result of S102, and obtaining the trend consistency loss by calculating the inter-segment trend change, normalization processing, and penalty term determination, thus providing a basis for trend direction optimization for model parameter adjustment.

[0048] In practice, the process of determining the trend consistency loss includes the following steps: AC: Step A: Based on the prediction results output by the time series prediction model, calculate the inter-segment trend change between adjacent time periods in the prediction time interval, as well as the standard deviation of the predicted value within each time period.

[0049] Optionally, the inter-segment trend change between adjacent time periods can be calculated using the following formula. : ; in, Indicates the first b The sample at the th s The mean of the predicted values ​​over a given time period; Indicates the first b The mean of the predicted values ​​of each sample in the (s+1)th time period.

[0050] To reduce the impact of differences in numerical scale across different time periods on trend judgment, the standard deviation of the predicted values ​​within each time period is further calculated using the following formula: ; in, represents the standard deviation of the predicted value of the b-th sample in the s-th time period; L represents the number of time steps in each time period. This represents the predicted value of a certain b-th sample at the t-th time step in the s-th time period.

[0051] Step B: Normalize the inter-segment trend changes based on the standard deviation of the predicted values ​​within each time period.

[0052] The optional calculation method is as follows: ;in, To prevent the use of a pre-defined minimum positive number with a denominator of zero.

[0053] Step C: Based on the normalized inter-segment trend change and trend prediction results, calculate the trend consistency loss using the following formula: ; in, For trend consistency loss; B represents the number of samples in the batch; S represents the number of time periods; m is the preset minimum threshold for trend change; This indicates the trend prediction result; This represents the change in trend between segments after normalization.

[0054] The beneficial effect of this step is that the trend consistency loss directly quantifies the trend direction deviation, fills the gap in traditional models that only focus on numerical errors, ensures that the trend direction is optimized synchronously during model training, and avoids invalid predictions that are numerically correct but have the wrong direction.

[0055] S104. Determine the total loss based on the numerical error loss and the trend consistency loss, and adjust the parameters of the time series prediction model in reverse according to the total loss to achieve the training of the time series prediction model.

[0056] Optionally, the trend consistency loss and numerical error loss can be weighted and fused according to the following formula to obtain the total loss. : ; in, Indicates the final training loss; Indicates the loss due to numerical error; This is the weighting coefficient for numerical error loss; The trend consistency loss weight coefficient; This is due to the loss of trend consistency.

[0057] When adjusting the model parameters in reverse, the gradients of the CNN convolutional kernel weights and the LSTM input / forget gate weights are calculated based on the total loss. The parameters are then adjusted using the Adam optimizer: if the total loss is large due to numerical error, the update amplitude of the CNN layer parameters is increased to improve the local feature capture capability; if the trend loss is large, the LSTM hidden layer parameters are adjusted to correct the trend direction.

[0058] The total loss achieves a balanced optimization of numerical values ​​and trends, avoiding model bias towards a single dimension (such as pursuing numerical accuracy while the trend is wrong, or only maintaining the trend while the numerical deviation is large), thus solving the core defects of traditional models; backpropagation accurately locates parameter defects, and improves optimization efficiency through targeted adjustments, avoiding low training efficiency caused by blind parameter updates.

[0059] S105. Based on the trained time series prediction model, process the time frame data to be predicted and output the time series prediction results for the future time period.

[0060] In practice, time frame data prior to the time point to be predicted (such as coal prices from January to March 2024) is collected, and the data is preprocessed (outlier correction, missing value imputation, Z-score standardization) to ensure that the format is consistent with the training samples. The processed data is then input into the trained time series prediction model, which outputs specific numerical prediction results for multiple future time blocks (such as average of 860 yuan / ton in April, 862 yuan / ton in May, and 855 yuan / ton in June).

[0061] In the coal price forecasting scenario, the time frame data to be predicted is the price of thermal coal at a certain port from January to March 2024 (845-858 yuan / ton), the output (10-10.5 million tons / month), and the import volume (2-2.2 million tons / month) during the same period. After preprocessing, the data is input into a trained time series forecasting model and outputs the numerical forecast results for April to June 2024: average price of 860 yuan / ton in April, 862 yuan / ton in May, and 855 yuan / ton in June. A well-trained model balances numerical accuracy with trend consistency, providing a comprehensive basis for practical decision-making (such as coal procurement and energy dispatch) and avoiding the uncertainty of single numerical predictions.

[0062] In this embodiment of the invention, the limitations of existing technologies are completely overcome by using trend priors in S101 to address the lack of trend constraints, dual-loss fusion in S104 to address the lack of model synergy, and rolling updates in S105 to address poor dynamic adaptability. This avoids problems such as correct numerical values ​​but incorrect direction and long-term predictive performance degradation. The numerical error loss in S102 and the trend consistency loss in S103 are fused through the total loss in S104, enabling the model to simultaneously improve both numerical accuracy and trend consistency, meeting the core requirements of accurate and controllable predictions for energy prices, financial markets, and other data.

[0063] Example 2 Figure 2 A flowchart of a time series forecasting method is provided as an embodiment of the present invention. See also... Figure 2 The method includes the following steps: S201. Obtain sample time frame data, process the sample time frame data through a pre-trained trend prediction model, and output the trend prediction results of the sample time frame data.

[0064] S202. Input the sample time frame data into the time series prediction model to be trained for processing, output the time series prediction results, and calculate the numerical error loss based on the time series prediction results and the true values ​​of the sample time frame data.

[0065] S203. Based on the preset trend consistency constraint loss function, determine the trend consistency loss according to the trend prediction results and time series prediction results.

[0066] S204. Determine the total loss based on the numerical error loss and the trend consistency loss, and adjust the parameters of the time series prediction model in reverse according to the total loss to achieve the training of the time series prediction model.

[0067] In this embodiment of the invention, after training the time series prediction model using samples in the training set, the time data of the samples in the test set can be processed based on the trained time series prediction model. The trained time series prediction model is then evaluated using the normalized root mean square error, normalized mean absolute error, and trend accuracy between the predicted results and the true values. These metrics can be used to measure the quality of the trained time series prediction model. After evaluation, the time series prediction model can be deployed and used for prediction according to step S205.

[0068] S205. Based on the trained time series prediction model, process the time frame data to be predicted and output the time series prediction results for the future time period.

[0069] S206. Construct incremental training data based on the collected real data for the prediction time interval.

[0070] S207. Start the dual-model joint incremental training and use the newly added real data to optimize the parameters of the trend prediction model and the time series prediction model. After the optimization training is completed, save the updated model parameters for the next time frame sequence prediction.

[0071] Specifically, we collect target sequences and related feature real data that perfectly match the previously predicted intervals. We then use the preprocessing rules from the initial training phase, such as outlier correction, missing value imputation, and standardization, to divide the samples into fixed windows and simultaneously generate corresponding target ground truth sequences and trend labels. Finally, we construct a structured incremental training dataset with a unified format and continuous temporal sequence. First, we load the currently used XGBoost trend prediction model and CNN-LSTM temporal prediction model, using the original optimizer with a lower learning rate and a small number of iteration epochs. Then, using the incremental data constructed by S206, we simultaneously fine-tune the parameters of both models. The trend prediction model learns new features and trend mappings, while the temporal prediction model optimizes numerical predictions under the updated trend label constraints. After training, we verify the performance using a validation set. If it passes, we save the updated model parameters for subsequent predictions; otherwise, we roll back to the original model.

[0072] In this embodiment of the invention, by continuously optimizing the model with newly added real data, the dual models can accurately capture new trends brought about by policy, market, and other factors, solving the core pain point of performance degradation in traditional fixed-parameter models and maintaining the accuracy and trend consistency of long-term predictions. Simultaneous updates to the trend prediction and time-series prediction models ensure the accuracy of prior trend information and the trend constraint effect of time-series predictions, avoiding synergistic failures caused by updates to a single model, and guaranteeing the continuous effectiveness of dual optimization in numerical accuracy and trend direction. The newly added data includes new scenarios and features, allowing the model to learn more comprehensive mapping relationships, not only adapting to the current prediction task but also coping with similar unknown changes in the future, extending the model's lifecycle and enhancing its value for business decision-making.

[0073] Example 3 Figure 3 This is a schematic diagram of a time series forecasting device provided in an embodiment of the present invention. This device can execute any of the time series forecasting methods of the present invention. For example... Figure 3 As shown, the time series prediction device includes: The trend prediction module 301 is used to acquire sample time frame data, process the sample time frame data through a pre-trained trend prediction model, and output the trend prediction results of the sample time frame data. The training module 302 is used to input sample time frame data into the time series prediction model to be trained for processing, output time series prediction results, and calculate numerical error loss based on the time series prediction results and the true values ​​of the sample time frame data. The first loss calculation module 303 is used to determine the trend consistency loss based on the trend prediction results and time series prediction results, according to the preset trend consistency constraint loss function. The second loss calculation module 304 is used to determine the total loss based on the numerical error loss and the trend consistency loss, and to adjust the parameters of the time series prediction model in reverse according to the total loss in order to train the time series prediction model. The time series prediction module 305 is used to process the time frame data to be predicted based on the trained time series prediction model and output the time series prediction results for the future time period.

[0074] In some embodiments, the apparatus further includes a trend prediction model training module for: The acquired historical time series data is standardized and preprocessed, and the samples are divided with a fixed window length to obtain several sample input sequences and their corresponding target true value sequences. The prediction time interval corresponding to the target true value sequence is divided into multiple consecutive time periods. The mean difference between adjacent time periods is calculated, and the trend label of the sample input sequence is generated based on the mean difference between adjacent time periods. An XGBoost classifier is used to construct a trend prediction model to be trained, and the model is trained using sample input sequences and their corresponding trend labels.

[0075] In some embodiments, regarding the determination of trend consistency loss based on a preset trend consistency constraint loss function, according to trend prediction results and time series prediction results, the first loss calculation module 303 is specifically used for: Based on the prediction results output by the time series prediction model, the inter-segment trend change between adjacent time periods of the prediction time interval is calculated, as well as the standard deviation of the predicted value within each time period. Based on the standard deviation of the predicted values ​​within each time period, the inter-segment trend changes are normalized. Based on the normalized inter-segment trend changes and trend prediction results, the trend consistency loss is calculated using the following formula: ; in, For trend consistency loss; B represents the number of samples in the batch; S represents the number of time periods; m is the preset minimum threshold for trend change; This indicates the trend prediction result; This represents the change in trend between segments after normalization.

[0076] In some embodiments, the time-series prediction model is trained based on a convolutional recurrent neural network; In terms of inputting sample time frame data into the time series prediction model to be trained for processing and outputting time series prediction results, the training module 302 is specifically used for: The sample time frame data is input into the convolutional recurrent neural network to be trained. The CNN layer in the convolutional recurrent neural network captures the local features of the input data, and the long short-term memory network layer captures the temporal dependencies to generate temporal prediction results. The trend label corresponding to the sample time frame data is used as a priori basis to check whether the direction of the mean change of each time period in the time series prediction result is consistent with the trend label. If the mean change direction of the time series forecast results is consistent with the trend label, then it is not necessary to calculate the trend consistency loss. If there is a discrepancy, an operation based on a preset trend consistency constraint loss function is executed to determine the trend consistency loss according to the trend prediction results and time series prediction results.

[0077] In some embodiments, the second loss calculation module 304 is specifically used for determining the total loss based on numerical error loss and trend consistency loss: The trend consistency loss and numerical error loss are weighted and fused according to the following formula to obtain the total loss. : ; in, Indicates the final training loss; Indicates the loss due to numerical error; This is the weighting coefficient for numerical error loss; The trend consistency loss weight coefficient; This is due to the loss of trend consistency.

[0078] In some embodiments, before processing the time frame data to be predicted based on the trained time series prediction model, the apparatus further includes a model evaluation module, used for: The trained time series prediction model is used to process the sample time data in the test set, and the trained time series prediction model is evaluated by the normalized root mean square error, normalized mean absolute error and trend accuracy between the predicted results and the true values.

[0079] In some embodiments, the device further includes an incremental training module for: Incremental training data is constructed based on the collected real data for the predicted time intervals; Initiate joint incremental training of the two models, using newly added real data to optimize the parameters of the trend prediction model and the time series prediction model; after the optimization training is completed, save the updated model parameters for the next time frame prediction.

[0080] The time series forecasting apparatus provided in the embodiments of the present invention can execute the time series forecasting method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method execution.

[0081] According to embodiments of the present invention, the present invention also provides an electronic device, a readable storage medium, and a computer program product.

[0082] Example 4 Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the invention described and / or claimed herein.

[0083] like Figure 4 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory 12 or a random access memory 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the read-only memory 12 or loaded from storage unit 18 into the random access memory 13. The random access memory 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, read-only memory 12, and random access memory 13 are interconnected via a bus 14. An input / output interface 15 is also connected to the bus 14.

[0084] Multiple components in electronic device 10 are connected to input / output interface 15, including: input unit 16; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disks, optical disks, etc.; and communication unit 19, such as network interface cards, modems, wireless transceivers, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0085] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, central processing units, graphics processing units, various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, digital signal processors, and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as performing time series forecasting methods.

[0086] In some embodiments, the time series forecasting method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via read-only memory 12 and / or communication unit 19. When the computer program is loaded into random access memory 13 and executed by processor 11, one or more steps of the time series forecasting method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the time series forecasting method by any other suitable means (e.g., by means of firmware).

[0087] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays, application-specific integrated circuits (ASICs), application-specific standard products (ASICs), systems-on-a-chip (SoCs), complex programmable logic devices, computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0088] Computer programs used to implement the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to the processor of a general-purpose computer, a special-purpose computer, or other programmable time series forecasting device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs can be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0089] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory, optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0090] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device or liquid crystal display for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0091] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet. The computing system can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having client-server relationships with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, a host product within the cloud computing service system, addressing the shortcomings of traditional physical hosts and virtual private servers, such as high management difficulty and weak business scalability.

[0092] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0093] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A time series forecasting method, characterized in that, include: Acquire sample time frame data, process the sample time frame data using a pre-trained trend prediction model, and output the trend prediction result of the sample time frame data. The sample time frame data is input into the time series prediction model to be trained for processing, and the time series prediction result is output. The numerical error loss is calculated based on the time series prediction result and the true value result of the sample time frame data. Based on a preset trend consistency constraint loss function, the trend consistency loss is determined according to the trend prediction result and the time series prediction result. The total loss is determined based on the numerical error loss and the trend consistency loss, and the parameters of the time series prediction model are adjusted in reverse based on the total loss to train the time series prediction model. Based on the trained time series prediction model, the data of the time frame to be predicted is processed, and the time series prediction results for the future time period are output.

2. The method according to claim 1, characterized in that, The method further includes: The acquired historical time series data is standardized and preprocessed, and the samples are divided with a fixed window length to obtain several sample input sequences and their corresponding target true value sequences. The prediction time interval corresponding to the target true value sequence is divided into multiple consecutive time periods. The mean difference between adjacent time periods is calculated, and the trend label of the sample input sequence is generated based on the mean difference between adjacent time periods. An XGBoost classifier is used to construct a trend prediction model to be trained, and the trend prediction model is trained using the sample input sequence and its corresponding trend label.

3. The method according to claim 2, characterized in that, The trend consistency loss, determined based on the preset trend consistency constraint loss function and the trend prediction result and the time series prediction result, includes: Based on the prediction results output by the time series prediction model, the inter-segment trend change of adjacent time periods in the prediction time interval is calculated, as well as the standard deviation of the predicted value within each time period. The inter-segment trend change is normalized based on the standard deviation of the predicted values ​​within each time period. Based on the normalized inter-segment trend change and the trend prediction results, the trend consistency loss is calculated according to the following formula: ; in, For trend consistency loss; B represents the number of samples in the batch; S represents the number of time periods; m is the preset minimum threshold for trend change; This indicates the trend prediction result; This represents the change in trend between segments after normalization.

4. The method according to claim 3, characterized in that, The time-series prediction model is trained based on a convolutional recurrent neural network; The sample time frame data is input into the time series prediction model to be trained for processing, and the time series prediction results are output, including: The sample time frame data is input into the convolutional recurrent neural network to be trained. The CNN layer in the convolutional recurrent neural network captures the local features of the input data, and the long short-term memory network layer captures the temporal dependencies to generate temporal prediction results. The trend label corresponding to the sample time frame data is used as a priori basis to check whether the direction of the mean change of each time period in the time series prediction result is consistent with the trend label. If the mean change direction of the time series prediction results is consistent with the trend label, then it is not necessary to calculate the trend consistency loss. If there is a discrepancy, an operation based on a preset trend consistency constraint loss function is executed to determine the trend consistency loss according to the trend prediction result and the time series prediction result.

5. The method according to claim 3, characterized in that, The determination of the total loss based on the numerical error loss and the trend consistency loss includes: The trend consistency loss and the numerical error loss are weighted and fused according to the following formula to obtain the total loss. : ; in, Indicates the final training loss; Indicates the loss due to numerical error; This is the weighting coefficient for numerical error loss; The trend consistency loss weight coefficient; This is due to the loss of trend consistency.

6. The method according to claim 1, characterized in that, Before processing the time frame data to be predicted based on the trained time series prediction model, the method further includes: The trained time series prediction model is used to process the sample time data in the test set, and the trained time series prediction model is evaluated by the normalized root mean square error, normalized mean absolute error and trend accuracy between the predicted results and the true values.

7. The method according to claim 1, characterized in that, The method further includes: Incremental training data is constructed based on the collected real data for the predicted time intervals; Initiate joint incremental training of the two models, using newly added real data to optimize the parameters of the trend prediction model and the time series prediction model; after the optimization training is completed, save the updated model parameters for the next time frame prediction.

8. A time series forecasting device, characterized in that, include: The trend prediction module is used to acquire sample time frame data, process the sample time frame data through a pre-trained trend prediction model, and output the trend prediction result of the sample time frame data. The training module is used to input the sample time frame data into the time series prediction model to be trained for processing, output the time series prediction result, and calculate the numerical error loss based on the time series prediction result and the true value result of the sample time frame data. The first loss calculation module is used to determine the trend consistency loss based on the trend prediction result and the time series prediction result, according to the preset trend consistency constraint loss function. The second loss calculation module is used to determine the total loss based on the numerical error loss and the trend consistency loss, and to adjust the parameters of the time series prediction model in reverse based on the total loss, so as to train the time series prediction model. The time series prediction module is used to process the time frame data to be predicted based on the trained time series prediction model and output the time series prediction results for the future time period.

9. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the method of any one of claims 1-7.