Dynamic threshold design method and device, equipment, medium and program product
Through the multi-objective timing prediction model, predicting the future value of product equity data and dynamically adjusting the threshold, solving the problem of insufficient flexibility in the existing technology, and achieving higher flexibility and accuracy.
Patent Information
- Application Number
- CN202411402657.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-02-11
AI Technical Summary
In the prior art, the dynamic threshold design method is not flexible enough to effectively adapt to the dynamic changes of data, resulting in the inflexible threshold setting.
By obtaining time series of multiple product equity data, using a multi-objective timing prediction model for training, predicting data values in the future period, and dynamically adjusting the threshold based on the predicted value. The model is trained using a preset loss function and is adjusted according to the time granularity or province granularity of the target prediction task.
It improves the flexibility and accuracy of dynamic threshold design, can better adapt to data changes, reduce the false alarm rate, and improve system monitoring capabilities.
Smart Images

Figure CN119417254A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a dynamic threshold design method, device, equipment, medium and program product. Background Art
[0002] Dynamic thresholds are an integral part of monitoring and alarm systems. They are used to respond to changes in system indicators caused by business characteristics or objective factors. The main purpose is to dynamically adjust thresholds based on historical and real-time data to optimize the system's monitoring capabilities, prevent potential problems, and reduce the false alarm rate in normal scenarios. In many fields, such as network security, financial monitoring, and industrial process control, thresholds are used to trigger alarms or take actions. Dynamic thresholds can adapt to changes in data behavior to a certain extent, improving the flexibility and efficiency of the system.
[0003] The core of traditional threshold statistical methods is to identify outliers in data, that is, values that significantly deviate from the normal fluctuation range of the data. Dynamic thresholds are usually evaluated using moving average and moving standard deviation in conjunction with window sliding. When a new data point deviates from the moving average by more than a certain multiple of the standard deviation, the data point is marked as an anomaly.
[0004] However, the moving average and moving standard deviation in traditional threshold statistical methods are usually based on fixed windows, which are not suitable for dynamic changes in data, resulting in inflexible threshold setting. Summary of the invention
[0005] The present invention provides a dynamic threshold design method, device, equipment, medium and program product, which are used to solve the problem that the dynamic threshold design method in the prior art is not flexible enough.
[0006] In a first aspect, the present invention provides a dynamic threshold design method, comprising: Obtain the time series corresponding to the equity data of various products; Based on multiple time series, a multi-objective time series forecasting model is used for training to obtain the predicted value of each product equity data output by the multi-objective time series forecasting model in the future period; the multi-objective time series forecasting model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or provincial granularity of the target forecasting task; Based on the predicted value of each product equity data in a future period of time, a threshold value of each product equity data in the future period of time is determined.
[0007] In one embodiment, when the preset loss function is adjusted according to the time granularity of the target prediction task, it includes: If the training data of multiple models are hourly data, the preset loss function is not adjusted; If the multiple model training data are daily level data or monthly level data, the preset loss function is adjusted in hours.
[0008] In one embodiment, when the preset loss function is adjusted according to the province granularity of the target prediction task, it includes: Determine the provinces to which the training data of multiple models are respectively associated; Calculate the weight value of each province; Based on the weight value of the province associated with each model training data, the preset loss function is weighted adjusted.
[0009] In one embodiment, the multi-objective time series prediction model is trained in the following manner: Obtain historical time series of equity samples of multiple products; Divide the historical time series of each product equity sample into a first time series sample and a second time series sample according to a preset ratio; Perform feature engineering based on the first time series sample of each product equity sample to obtain a feature series sample of each product equity sample; Determine the characteristic sequence samples of each product equity sample as model training data, and determine the second time series samples of the product equity sample as label data corresponding to the model training data; Based on multiple model training data and label data corresponding to each model training data, the TSMixer model is trained to obtain the multi-objective time series prediction model.
[0010] In one embodiment, the training is performed based on multiple time series through a multi-objective time series prediction model to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in the future period, including: Perform data preprocessing based on multiple time series to obtain multiple time series after data preprocessing; Perform feature engineering on each time series to obtain multiple target feature sequences; The multiple target feature sequences are input into a multi-target time series forecasting model to obtain a forecast value of each product equity data output by the multi-target time series forecasting model in a future period of time.
[0011] In one embodiment, the threshold value includes a maximum threshold value and a minimum threshold value; when determining the threshold value of each product equity data in the future period based on the predicted value of each product equity data in the future period, the following steps are performed for each product equity data: Adding the predicted value of the product equity data in the future period to the preset floating value to obtain the highest threshold of the product equity data in the future period; The predicted value of the product equity data in a future period of time is subtracted from the preset floating value to obtain the minimum threshold value of the product equity data in the future period of time.
[0012] In one embodiment, after determining the lowest threshold of the product equity data in the future period of time, the method further includes: Divide the data into a normal range based on the highest threshold and the lowest threshold; Get the real value of the product equity data at the current moment; If the true value is within the normal range of the data, it is determined that the product equity data is normal at the current moment; If the true value does not fall within the normal range of the data, it is determined that the product equity data is abnormal at the current moment, and an alarm is issued based on the product equity data.
[0013] In a second aspect, the present invention further provides a dynamic threshold design device, comprising: The acquisition module is used to obtain the time series corresponding to the equity data of various products; A model prediction module is used to train a multi-objective time series prediction model based on multiple time series to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in the future; the multi-objective time series prediction model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or provincial granularity of the target prediction task; The threshold design module is used to determine the threshold of each product equity data in the future period based on the predicted value of each product equity data in the future period.
[0014] In a third aspect, the present invention provides a device, comprising an electronic device, wherein the electronic device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the dynamic threshold design method as described in any one of the above are implemented.
[0015] In a fourth aspect, the present invention further provides a medium, comprising a non-transitory computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the dynamic threshold design methods described above are implemented.
[0016] In a fifth aspect, the present invention also provides a product, comprising a computer program product, wherein the computer program product comprises a computer program, wherein the computer program can be stored on a non-transitory computer-readable storage medium, and wherein when the computer program is executed by the processor, the steps of the dynamic threshold design method as described above are implemented.
[0017] The dynamic threshold design method, device, equipment, medium and program product provided by the present invention take into account the problem of unbalanced gradient descent trend during simultaneous training of large-granularity targets and small-granularity targets under the target prediction task of the multi-target time series prediction model, and coordinately adjust the loss of the multi-target output value, which can improve the consistency of the prediction values of targets of different granularity and improve the prediction accuracy of the model. After obtaining a multi-target time series prediction model with high generalization ability, based on the time series corresponding to multiple product equity data, prediction is performed through the multi-target time series prediction model, and multiple accurate future prediction values are output at one time. The threshold within this future time period is further determined on each accurate future prediction value, and the threshold can be flexibly adapted to the change of data to realize dynamic adjustment of the threshold, thereby ensuring the accuracy of the dynamic threshold design and improving the flexibility of the dynamic threshold design. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 It is a flow chart of the dynamic threshold design method provided by the present invention.
[0020] Figure 2 It is a schematic diagram of various data collection approaches provided by the present invention.
[0021] Figure 3 It is a schematic diagram of the model architecture of the TSMixer model provided by the present invention.
[0022] Figure 4 It is a structural schematic diagram of the dynamic threshold design device provided by the present invention.
[0023] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] The terms "first", "second", etc. in the present invention are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described herein.
[0026] Combine the following Figure 1-Figure 5 The present invention describes the dynamic threshold design method, device, equipment, medium and program product provided by the present invention.
[0027] It should be noted that the dynamic threshold design method provided by the embodiment of the present invention is implemented based on the dynamic threshold design device. Under the premise of getting rid of the limitations of linear relationships, the dynamic threshold design method inputs different sequences of multiple product equity data with multi-dimensional business information into the neural network model of the same TSMixer architecture, learns the intersection and interactivity of multiple features and outputs multiple prediction values at one time (for example, product order volume prediction values in different regions, different time granularities, and different activities), thereby getting rid of the limitations of traditional models, improving the intersection of features, and ensuring the accuracy of system monitoring indicators, so as to make accurate predictions of various indicators of the monitoring system, further calculate dynamic thresholds and conduct full-link monitoring.
[0028] The embodiment of the present invention describes the dynamic threshold design method by taking a dynamic threshold design device as an execution subject as an example.
[0029] Figure 1 It is a flow chart of the dynamic threshold design method provided by the present invention.
[0030] like Figure 1 As shown, the method includes the following: Step 101, obtaining time series corresponding to the equity data of multiple products; Step 102: Based on multiple time series, a multi-objective time series prediction model is trained to obtain a predicted value of each product equity data output by the multi-objective time series prediction model in a future period of time; Step 103: Based on the predicted value of each product equity data in the future period, determine the threshold value of each product equity data in the future period.
[0031] Specifically, the dynamic threshold design device acquires a variety of product equity data from a variety of path collection paths, and constructs a time series corresponding to each product equity data in chronological order.
[0032] It should be noted that data collection is collected from various channels and aggregated into a unified message queue. Figure 2 , Figure 2 Schematic diagram of various data collection methods provided by the present invention. Figure 2 As shown in the figure, the business system interface log selects the data forwarding software development kit SDK (Software Development Kit) or pushes it directly to the message queue according to its own network environment; the front-end embedded data is synchronized to the message queue by the front-end page request data forwarding service; the business database data is collected by Flink using the Change Data Capture (CDC) tool to monitor the database binlog and is collected in real time to the message queue.
[0033] Business interface data generally obtains request status and time consumption during the business process, and is used to obtain indicator data such as interface success rate, business success rate, and average time consumption. Front-end embedded data is the user's behavior data on the front-end, and is used for indicator data such as page views (PV), unique visitor visits (UV), and access time consumption of the front-end pages. Business databases generally obtain product order volume, order success rate, etc., as well as dimensional data, including provinces, professional company information, event information, product information, commodity information, etc.
[0034] Therefore, multiple product equity data can be considered as different target variables input into the model time series forecast, such as product order volume, time consumption, success rate, failure rate, etc., and each product equity data is also associated with multi-dimensional business data, such as province, professional company information, activity information, product information, commodity information, etc. Therefore, different time series composed of multi-dimensional business information and multiple target variables can be input into the model, and the model learns the feature intersection and interactivity between different time series, and finally outputs multiple prediction values at one time.
[0035] Furthermore, the dynamic threshold design device is based on multiple time series and is trained together through a multi-objective time series prediction model to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in the future.
[0036] It should be noted that traditional forecasting models, such as the autoregressive moving average model ARIMA and the triple exponential smoothing model Holt-Winters, are usually built based on linear relationships, so they perform poorly when processing time series data that exhibit nonlinear dynamics, and it is difficult to accurately capture complex or fluctuating data patterns. Therefore, the multi-objective time series forecasting model uses the TSMixer architecture, which can adapt to the equity business changes of linear and nonlinear characteristics, combine time series and multiple feature dependencies, get rid of the limitations of single variable sequence forecasting, learn the intersection and interactivity of multiple features, and output multiple forecast values at a time.
[0037] In addition, in the training of multi-objective time series forecasting models, product equity data involves the prediction of the same indicators at different time granularities and different feature dimensions. In order to avoid the data of a certain time granularity or a large province dominating the training process, the preset loss function used in the training process of the multi-objective time series forecasting model needs to be adjusted according to the time granularity or provincial granularity of the target prediction task to balance the impact of loss contributions under different conditions on model training.
[0038] Furthermore, the dynamic threshold design device adds a corresponding preset floating range to the predicted value of each product equity data in the future period according to the preset acceptable floating range under each product equity data, so as to determine the threshold of each product equity data in the future period.
[0039] The dynamic threshold design method provided by the present invention takes into account the problem of unbalanced gradient descent trends during simultaneous training of large-granularity targets and small-granularity targets under the target prediction task of the multi-target time series prediction model, and coordinates the loss of the multi-target output value to improve the consistency of the prediction values of targets of different granularities and improve the prediction accuracy of the model. After obtaining a multi-target time series prediction model with high generalization ability, prediction is performed through the multi-target time series prediction model based on the time series corresponding to multiple product equity data, and multiple accurate future prediction values are output at one time. The threshold within this future time period is further determined on each accurate future prediction value, and the threshold can be flexibly adapted to changes in data to achieve dynamic adjustment of the threshold, thereby ensuring the accuracy of the dynamic threshold design and improving the flexibility of the dynamic threshold design.
[0040] In some embodiments, based on step 102, based on multiple time series, a multi-objective time series forecasting model is trained to obtain a forecast value of each product equity data output by the multi-objective time series forecasting model in a future period of time, including: Perform data preprocessing based on multiple time series to obtain multiple time series after data preprocessing; Perform feature engineering on each time series to obtain multiple target feature sequences; The multiple target feature sequences are input into a multi-target time series forecasting model to obtain a forecast value of each product equity data output by the multi-target time series forecasting model in a future period of time.
[0041] Specifically, the dynamic threshold design model performs data preprocessing based on multiple time series to obtain multiple time series after data preprocessing, wherein the data preprocessing mainly includes missing value processing and outlier processing.
[0042] In one embodiment, missing values may be processed in the following manner: when there are not many missing values, consider directly deleting records with missing values; when there are many missing values, use the mean or median to fill in the missing values, and use the mode to fill in the missing variables.
[0043]
[0044] This formula means that if a certain data is not missing, then continue to use the data; if a certain data is missing, then use the mean to fill in the data.
[0045] In another embodiment, outlier processing may be performed in the following manner: outliers caused by erroneous data, equipment failures, or atypical conditions are processed, and outliers are identified by using the interquartile range (IQR), and the third quartile is subtracted from the first quartile to obtain the IQR, which is expressed as follows: , the range of abnormal values is .
[0046] Furthermore, the dynamic threshold design device performs feature engineering on each time series to obtain multiple target feature sequences to improve the model prediction ability, wherein the feature engineering mainly focuses on four aspects, including time feature extraction, lag feature extraction, rolling window design and periodic feature extraction.
[0047] It can be understood that the dynamic threshold design device performs time feature extraction, lag feature extraction, rolling window design and periodic feature extraction on each time series respectively, and obtains the time feature, lag feature, rolling window and periodic feature corresponding to each time series. Further, the time feature, lag feature, rolling window and periodic feature corresponding to each time series are integrated to obtain the target feature sequence of each time series.
[0048] It should be noted that a simple time series cannot allow the model to deeply learn the characteristics of time, so it is necessary to extract effective features to enhance the performance of the model, improve data utilization, and accelerate the model training process.
[0049] The following describes time feature extraction, lag feature extraction, rolling window design, and periodic feature extraction respectively.
[0050] 1. Time feature extraction: (1) Year, month, day, hour: Features capture seasonality and cyclicity, such as changes in order volume over time; (2) Weekday: Extract the impact of whether the data point is a weekend or a weekday on the number of active orders; (3) Is it a holiday? Holidays have a certain impact on monitoring indicators.
[0051] 2. Hysteresis feature extraction: The lag value means that the data from the previous hour or 24 hours before the data point can be used as the input feature of the current data point.
[0052] 3. Rolling window design: Provide trend and volatility information of time series through statistical data of a certain period of time; (1) Average value: the average value within the window period, which can reflect the trend; (2) Standard deviation: the standard deviation within the window period, used to quantify volatility; (3) Maximum / minimum value: extreme value within the window period, capturing extreme changes.
[0053] 4. Periodic feature extraction: Due to the business characteristics, daily / monthly / weekly activities and the beginning / end of the month data have strong periodicity. The periodic component of Fourier transform is used to help the model understand the underlying periodicity. The Fourier transform converts time series data into a combination of a series of frequencies, each with a corresponding amplitude and phase. The Fourier transform formula is as follows: ; in, is a time domain signal, is a frequency domain signal, f is frequency, t is time, and j is an imaginary unit.
[0054] Furthermore, the dynamic threshold design device inputs multiple target feature sequences into the target time series prediction model to obtain the predicted value of each product equity data output by the multi-target time series prediction model in the future period of time.
[0055] The embodiment of the present invention can improve data quality and thus data accuracy by performing data preprocessing on the model input data, and further perform feature engineering on the model input data after data preprocessing to help the model better capture patterns in the data and improve prediction capabilities. Therefore, by inputting the target feature sequence into the multi-target time series prediction model, accurate future prediction values can be obtained.
[0056] In some embodiments, based on step 103, when determining the threshold of each product equity data in the future period based on the predicted value of each product equity data in the future period, the following steps are performed for each product equity data: Adding the predicted value of the product equity data in the future period to the preset floating value to obtain the highest threshold of the product equity data in the future period; The predicted value of the product equity data in a future period of time is subtracted from the preset floating value to obtain the minimum threshold value of the product equity data in the future period of time.
[0057] Specifically, the dynamic threshold design device adds the predicted value of the product equity data in the future period to the preset floating value to obtain the highest threshold of the product equity data in the future period, wherein the preset floating value is set according to actual conditions.
[0058] Furthermore, the dynamic threshold design device subtracts the predicted value of the product equity data in the future period from the preset floating value to obtain the minimum threshold of the product equity data in the future period.
[0059] It can be expressed by formula: threshold = predicted value ± preset floating value.
[0060] It should be noted that the present invention can adopt not only a preset floating value, but also a preset floating ratio. That is to say, the sum of the predicted value and the predicted value under the preset floating ratio is the highest threshold, and the subtraction of the predicted value and the predicted value under the preset floating ratio is the lowest threshold. It can be flexibly applied according to actual conditions.
[0061] The embodiment of the present invention obtains the maximum and minimum thresholds by adding and subtracting the predicted value of the product equity data from the preset floating value, which can provide clear boundaries for future equity fluctuations of the product and can flexibly adapt to changes in data to dynamically adjust the thresholds, thereby achieving more effective risk management and improving the scientificity and rationality of strategic decision-making.
[0062] In some embodiments, after determining the lowest threshold of the product equity data within the future period of time, the method further includes: Divide the data into a normal range based on the highest threshold and the lowest threshold; Get the real value of the product equity data at the current moment; If the true value is within the normal range of the data, it is determined that the product equity data is normal at the current moment; If the true value does not fall within the normal range of the data, it is determined that the product equity data is abnormal at the current moment, and an alarm is issued based on the product equity data.
[0063] Specifically, the dynamic threshold design device divides the data into a normal range based on the highest threshold and the lowest threshold. It can be understood that if the real data meets the normal range, it means that the monitored data is normal. If the real data does not meet the normal range, it means that the monitored data is abnormal.
[0064] Therefore, the dynamic threshold design device can obtain the real value of the product equity data at the current moment to monitor the product equity data.
[0065] In one case, if the true value is within the normal range of the data, the dynamic threshold design device determines that the product equity data is normal at the current moment.
[0066] In another case, if the true value does not fall within the normal range of the data, the dynamic threshold design device determines that the product equity data is abnormal at the current moment.
[0067] After determining that the product equity data is abnormal, an alarm level judgment is made on the abnormal situation of the product equity data, and different alarm modes are selected for alarm output according to different alarm levels.
[0068] In one embodiment, the alarm level can be divided into low-level alarm, medium-level alarm and emergency alarm. When the alarm level is a low-level alarm, it can be sent to relevant personnel via email to remind them to pay attention to data changes; when the alarm level is a medium-level alarm, the alarm can be issued by a robot to ensure that even if relevant personnel obtain the alarm information, they need to pay attention and evaluate the follow-up measures; when the alarm level is an emergency alarm, all relevant personnel can be notified through multiple channels at the same time, and an emergency meeting can be held for emergency discussion and decision-making.
[0069] The embodiment of the present invention divides the normal range of data based on the highest threshold and the lowest threshold, and can monitor the true value of product rights and interests data in real time to ensure that it is within a reasonable range. If the true value exceeds the normal range, the system will automatically identify the anomaly and trigger an alarm, thereby providing timely feedback on potential risks, effectively improving risk management capabilities, ensuring the security and stability of product rights and interests, and helping relevant personnel to quickly take countermeasures.
[0070] In some embodiments, the multi-objective time series prediction model is trained in the following manner: Obtain historical time series of equity samples of multiple products; Divide the historical time series of each product equity sample into a first time series sample and a second time series sample according to a preset ratio; Perform feature engineering based on the first time series sample of each product equity sample to obtain a feature series sample of each product equity sample; Determine the characteristic sequence samples of each product equity sample as model training data, and determine the second time series samples of the product equity sample as label data corresponding to the model training data; Based on multiple model training data and label data corresponding to each model training data, the TSMixer model is trained to obtain the multi-objective time series prediction model.
[0071] Specifically, the dynamic threshold design model obtains the historical time series of equity samples of various products.
[0072] Furthermore, the dynamic threshold design model divides the historical time series of each product equity sample into a first time series sample and a second time series sample according to a preset ratio, wherein the preset ratio is set according to actual conditions, and usually the proportion of the first time series sample is larger than that of the second time series sample.
[0073] Furthermore, the dynamic threshold design model performs data preprocessing on the plurality of first time series samples to obtain the plurality of first time series samples after data preprocessing.
[0074] Furthermore, the dynamic threshold design model performs feature engineering on the multiple first time series samples after data preprocessing to obtain feature sequence samples of each product equity sample.
[0075] Furthermore, the dynamic threshold design model determines the characteristic sequence samples of each product equity sample as model training data, and determines the second time series samples of the product equity sample as label data corresponding to the model training data.
[0076] Furthermore, the dynamic threshold design model trains the TSMixer model based on multiple model training data and label data corresponding to each model training data to obtain a multi-objective time series prediction model.
[0077] It should be noted that the TSMixer model combines the ideas of Transformer and MLP Mixer to cope with the modeling and prediction tasks of time series data. Figure 3 , Figure 3 Schematic diagram of the model architecture of the TSMixer model provided by the present invention. Specifically, its basic idea can be refined into the following key points.
[0078] 1. Self-attention mechanism: TSMixer borrows the self-attention mechanism from the Transformer model. This mechanism allows the model to model the dependencies between different time steps when processing time series data. Through the self-attention mechanism, the model can dynamically adjust the degree of attention to different time steps, thereby better capturing the long-term and short-term dependencies in the time series data. The self-attention mechanism allows the model to calculate the representation of each position based on the contextual information of each position in the sequence. In TSMixer, the self-attention mechanism can be expressed as:
[0079] Among them, Q, K, and V represent query vector, key vector, and value vector respectively; represents the dimension of the key vector; the softmax function is used to calculate the attention weights and normalize them into a probability distribution.
[0080] 2. Fully connected layer structure: Based on the idea of MLP Mixer, a fully connected layer structure is used to deeply transform and abstract time series features. The MLP Mixer model performs nonlinear transformation on input features through multiple fully connected layers to obtain richer and more complex feature representations.
[0081] 3. Time series splitting: The time series data is divided into two parts, the past and the future, and processed separately. By modeling the past data and predicting the future data, the model can fully understand and analyze the characteristics and laws of the time series data. Time series splitting divides the sequence into two parts, the past and the future, and processes them separately, which can be expressed as:
[0082] Where X represents the original time series data, Represents the past and future parts of the data respectively.
[0083] 4. Feature mixing and interaction: Use the time mixing block and feature mixing block to mix and interact time series features. The time mixing block is used to interact and adjust features in the time dimension to capture the temporal dependencies in time series data; the feature mixing block is used to mix and interact features in the feature dimension to capture the complex relationships between features in time series data.
[0084] 5. Initialization parameters: Extract various parameters required for model construction from the function parameters, such as input specification (input_spec), LSTM (Long Short-Term Memory) layer size (lstm_layer_sizes), model name (name), random seed (seed), number of embedding layer units (emb_dense_unit, emb_sparse_unit), past length (past_length), future length (future_length), etc.
[0085] 6. Construct the input layer: Creates the input layers of the model according to the input specification (input_spec). Each input feature is named and a corresponding input layer is created in the order in which it appears in the specification. These input layers are stored in the input_layer dictionary for later use.
[0086] 7. Build the embedding layer: Creates an embedding layer for a given embedding group (emb_group). Depending on the type of each subgroup in the embedding group (dense or sparse), the corresponding layer type is created. The created embedding layer is stored in the emb_group_layer dictionary.
[0087] 8. Determine time series and static characteristics: According to the naming rules of input features, the input features are divided into time series (past and future) and static features. Usually, the names of time series features contain "past_sequence" or "future_sequence", and static features are usually related to the features in the embedding group.
[0088] 9. Construct LSTM layer: The model parameters specify that it contains LSTM layers (via the models parameter), create the corresponding number of LSTM layers based on the lstm_layer_sizes parameter, and store them in the _past_lstms, _future_lstms, and _backward_lstms lists.
[0089] 10. Build TSMixer architecture: If the model parameter specifies that a TSMixer module is to be included (via the models parameter), the layers required for that module are constructed. This includes creating the PastToFutureMap, FeatureToHiddenMap, and MlpMixerBlock layers.
[0090] 11. Construct the output layer: According to the prediction type (predict_type) in the model parameters, the appropriate output layer type is selected for construction. The output layer is responsible for converting the final output of the model into the desired prediction result.
[0091] 12. Return model: Return the constructed model and its related configuration information for further training, adjustment, or use of the model for prediction.
[0092] The embodiment of the present invention adopts the Tsmixer architecture for model training. The model under this architecture can adapt to the equity business changes of linear and nonlinear features, improve the intersection of feature extraction, integrate the dependency between multiple features into the time series, and get rid of the limitations of single variable single sequence prediction. At the same time, the model under this architecture can learn the intersection and interactivity of multiple features, and output multiple prediction values at one time, so as to accurately predict the results of different dimensions and different granularities.
[0093] In some embodiments, when the preset loss function is adjusted according to the time granularity of the target prediction task, it includes: If the training data of multiple models are hourly data, the preset loss function is not adjusted; If the multiple model training data are daily level data or monthly level data, the preset loss function is adjusted in hours.
[0094] Considering that the training of multi-objective time series prediction models may involve target prediction tasks of different time granularities, such as predicting the product order volume in the next 6 days and predicting the product order volume in the next 6 hours, there is an unbalanced gradient descent trend problem between large-granularity targets and small-granularity targets during simultaneous training actions. Therefore, in order to balance the impact of different time granularities, the following time granularity loss function adjustment strategy is defined.
[0095] Specifically, if the training data of multiple models are hourly data, the dynamic threshold design device does not adjust the preset loss function.
[0096] If the training data of multiple models are daily or monthly data, the dynamic threshold design device will adjust the preset loss function in hours.
[0097] The specific adjustment strategies are described using hourly data, daily data, and monthly data respectively.
[0098] Hourly data: directly calculate the loss without making any adjustments; Daily data: loss divided by 24 (number of hours in a day); Monthly data: loss divided by the total number of hours in the month. This value varies from month to month, for example, January is 744 hours (31 days), February is usually 672 hours (28 days) or 696 hours (29 days), etc.
[0099] The embodiment of the present invention dynamically adjusts the preset loss function according to the time granularity of the target prediction task. This flexible adjustment mechanism can improve the consistency of target prediction values of different granularities, improve prediction accuracy and interpretability, and ensure the reliability and practicality of the output results.
[0100] In some embodiments, when the preset loss function is adjusted according to the province granularity of the target prediction task, it includes: Determine the provinces to which the training data of multiple models are respectively associated; Calculate the weight value of each province; Based on the weight value of the province associated with each model training data, the preset loss function is weighted adjusted.
[0101] Considering that the training of multi-objective time series prediction models may involve target prediction tasks of different provincial granularities, such as predicting the future order success rate of Province A and predicting the future order success rate of Province B, there is an unbalanced gradient descent trend problem between large-grained targets and small-grained targets during simultaneous training actions. Therefore, in order to ensure that the model can learn evenly on all provinces and prevent overfitting of large-volume provinces during training, the following loss function strategy for dynamic weight adjustment between provinces is defined.
[0102] Specifically, first, the dynamic threshold design device needs to determine the provinces to which multiple model training data are respectively associated.
[0103] Given a province p, the total order volume is , maximum order quantity : ; Normalized weight for each province The calculation is as follows: .
[0104] Bigger means province p ’s order volume is relatively small and needs to be given a larger weight in the loss calculation to balance the model’s learning for all provinces.
[0105] Furthermore, the dynamic threshold design device performs weighted adjustment on the preset loss function based on the weight value of the province associated with each model training data.
[0106] In one embodiment, let L be the mean square error loss of the model for a batch of data, where each model training data i Belongs to a province :
[0107] in, L represents the mean square error loss; represents the simulated predicted value; Represents the true value, and its corresponding province is consistent with the model training data, so the corresponding province weight is also consistent; N is the number of samples in the batch.
[0108] The loss adjusted according to the province weights is:
[0109] in, represents the adjusted mean square error loss; yes The corresponding province weight.
[0110] In another embodiment, let L be the mean absolute error loss of the model for a batch of data, where each model training data i Belongs to a province :
[0111] in, L represents the mean absolute error loss; represents the simulated predicted value; Represents the true value, and its corresponding province is consistent with the model training data, so the corresponding province weight is also consistent; N is the number of samples in the batch.
[0112] The loss adjusted according to the province weights is:
[0113] in, represents the adjusted mean absolute error loss; yes The corresponding province weight.
[0114] The embodiment of the present invention dynamically adjusts the preset loss function according to the province granularity of the target prediction task. This flexible adjustment mechanism can improve the consistency of target prediction values of different granularities, improve prediction accuracy and interpretability, and ensure the reliability and practicality of the output results.
[0115] The dynamic threshold design device provided by the present invention is described below. The dynamic threshold design device described below and the dynamic threshold design method described above can be referenced to each other.
[0116] Reference Figure 4 , Figure 4 It is a structural schematic diagram of the dynamic threshold design device provided by the present invention.
[0117] The dynamic threshold design device comprises: The acquisition module 410 is used to acquire time series corresponding to the equity data of various products.
[0118] The model prediction module 420 is used to train a multi-objective time series prediction model based on multiple time series to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in the future period; the multi-objective time series prediction model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or province granularity of the target prediction task.
[0119] The threshold design module 430 is used to determine the threshold of each product equity data in the future period of time based on the predicted value of each product equity data in the future period of time.
[0120] The dynamic threshold design device provided by the present invention takes into account the problem of unbalanced gradient descent trends during simultaneous training of large-granularity targets and small-granularity targets under the target prediction task of the multi-target time series prediction model, and coordinates the loss of the multi-target output value to improve the consistency of the prediction values of targets of different granularities and improve the prediction accuracy of the model. After obtaining a multi-target time series prediction model with high generalization ability, based on the time series corresponding to multiple product equity data, predictions are made through the multi-target time series prediction model, and multiple accurate future prediction values are output at one time. The threshold within this future time period is further determined on each accurate future prediction value, and the threshold can be flexibly adapted to changes in data to achieve dynamic adjustment of the threshold, thereby ensuring the accuracy of the dynamic threshold design and improving the flexibility of the dynamic threshold design.
[0121] Furthermore, the model prediction module 420 is also used for: Perform data preprocessing based on multiple time series to obtain multiple time series after data preprocessing; Perform feature engineering on each time series to obtain multiple target feature sequences; The multiple target feature sequences are input into a multi-target time series forecasting model to obtain a forecast value of each product equity data output by the multi-target time series forecasting model in a future period of time.
[0122] Furthermore, the threshold design module 430 is also used for: Adding the predicted value of the product equity data in the future period to the preset floating value to obtain the highest threshold of the product equity data in the future period; The predicted value of the product equity data in a future period of time is subtracted from the preset floating value to obtain the minimum threshold value of the product equity data in the future period of time.
[0123] Furthermore, the dynamic threshold design device is also used for: Divide the data into a normal range based on the highest threshold and the lowest threshold; Get the real value of the product equity data at the current moment; If the true value is within the normal range of the data, it is determined that the product equity data is normal at the current moment; If the true value does not fall within the normal range of the data, it is determined that the product equity data is abnormal at the current moment, and an alarm is issued based on the product equity data.
[0124] Furthermore, the dynamic threshold design device is also used for: Obtain historical time series of equity samples of multiple products; Divide the historical time series of each product equity sample into a first time series sample and a second time series sample according to a preset ratio; Perform feature engineering based on the first time series sample of each product equity sample to obtain a feature series sample of each product equity sample; Determine the characteristic sequence samples of each product equity sample as model training data, and determine the second time series samples of the product equity sample as label data corresponding to the model training data; Based on multiple model training data and label data corresponding to each model training data, the TSMixer model is trained to obtain the multi-objective time series prediction model.
[0125] Furthermore, the dynamic threshold design device is also used for: If the training data of multiple models are hourly data, the preset loss function is not adjusted; If the multiple model training data are daily level data or monthly level data, the preset loss function is adjusted in hours.
[0126] Furthermore, the dynamic threshold design device is also used for: Determine the provinces to which the training data of multiple models are respectively associated; Calculate the weight value of each province; Based on the weight value of the province associated with each model training data, the preset loss function is weighted adjusted.
[0127] It should be noted that the dynamic threshold design device provided by the present invention can execute the dynamic threshold design method described in any of the above embodiments during specific operation, which will not be elaborated in this embodiment.
[0128] Figure 5 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the dynamic threshold design method, which includes: obtaining time series corresponding to a plurality of product equity data respectively; based on a plurality of time series, training through a multi-objective time series prediction model to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in a future period of time; the multi-objective time series prediction model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or the province granularity of the target prediction task; based on the predicted value of each product equity data in a future period of time, determining the threshold of each product equity data in the future period of time.
[0129] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0130] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the dynamic threshold design method provided by the above-mentioned embodiments, and the method includes: obtaining time series corresponding to multiple product equity data respectively; based on multiple time series, training through a multi-objective time series prediction model to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in the future period; the multi-objective time series prediction model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or province granularity of the target prediction task; based on the predicted value of each product equity data in the future period, determining the threshold of each product equity data in the future period.
[0131] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the dynamic threshold design method provided in the above-mentioned embodiments, the method comprising: obtaining time series corresponding to a plurality of product equity data respectively; based on the plurality of time series, training through a multi-objective time series prediction model to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in a future period of time; the multi-objective time series prediction model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or province granularity of the target prediction task; based on the predicted value of each product equity data in the future period of time, determining the threshold of each product equity data in the future period of time.
[0132] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. Those of ordinary skill in the art may understand and implement the present invention without creative effort.
[0133] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0134] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A dynamic threshold design method, characterized in that: include: Obtain the time series corresponding to the equity data of various products; Based on multiple time series, a multi-objective time series forecasting model is used for training to obtain the predicted value of each product equity data output by the multi-objective time series forecasting model in the future period; the multi-objective time series forecasting model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or provincial granularity of the target forecasting task; Based on the predicted value of each product equity data in a future period of time, a threshold value of each product equity data in the future period of time is determined.
2. The dynamic threshold design method according to claim 1, characterized in that: When the preset loss function is adjusted according to the time granularity of the target prediction task, it includes: If the training data of multiple models are hourly data, the preset loss function is not adjusted; If the multiple model training data are daily level data or monthly level data, the preset loss function is adjusted in hours.
3. The dynamic threshold design method according to claim 2, characterized in that: When the preset loss function is adjusted according to the province granularity of the target prediction task, it includes: Determine the provinces to which the training data of multiple models are respectively associated; Calculate the weight value of each province; Based on the weight value of the province associated with each model training data, the preset loss function is weighted adjusted.
4. The dynamic threshold design method according to claim 1, characterized in that: The multi-objective time series prediction model is trained in the following way: Obtain historical time series of equity samples of multiple products; Divide the historical time series of each product equity sample into a first time series sample and a second time series sample according to a preset ratio; Perform feature engineering based on the first time series sample of each product equity sample to obtain a feature series sample of each product equity sample; Determine the characteristic sequence samples of each product equity sample as model training data, and determine the second time series samples of the product equity sample as label data corresponding to the model training data; Based on multiple model training data and label data corresponding to each model training data, the TSMixer model is trained to obtain the multi-objective time series prediction model.
5. The dynamic threshold design method according to claim 4, characterized in that: The method of training a multi-objective time series forecasting model based on multiple time series to obtain a forecast value of each product equity data output by the multi-objective time series forecasting model in a future period of time includes: Perform data preprocessing based on multiple time series to obtain multiple time series after data preprocessing; Perform feature engineering on each time series to obtain multiple target feature sequences; The multiple target feature sequences are input into a multi-target time series forecasting model to obtain a forecast value of each product equity data output by the multi-target time series forecasting model in a future period of time.
6. The dynamic threshold design method according to any one of claims 1 to 5, characterized in that: The threshold value includes a maximum threshold value and a minimum threshold value; when determining the threshold value of each product equity data in the future period of time based on the predicted value of each product equity data in the future period of time, the following steps are performed for each product equity data: Adding the predicted value of the product equity data in the future period to the preset floating value to obtain the highest threshold of the product equity data in the future period; The predicted value of the product equity data in a future period of time is subtracted from the preset floating value to obtain the minimum threshold value of the product equity data in the future period of time.
7. The dynamic threshold design method according to claim 6, characterized in that: After determining the minimum threshold of the product equity data in the future period, it also includes: Divide the data into a normal range based on the highest threshold and the lowest threshold; Get the real value of the product equity data at the current moment; If the true value is within the normal range of the data, it is determined that the product equity data is normal at the current moment; If the true value does not fall within the normal range of the data, it is determined that the product equity data is abnormal at the current moment, and an alarm is issued based on the product equity data.
8. A dynamic threshold design device, characterized in that: include: The acquisition module is used to obtain the time series corresponding to the equity data of various products; A model prediction module is used to train a multi-objective time series prediction model based on multiple time series to obtain the predicted value of each product equity data output by the multi-objective time series prediction model in the future; the multi-objective time series prediction model is trained using a preset loss function, and the preset loss function is adjusted according to the time granularity or provincial granularity of the target prediction task; The threshold design module is used to determine the threshold of each product equity data in the future period based on the predicted value of each product equity data in the future period.
9. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the dynamic threshold design method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, the computer-readable storage medium comprising a non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the dynamic threshold design method according to any one of claims 1 to 7 are implemented.
11. A computer program product, comprising a computer program, characterized in that: When the computer program is executed by a processor, the steps of the dynamic threshold design method according to any one of claims 1 to 7 are implemented.