Sales prediction method based on multi-source data fusion and ensemble learning
By using multi-source data fusion and ensemble learning methods, a feature set is constructed and a multi-model architecture is used for sales forecasting. This solves the problems of narrow data coverage and poor adaptability in existing technologies, and achieves higher prediction accuracy and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- LUZHOU CO LTD SICHUAN TOBACCO
- Filing Date
- 2026-01-26
- Publication Date
- 2026-05-15
AI Technical Summary
Existing sales forecasting technologies suffer from narrow data coverage and poor model adaptability, resulting in low accuracy and poor robustness.
We employ a multi-source data fusion and ensemble learning approach to acquire historical sales data and social impact data. We construct a feature set through feature extraction and dynamic adaptive filtering, and use three predictive models with clearly defined functions to predict sales. The first predictive model extracts time series characteristics, the second predictive model mines nonlinear features, and a meta-model is used for nonlinear fitting. The model is then optimized by a dynamic update mechanism.
It improves the accuracy and robustness of sales forecasts, enabling it to better adapt to market fluctuations and policy adjustments, and enhances the stability and generalization performance of the forecasting system.
Smart Images

Figure CN122048428A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a sales forecasting method based on multi-source data fusion and ensemble learning. Background Technology
[0002] In modern business operations, sales forecasting serves as a crucial support for supply chain management, production planning, and marketing decisions, directly impacting resource allocation efficiency and the scientific nature of business strategies.
[0003] However, current technologies still face challenges in achieving high-precision sales forecasting. On the one hand, existing methods often suffer from narrow data coverage for sales forecasting; on the other hand, existing forecasting models also have certain adaptability limitations, resulting in generally low accuracy and poor robustness in current sales forecasting technologies. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a sales forecasting method based on multi-source data fusion and ensemble learning, so as to improve the accuracy and robustness of sales forecasting.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: Firstly, this application provides a sales forecasting method based on multi-source data fusion and ensemble learning, the method comprising: Obtain historical sales data and social impact data for the target product and perform data preprocessing; Feature extraction is performed on the historical sales data and the social impact data to obtain multiple initial features. The initial features are then dynamically and adaptively filtered based on the lightweight attention weights of each initial feature and multiple preset features to obtain a feature set. The feature set includes time series features that reflect the time evolution of sales and social impact features that reflect the influence on sales. The feature set and the historical sales data are input into a pre-generated sales prediction model for processing, and the sales prediction result of the target product within a preset time period is output. The sales forecasting model includes a first forecasting model, a second forecasting model, and a meta-model. The first forecasting model is used to extract time series characteristics from the feature set to generate a first sales forecasting result. The second forecasting model is used to extract nonlinear features from the feature set to generate a second sales forecasting result. The meta-model performs nonlinear fitting on the first sales forecasting result and the second sales forecasting result to generate the sales forecasting result. Every preset time step, new sample historical sales data and new sample social impact data are obtained according to a preset sliding window, and the sales prediction model is updated based on the new sample historical sales data and the new sample social impact data to obtain a new sales prediction model.
[0006] In an optional implementation, the initial features include time features, time period features, lag features, and pseudo-monthly time series features corresponding to the social impact data; the feature extraction of the historical sales data and the social impact data to obtain multiple initial features includes: The year and month corresponding to the historical sales data are determined as the time feature; Trigonometric function transformations are performed on the months corresponding to the historical sales data to obtain the time period features corresponding to the historical sales data; the time period features represent the cyclical adjacency relationship between the time features of the months. For each month, a lag feature is constructed based on the historical sales data from three aspects: the lag feature includes lag_1 (sales volume of the previous month), lag_2 (sales volume of the previous two months), and lag_3 (sales volume of the previous three months) to reflect short-term memory; lag_12 (sales volume of the same month of the previous year) to represent annual seasonal memory; and lag_3 (moving average of the past three months), lag_6 (moving average of the past six months), and lag_12 (moving average of the past twelve months) to characterize short-term and medium-term trends. The lag feature represents the relationship between short-term dependence and long-term seasonal trends in the historical sales data. For the low-frequency social impact data, a weighted allocation method is used to map it to a monthly time granularity, and a pseudo-monthly time series feature is constructed that is aligned with the time series of the historical sales data, so as to achieve the unification of the feature space of internal and external data.
[0007] In an optional implementation, the step of dynamically and adaptively filtering the initial features based on lightweight attention weights of each initial feature and multiple preset features to obtain a feature set includes: Multiple initial features are input into the lightweight attention module, and lightweight attention weights corresponding to each initial feature are calculated based on learnable parameters; the calculation formula for the lightweight attention weights is as follows:
[0008] in, The learnable parameters corresponding to the input vector representing the i-th initial feature are iteratively optimized using the backpropagation algorithm based on the prediction error during model training, in order to adaptively represent the sales contribution of the corresponding initial feature in different time periods. The input vector representing the i-th initial feature. Attention weights that characterize the i-th initial feature; A global statistical analysis is performed on the lightweight attention weights corresponding to all the initial features to obtain the mean and standard deviation that reflect the weight distribution characteristics. Based on the mean, the standard deviation and the preset sensitivity coefficient, a screening threshold adapted to the current data distribution is dynamically constructed. Adaptively identify initial features whose lightweight attention weight is higher than the filtering threshold as target features, and determine the feature set by the union of the target features and multiple preset features.
[0009] In an optional implementation, the first prediction model includes a time series model and a residual prediction model, and the first prediction model is trained through the following steps: Obtain the sample historical sales data and sample social impact data corresponding to the target product, and construct a sample feature set based on the sample historical sales data and the sample social impact data; The sample feature set and the sample historical sales data are input into a pre-built time series model. After the hyperparameters of the pre-built time series model are optimized using a stepwise search method, the time series model is trained to obtain a trained time series model. The sample feature set and the sample historical sales data are input into the trained time series model to perform in-sample prediction and obtain the residual values corresponding to each month. The pre-built residual prediction model is trained based on the residual values corresponding to each month and the sample feature set to obtain the trained residual prediction model. The trained time series model and the residual prediction model are integrated to obtain the first prediction model.
[0010] In an optional implementation, the step of training a pre-built residual prediction model based on the residual values corresponding to each month and the sample feature set to obtain a trained residual prediction model includes: Based on the residual values, determine the corresponding lagged residual values for each month; A residual sample set is constructed based on the lagged residual values corresponding to each month and the sample feature set. The residual sample set and the historical sales data of the samples are then input into the pre-constructed residual prediction model for training, thereby obtaining the trained residual prediction model.
[0011] In an optional implementation, the second prediction model is trained through the following steps: The sample feature set and sample historical sales data are input into the pre-built second prediction model. After the model hyperparameters of the pre-built second prediction model are optimized, the second prediction model is trained to obtain the trained second prediction model.
[0012] In an optional implementation, the loss function of the second prediction model is: , , , Representing historical sales data, Characterizing sales forecast results, The weighting value represents sales volume. Characterize the penalty term, The median of historical sales data is represented by s, and s represents the preset multiple. , Characterizes the preset penalty coefficient.
[0013] In an optional implementation, the meta-model is trained through the following steps: The sample feature set and sample historical sales data are input into the trained first prediction model and second prediction model for processing to obtain the first sample sales prediction result and the second sample sales prediction result. Based on the sales prediction results of the first sample, the sales prediction results of the second sample, the sample feature set, and the historical sales data of the sample, a fused sample set is constructed. The fused sample set is then input into a pre-constructed meta-model for training to obtain a trained meta-model. The method further includes: using the trained first prediction model and the second prediction model as base learners, performing model integration on the base learners and the meta-model to obtain the sales prediction model.
[0014] This application provides a sales forecasting method based on multi-source data fusion and ensemble learning. First, historical sales data and social impact data of the target product are acquired and preprocessed. Then, feature extraction and dynamic adaptive filtering are performed on the historical sales data and social impact data to obtain a feature set corresponding to the target product. This feature set covers time-series features reflecting the evolution of sales over time and external features reflecting the effects of external factors, thus providing a more comprehensive decision-making basis for the model. Subsequently, the feature set is input into a pre-generated sales forecasting model for processing. This model consists of three sub-models with clearly defined functions: a first forecasting model extracts time-series characteristics from the feature set to generate a first sales forecast result; a second forecasting model focuses on mining the complex nonlinear relationships and higher-order interaction effects between variables in the feature set to generate a second sales forecast result. These two models, from different modeling perspectives, form complementary linear and nonlinear forecast outputs. Finally, a meta-model is used to perform a nonlinear fitting operation on the first and second sales forecast results to output the final sales forecast result. In this way, by using the characteristic representation and hierarchical modeling strategy of multi-source data, the influence of the inherent laws of time series and external driving factors can be effectively integrated, and the prediction accuracy and stability can be synergistically optimized at the model output level, thereby improving the accuracy and robustness of sales forecasting.
[0015] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 The diagram illustrates a sales forecasting method based on multi-source data fusion and ensemble learning provided in an embodiment of this application. Figure 2 A schematic diagram showing each feature in the feature set and its corresponding attention weight is provided. Figure 3 The training flowchart for the sales forecasting model is shown; Figure 4 The chart shows the monthly sales forecast curve for 2024. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can be arranged and designed in various different configurations.
[0019] The following section uses the server as the execution entity and, in conjunction with a flowchart, provides an exemplary description of a sales forecasting method based on multi-source data fusion and ensemble learning provided in this application. Specifically, Figure 1 A flowchart illustrating a sales forecasting method based on multi-source data fusion and ensemble learning, provided as an embodiment of this application, can be found here. Figure 1 The method includes: Step S20: Obtain historical sales data and social impact data of the target product and perform data preprocessing.
[0020] Optionally, the target product can be tobacco products, alcoholic beverages, electronic products, etc. To ensure that the model learns sufficient information, the historical sales data and social impact data should be taken from a relatively long period of time, such as the past five years.
[0021] In this embodiment, historical sales data, as an endogenous indicator reflecting product market dynamics, mainly comes from the periodic sales ledgers recorded by the enterprise's internal business system, such as the monthly sales statistics of cigarettes in the tobacco industry. This type of data usually has a high time granularity, such as recording historical sales volume for many years on a monthly or weekly basis, forming a time series with trend, seasonality and periodic characteristics.
[0022] However, most existing sales forecasting models are limited to the aforementioned single-dimensional internal historical data, neglecting the potential driving force of the external macroeconomic environment on market demand. This results in a lack of adaptability in the face of economic fluctuations or policy adjustments. Therefore, this embodiment innovatively introduces social impact data as a key exogenous variable. Social impact data characterizes the factors influencing product sales based on the macroeconomic environment. Its scope includes, but is not limited to, socioeconomic variables such as regional economic development levels, population structure changes, industrial restructuring, and residents' consumption capacity. This type of data is typically released regularly by government statistical departments or authoritative institutions and is generally an annual macroeconomic indicator. By integrating such macroeconomic indicators, this method can overcome the closed nature of traditional time series analysis and capture the external driving forces of sales changes from a multi-dimensional perspective.
[0023] In one possible implementation, Table 1 contains the contents of the social impact data; please refer to Table 1.
[0024] Table 1
[0025] It should be noted that the above two types of data may face problems such as missing data, abnormal fluctuations and inconsistent dimensions during the collection process, so preliminary data cleaning and preprocessing operations are required.
[0026] In one example, the preprocessing operation may include filling missing values within the data sequence using linear interpolation, filling missing values at the beginning and end of the sequence with nearby valid values to maintain the continuity of the time series, and identifying outliers that deviate significantly from the normal distribution range according to the statistical 3σ criterion and correcting them by median replacement or numerical truncation, thereby improving data quality and stability.
[0027] Based on this, in order to further eliminate model bias caused by differences in measurement units among different features, all input features can be standardized by Z-score, that is, the original values are converted into a standard normal distribution with a mean of 0 and a standard deviation of 1, so that all types of features can participate in the modeling process on a uniform scale.
[0028] Step S21: Extract features from historical sales data and social impact data to obtain multiple initial features. Then, dynamically and adaptively filter the initial features based on the lightweight attention weights of each initial feature and multiple preset features to obtain a feature set.
[0029] The feature set includes time series features reflecting the evolution of sales over time, and social impact features reflecting the influence on sales.
[0030] In this embodiment, the server can systematically integrate historical sales data and social impact data to construct multiple initial features, forming a candidate feature set covering a wide range of potential influencing factors to comprehensively characterize factors that may affect sales changes. Based on this, a lightweight attention mechanism is introduced to evaluate the importance of each initial feature.
[0031] In this embodiment, the server first calculates the lightweight attention weights of each initial feature and then adaptively filters the initial features based on these calculated lightweight attention weights. In this process, the server abandons the traditional fixed threshold or fixed number of filtering methods, instead dynamically generating filtering boundaries based on the statistical distribution characteristics of all feature weights (such as mean and variance). This means that the filtering criteria can automatically scale as the data changes: when the feature contribution is generally high, the threshold is automatically adjusted to retain more details; when the feature contribution is polarized, the threshold is automatically tightened to remove noise. Through this mechanism, the server can adaptively lock in high-contribution features under the current data distribution and merge them with a preset feature set based on industry expert knowledge, ultimately constructing an optimal feature set that combines data interpretability and business logic. In this embodiment, the preset features refer to a set of key variables predefined based on industry background knowledge and social consumption patterns. The selection of this set of features mainly relies on the relevant experts' deep understanding of the business scenario.
[0032] Step S22: Input the feature set and historical sales data into the pre-generated sales prediction model for processing, and output the sales prediction result of the target product within the preset time period.
[0033] The sales forecasting model includes a first forecasting model, a second forecasting model, and a meta-model. The first forecasting model is used to extract time series characteristics from the feature set to generate a first sales forecast result. The second forecasting model is used to extract nonlinear features from the feature set to generate a second sales forecast result. The meta-model performs nonlinear fitting between the first and second sales forecast results to generate a sales forecast result.
[0034] Optionally, the preset time period can be set by the user in advance for the sales forecasting model, such as one month, one quarter, or one year.
[0035] In this embodiment, the sales forecasting model consists of three core components: a first forecasting model, a second forecasting model, and a meta-model. The first forecasting model extracts time-series characteristics reflecting dynamic changes in sales from the feature set, such as long-term trends, seasonal fluctuations, and periodic patterns, and generates a first sales forecast based on this structural information. The second forecasting model focuses on capturing the nonlinear interaction effects between variables in the feature set, especially the complex correlations between external influencing factors and sales, thereby generating a second sales forecast. These two models serve as base models, modeling the data from two complementary dimensions: linear time-series structure and nonlinear response, respectively, resulting in heterogeneous but complementary forecast outputs.
[0036] Building upon this foundation, the meta-model performs a high-level integration of the two prediction results. Unlike traditional linear weighting or simple averaging, the meta-model employs a nonlinear fitting mechanism, receiving the first and second sales forecast results as inputs, learning the mapping relationship between them and actual sales, and thus generating the final sales forecast result. This process is not simply error compensation; rather, it introduces a learner with strong nonlinear expressive capabilities to dynamically identify the confidence and bias patterns of each base model under different scenarios, achieving more refined weight allocation and residual correction.
[0037] The core concept of this embodiment lies in constructing a hierarchical integrated architecture. The first prediction model focuses on analyzing interpretable temporal evolution patterns, the second prediction model focuses on uncovering nonlinear feature responses that are difficult to characterize using traditional methods, and the meta-model, as a high-level decision-making unit, comprehensively utilizes the outputs of both models and combines key information from the original features to complete the transformation from local prediction to global optimal estimation. Understandably, this model structure achieves functional decoupling and complementary advantages, not only enhancing adaptability to multi-source heterogeneous features but also significantly improving the stability and generalization performance of the prediction system in the face of market fluctuations.
[0038] Step S23: Every preset time step, new sample historical sales data and new sample social impact data are obtained according to a preset sliding window, and the sales prediction model is updated based on the new sample historical sales data and new sample social impact data to obtain a new sales prediction model.
[0039] It should be understood that market conditions and sales performance may undergo structural changes over time. If a sales forecasting model relies on a fixed historical dataset for prediction in the long term, its parameter configuration will struggle to adapt to the latest trend evolution, leading to a gradual decline in forecasting performance. To address this challenge, this embodiment also introduces a dynamic update mechanism to enhance the model's responsiveness to time-varying features.
[0040] In this embodiment, after the initial construction of the sales forecasting model is completed, it is not used permanently. Instead, periodic triggering conditions are set to initiate the model update process every preset time step. This time step can be flexibly set according to the actual business rhythm, such as executing monthly, quarterly, or specific marketing cycles, to ensure that the model can absorb the latest observation information in a timely manner.
[0041] Each time an update is triggered, the server acquires a new round of training input data according to a preset sliding window strategy. This sliding window has a fixed time series length, for example, covering a time range of the most recent 36 months, and only includes data segments spanning W consecutive months backward from the current moment. For the target update point t, the time interval corresponding to the extracted new sample historical sales data is [t...]. W,t 1]. This method excludes all past records earlier than the start point of the window, effectively suppressing the interference of noise or outdated patterns that may exist in the old data on the modeling process.
[0042] Simultaneously, the server acquires new sample social impact data matching this time interval. Based on the sample's historical sales data and social impact data, a new set of sample features is constructed, including but not limited to time-cycle features, lag features, and reconstructed external features calculated based on the data within the current window. During this process, all features are dynamically recalculated based on the latest data to ensure they reflect the actual state of the recent market.
[0043] Subsequently, the new set of sample features is input into the existing model framework to retrain or fine-tune the parameters of the original sales forecasting model. This process may include local optimization of the base learners (such as the first and second forecasting models) and the meta-model's learning and adjustment of the latest forecast distribution, ultimately outputting a refreshed new sales forecasting model that is more adapted to the current market environment.
[0044] This application provides a sales forecasting method based on multi-source data fusion and ensemble learning. First, historical sales data and social impact data of the target product are acquired and preprocessed. Then, feature extraction and adaptive filtering are performed on the historical sales data and social impact data to obtain a feature set corresponding to the target product. This feature set covers time-series features reflecting the evolution of sales over time and external features reflecting the effects of external factors, thus providing a more comprehensive decision-making basis for the model. Subsequently, the feature set is input into a pre-generated sales forecasting model for processing. This model consists of three sub-models with clearly defined functions: a first forecasting model extracts time-series characteristics from the feature set to generate a first sales forecast result; a second forecasting model focuses on mining the complex nonlinear relationships and higher-order interaction effects between variables in the feature set to generate a second sales forecast result. These two models, from different modeling perspectives, form complementary linear and nonlinear forecast outputs. Finally, a meta-model is used to perform a nonlinear fitting operation on the first and second sales forecast results to output the final sales forecast result. In this way, by using the characteristic representation and hierarchical modeling strategy of multi-source data, the influence of the inherent laws of time series and external driving factors can be effectively integrated, and the prediction accuracy and stability can be synergistically optimized at the model output level, thereby improving the accuracy and robustness of sales forecasting.
[0045] First, we proceed with the construction of multi-level features. In one possible approach, the initial features may include time features, time period features, lag features, and pseudo-monthly time series features corresponding to social impact data.
[0046] In this embodiment, the server can determine the year and month corresponding to the historical sales data as time features; perform trigonometric function transformation on the month corresponding to the historical sales data to obtain the time period features corresponding to the historical sales data, wherein the time period features represent the cyclical adjacency relationship between the time features of the months.
[0047] For each month, lagged features are constructed from three aspects based on historical sales data. The lagged features include the sales lag_1 of the previous month, the sales lag_2 of the previous two months, and the sales lag_3 of the previous three months, which reflect short-term memory; the sales lag_12 of the same month of the previous year, which represents annual seasonal memory; and the moving average features of the past three months (ma_3), the moving average features of the past six months (ma_6), and the moving average features of the past twelve months (ma_12), which depict short-term and medium-term trends. The lagged features represent the relationship between short-term dependence and long-term seasonal trends in historical sales data.
[0048] For low-frequency social impact data, a weighted allocation method is used to map it to a monthly time granularity, constructing pseudo-monthly time series features that are aligned with the time series of historical sales data, so as to achieve a unified feature space for internal and external data.
[0049] In this embodiment, the initial feature must first include the time feature, namely the year information (year) and month information (month) corresponding to the historical sales data itself.
[0050] It should be understood that in sales forecasting tasks, months are a periodic variable. If they are directly encoded linearly with values from 1 to 12, their inherent cyclical characteristics cannot be accurately reflected. For example, the fact that December and January are adjacent in time will be incorrectly modeled as the maximum interval under linear representation. Therefore, to overcome this problem, this embodiment can transform discrete month values into a continuous, smooth, and periodic two-dimensional representation through mathematical mapping, thereby more realistically depicting the cyclical adjacency relationship between months.
[0051] Specifically, the server can use sine and cosine functions to perform nonlinear transformations on the original month m (ranging from 1 to 12) to generate the time period feature.
[0052] In this embodiment, the time period feature includes two aspects, one of which is... It can be done through the formula The calculation shows that the other one is... It can be done through the formula The calculation yielded this result. Therefore, and They can form a pair of complementary periodic eigenvectors.
[0053] During the above steps, the transformation maps each month to a coordinate point on the unit circle, naturally bringing adjacent months closer in Euclidean distance in vector space, while increasing the distance between relative months, thus effectively preserving the topological structure information in the time dimension. Based on this, the obtained time-cycle features can not only be more reasonably analyzed by the model, but also provide a more expressive input basis for subsequent capture of seasonal patterns.
[0054] In one example, taking the current month as December, the lag feature could include sales in November, October, and September reflecting short-term memory; sales in December of last year representing annual seasonal memory; and average sales from September to December, average sales from June to December, and average sales for the year depicting short-term and medium-term trends.
[0055] In addition, the weighting method refers to using the proportion of sales in each month to the total sales for the year in historical sales data as the weight coefficient for each month, and then decomposing the social impact data released annually into 12 corresponding virtual monthly values according to the weight coefficient, so that the original static annual total is reconstructed into a pseudo-monthly time series feature with a reasonable seasonal distribution.
[0056] In this process, the calculated percentages essentially reflect the typical sales activity of the product in different months. Using this prior information to guide the detailed allocation of social consumption data can enhance the rationality of the correlation between external characteristics and the actual market conditions of the month while maintaining overall consistency. The final social consumption data not only inherits the economic significance of the original macroeconomic variables but also adapts to the time resolution required for monthly modeling, thereby introducing more explanatory external driving factors into the model.
[0057] This application provides a sales forecasting method based on multi-source data fusion and ensemble learning. By constructing time features, time cycle features, lag features, and external features, it systematically enhances the ability of the feature space to represent the dynamic behavior of sales. Among them, time cycle features solve the nonlinear modeling problem of periodic variables, lag features capture the time-series dependency structure of sales itself, and social impact data realizes the effective transfer of low-frequency macro information to a high-frequency forecasting framework.
[0058] This can be understood as follows: this feature extraction method not only improves the information density of the input variables, but also enhances the model's ability to fit real market patterns. In particular, it can demonstrate stronger adaptability in consumer goods forecasting scenarios that are highly seasonal and significantly affected by the macroeconomy.
[0059] Optionally, after determining the time features, time period features, lag features, and external features, the server can further assign lightweight attention weights to each initial feature, thereby adaptively filtering the initial features based on the lightweight attention weights and multiple preset features.
[0060] The following section proposes a possible implementation method for dynamically and adaptively filtering initial features based on lightweight attention weights for each initial feature and multiple preset features to obtain a feature set. Specifically, the server can input multiple initial features into the lightweight attention module and calculate the lightweight attention weights corresponding to each initial feature based on learnable parameters.
[0061] During the above steps, the server first organizes all initial features into a two-dimensional feature matrix, where each row corresponds to a complete observation over a time step (e.g., one month), and each column represents the performance of a particular initial feature throughout the entire time period. This feature matrix is then fed into a lightweight attention module for processing. In this module, the vector of each feature is multiplied by its corresponding learnable parameter to generate an initial attention score. Subsequently, the scores of all features are normalized using the Softmax function, resulting in a set of lightweight attention weights between 0 and 1. These weights reflect the relative importance of each initial feature for sales prediction in the current modeling task.
[0062] In one possible implementation, the lightweight attention weight can be calculated using the following formula:
[0063] in, The learnable parameters corresponding to the input vector representing the i-th initial feature are iteratively optimized using the backpropagation algorithm based on the prediction error during model training, in order to adaptively represent the sales contribution of the corresponding initial feature in different time periods. The input vector representing the i-th initial feature. The attention weights represent the i-th initial feature. Furthermore, the attention weights of all initial features, after being normalized using the Softmax function, should satisfy the following condition: .
[0064] It should be noted that this lightweight attention weight... Instead of being preset fixed values, the learnable parameters are continuously optimized based on the prediction error during backpropagation. This means that the model can automatically perceive the changes in the contribution of various social influencing factors (such as policy fluctuations and seasonal anomalies) to sales in different historical periods, thereby achieving dynamic focusing on the intensity of feature attention.
[0065] Furthermore, the lightweight attention module used in this embodiment is lightweight in terms of simplified computational structure. Unlike traditional full attention mechanisms that require constructing complex query, key, and value transformation matrices, this embodiment uses a one-dimensional learnable parameter vector. With feature vectors Direct dot product operations are performed. This design significantly reduces the number of parameters and computational complexity, making the computational cost increase linearly with the feature dimension. This significantly improves the server's processing efficiency while ensuring the accuracy of feature evaluation, making it suitable for real-time or near-real-time processing of large-scale social consumption data.
[0066] Furthermore, the server can perform global statistical analysis on the lightweight attention weights corresponding to all initial features to obtain the mean and standard deviation that reflect the weight distribution characteristics. Based on the mean, standard deviation, and preset sensitivity coefficient, it can dynamically construct a screening threshold that is adapted to the current data distribution. Then, it can adaptively identify the initial features with lightweight attention weights higher than the screening threshold as target features and determine the feature set by the union of the target features and multiple preset features.
[0067] In this embodiment, the server can first statistically analyze the overall distribution characteristics of the lightweight attention weights of all initial features, including their arithmetic mean and standard deviation of dispersion. Based on this, a screening threshold is constructed by combining a preset empirical adjustment coefficient, thereby forming a judgment criterion that dynamically adjusts with the data distribution.
[0068] In one possible implementation, the filtering threshold can be ,in, The mean of the attention weights. Standard deviation, This is the preset sensitivity coefficient. Understandably, this sensitivity coefficient can be set based on actual application conditions and experience, for example, set to 0.7.
[0069] During the execution of the above steps, since the screening threshold is not fixed but generated based on the actual fluctuation of the feature importance distribution in the current dataset, it can adapt to the feature structure changes in different regions, time periods or product categories, and avoid the subjective bias or overly strict or lenient problems caused by manually setting the screening threshold.
[0070] Furthermore, the server can retain only the initial features whose attention weight is higher than the screening threshold as target features. It should be noted that the target features are not directly used as the feature set, but need to be further combined with multiple preset features to determine the final feature set.
[0071] In this embodiment, since the preset feature refers to a set of key variables predetermined based on industry experience, economic theory or business logic, its selection does not completely depend on the statistical performance in the current sample, but rather reflects the understanding and prior knowledge of the consumption patterns in real society. Therefore, by taking the union between the high contribution features identified by the attention mechanism and the set of features guided by the knowledge of the field, it can be ensured that the features finally included in the model not only show strong correlation at the data level, but also have reasonable interpretability at the business level.
[0072] In one example, the attention weights of the time period features (month_sin, month_cos), time features (month, year), and lag features (lag_1, lag_2, lag_3, lag_12, ma_3, ma_6, ma_12) can be represented as shown in Table 2 below.
[0073] Table 2
[0074] In this example, Figure 2 For a schematic diagram of each feature in the feature set and its corresponding attention weight, please refer to [link / reference]. Figure 2 This feature set may include other features besides year, as well as some key social features, such as GDP, per capita consumption expenditure of rural residents, and number of employed persons.
[0075] Next, we will present a possible implementation method for training the first prediction model.
[0076] In one possible implementation, the first prediction model includes a time series model and a residual prediction model. In this embodiment, the server can obtain sample historical sales data and sample social impact data corresponding to the target product, and construct a sample feature set based on the sample historical sales data and sample social impact data; input the sample feature set and sample historical sales data into the pre-constructed time series model; after optimizing the hyperparameters of the pre-constructed time series model using a stepwise search method, train the time series model to obtain a trained time series model; input the sample feature set and sample historical sales data into the trained time series model for in-sample prediction to obtain the residual values corresponding to each month; train the pre-constructed residual prediction model based on the residual values corresponding to each month and the sample feature set to obtain a trained residual prediction model; integrate the trained time series model and the residual prediction model to obtain the first prediction model.
[0077] In this embodiment, during the model initialization phase, the server can first obtain the historical sales data and social impact data of the target product. These data constitute the basic input set for model learning, reflecting the actual sales performance of the product at different time points and its socio-economic background. Subsequently, a sample feature set can be constructed based on this historical sales data and social impact data. This process is similar to the feature set construction process described above and will not be elaborated upon here.
[0078] Based on this, the server can input the sample feature set and sample historical sales data into a pre-built time series model for training.
[0079] In one possible implementation, the time series model can be the SARMIX model. This model can simultaneously capture the three core characteristics of time series: trend, seasonality, and autocorrelation, thus solving most complex time series problems. In another possible implementation, the model can be simply represented as SARIMAX(p,d,q)(P,D,Q), specifically represented by the following formula:
[0080] .
[0081] in, This is the non-seasonal autoregressive component. This is the seasonal autoregressive component. This is the non-seasonal difference component. This is the seasonal difference component. The predicted value at time t, For the preset constant term, This is the non-seasonal moving average portion. This is the seasonal moving average portion. For the error term over time t, For exogenous variables, p is the autoregression order, d is the difference order, q is the moving average order, P is the seasonal autoregression order, D is the seasonal difference order, Q is the seasonal moving average order, and s is the seasonal cycle length.
[0082] This model can simultaneously characterize the trend components, periodic fluctuations, and lag dependencies of the target variable over time. Based on this, a fully automated hyperparameter optimization mechanism is introduced to systematically evaluate the model's performance under different parameter combinations.
[0083] This optimization process employs a stepwise search algorithm, traversing key parameter combinations within a preset range, including the autoregressive order (p), differencing order (d), moving average order (q), and seasonally relevant combinations such as the autoregressive order (P), differencing order (D), moving average order (Q), and period length (s). The AIC criterion (Akaike Information Criterion) is used as the evaluation metric. The AIC criterion balances model goodness of fit with complexity; a smaller value indicates that the model maintains simplicity while possessing stronger data interpretability.
[0084] In this process, by comparing the AIC scores under different parameter configurations, the parameter combination that minimizes the criterion value is selected, thereby achieving parameter tuning of the pre-built time series model.
[0085] In one example, the optimal parameter combination could be SARIMAX(2,0,2)(1,0,1,12), which indicates that the model does not require differencing (d=0,D=0), the original sequence is stationary, and it contains second-order non-seasonal autoregressive (AR) and moving average (MA) terms, as well as first-order seasonal autoregressive (SAR) and seasonal moving average (SMA) terms, with a period of 12 months.
[0086] In this example, after optimization, the MAPE (Mean Absolute Error) of the model decreased from 12.6 to 5.9%, and the R2 increased from 0.897 to 0.973, resulting in a significant improvement in model performance.
[0087] After hyperparameter optimization, the server can use the optimized parameter configuration to train the time series model, enabling it to learn an internal mapping relationship that accurately reflects actual sales dynamics based on the sample feature set and historical sales data. Once trained, the time series model possesses the ability to effectively extract core features of the time series and can output the first sales prediction result for future time points.
[0088] Furthermore, the server can use the trained time series model to perform internal predictions on samples within the training set, outputting the predicted values for each month, and then subtracting these predictions from the actual sales values to obtain the residual values for each month. These residual values reflect the data fluctuations that the time series model failed to explain, typically containing complex nonlinear structures or random perturbations.
[0089] In one possible implementation, for month t, the corresponding residual value Through formula Calculated.
[0090] Furthermore, the server can train the pre-built residual prediction model based on the residual value and the sample feature set to obtain the trained residual prediction model. After the independent training of the two sub-models is completed, the server can integrate the trained time series model with the residual prediction model to form a unified first prediction model.
[0091] The integration method can be as follows: During the inference phase, the time series model first generates the basic prediction results, then the residual prediction model estimates the corresponding residual terms, and finally the two are superimposed to output as the overall prediction output of the first prediction model. That is to say, the final output prediction value is... The predicted value output by the time series model The residual values output by the residual prediction model sum.
[0092] Alternatively, the residual prediction model can be a LightGBM model.
[0093] In one possible implementation, when training the residual prediction model, the server can first determine the lagged residual values corresponding to each month based on the residual values, then construct a residual sample set based on the lagged residual values corresponding to each month and the sample feature set, and input the residual sample set and the sample historical sales data into the pre-constructed residual prediction model for training to obtain the trained residual prediction model.
[0094] Understandably, to further uncover potential patterns in the residuals, the server can construct lagged residual features based on the residual values corresponding to each month, such as the residual terms of the previous month. Residual items from the first two months To characterize the time dependence of the error sequence.
[0095] Subsequently, the server can construct a residual sample set based on the lagged residual values and the original sample feature set, including lagged residual terms and features filtered by attention weights. This residual sample set is then input into a pre-built residual prediction model for training, and the output target is set to the residual value at the current moment. This allows the residual prediction model to learn how to predict future residual change trends from historical error patterns and the external environment, thereby improving the overall prediction accuracy.
[0096] The core concept of this embodiment lies in introducing a residual learning mechanism to achieve secondary modeling of prediction errors, thereby effectively improving the model's adaptability to complex dynamic systems, especially suitable for sales forecasting scenarios with significant seasonality and nonlinear disturbances. Thus, this architecture not only retains the advantages of time-series models in handling trends and cycles, but also enhances the ability to capture some nonlinear components through the residual prediction model, achieving multi-level, complementary information extraction and fusion.
[0097] Next, we will present a possible implementation method for training the second prediction model.
[0098] Specifically, the server can input the sample feature set and sample historical sales data into the pre-built second prediction model. After optimizing the model hyperparameters of the pre-built second prediction model, the second prediction model is trained to obtain the trained second prediction model.
[0099] Optionally, the second prediction model can be an ensemble learning model based on a gradient boosting framework, namely XGBoost (eXtreme Gradient Boosting). The server can input the sample feature set into the pre-built second prediction model and carry out the training process under a supervised learning paradigm.
[0100] Specifically, the training process optimizes by minimizing a predefined objective function. Multiple weak learners—typically decision trees—are iteratively built, and their outputs are weighted and summed to form a final strong prediction model. In each iteration, the model focuses on the residuals from the previous prediction, learning how to correct biases and continuously improving overall prediction accuracy.
[0101] In this embodiment, the XGBoost model formula is represented as: Its objective function is expressed as: .in, These are the predicted values output by the XGBoost model. This represents the actual sales figures. Let K be the predicted value of the k-th tree, and K represent the total number of decision trees in the model. For loss function, For regularization terms, Let F be the complexity of the k-th tree, and F() be the function space, which is the set of all allowed regression tree functions. Represents the k-th tree It must be selected from a set of tree models F defined by XGBoost.
[0102] In this process, the objective function consists of two parts: a loss function and a regularization term. The loss function measures the difference between the predicted value output by the current model and the actual sales value, driving the model to converge toward a better solution; while the regularization term penalizes the complexity of each newly added weak learner, preventing the model from overfitting the training data and causing its performance to decline on new samples.
[0103] By jointly optimizing these two aspects, the model improves its fitting ability while maintaining structural simplicity, achieving a learning effect that appropriately avoids over-assumption of the training data. It should be noted that the gradient boosting mechanism used in the second prediction model differs from parallel ensemble methods such as random forests. Its core lies in sequentially constructing tree structures with error correction capabilities, allowing subsequent trees to specifically improve the overall model's performance on specific samples.
[0104] Understandably, the second prediction model needs to optimize and adjust its internal hyperparameters during training to improve the model's learning ability and generalization performance on the target data distribution.
[0105] Specifically, after inputting the sample feature set into the pre-built second prediction model, the server can initiate the hyperparameter optimization process for the second prediction model. This optimization process can be implemented using Bayesian optimization methods. Its core mechanism is to use Gaussian processes to establish a probabilistic surrogate model of the objective function, thereby efficiently exploring the hyperparameter space within a limited number of iterations and identifying the optimal hyperparameter combination that minimizes the validation error. In this process, the model evaluation strategy adopts time-series cross-validation to ensure that the data partitioning conforms to the chronological order and avoids information leakage. In specific implementation, the training set is divided into the first 75% as the training subset and the last 25% as the validation subset according to the time axis to simulate the rolling prediction logic in real prediction scenarios.
[0106] In one example, the second prediction model is the XGBOOST model, and the optimal hyperparameters obtained after Bayesian optimization are shown in Table 3.
[0107] Table 3
[0108] The optimal hyperparameters determined through the above optimization process include key configuration items such as learning rate, maximum tree depth, minimum weight of child nodes, number of trees, sample sampling ratio, and feature sampling ratio. These parameters together determine the structural complexity and learning behavior of the second prediction model.
[0109] After completing hyperparameter tuning, the server can fix the obtained parameter configuration and formally train the second prediction model based on it. During the training phase, the sample feature set is used as input, and multiple decision tree weak learners are iteratively constructed through a gradient boosting framework to gradually reduce prediction bias and finally generate the trained second prediction model.
[0110] It is worth noting that the loss function relied upon in this training process is not This is not the standard squared error form, but an asymmetric weighted loss function customized for the business scenario. In this embodiment, the loss function of the second prediction model is... , , , Representing historical sales data, Characterizing sales forecast results, The weighting value represents sales volume. Characterize the penalty term, The median of historical sales data is represented by s, and s represents the preset multiple. , Characterizes the preset penalty coefficient.
[0111] The function This is used to adjust the strength of the error penalty under different sales ranges; here The median of historical sales data is set as the threshold separating high and low sales, and s is a preset multiple. (e.g., 0.15) This is used to control the steepness of the weight changes. This design ensures that when actual sales volume y is at a low level (e.g., during the off-season), When y approaches 1, a higher error weight is assigned, thereby enhancing the model's focus on predicting accuracy during periods of low sales; while when y is higher, The value was reduced to between 0.3 and 0.5 to moderately suppress the excessive impact of abnormal fluctuations.
[0112] In addition, the loss function also introduces As a direction-sensitive penalty, it distinguishes the consequences of overestimation and underestimation. Taking the tobacco industry as an example, based on the actual operational needs of the tobacco industry, a significant underestimation in sales forecasting may lead to irreversible losses such as market shortages and customer churn, thus requiring a higher penalty; while overestimation, although increasing inventory pressure, is relatively acceptable. Therefore, Set as a conditional coefficient in the predicted value When the value is significantly lower than the true value y, a larger value is applied (e.g., the preset penalty coefficient is 2), while the baseline value remains unchanged in other cases, thereby achieving selective reinforcement constraints on the underestimated behavior.
[0113] The core of this embodiment lies in jointly optimizing the hyperparameter configuration and loss function structure of the model. This enables the second prediction model to not only possess excellent fitting capabilities but also fully reflect the asymmetric risk preferences and seasonal sensitivity characteristics in sales operations. This effectively enhances the model's adaptability and predictive robustness in complex consumption environments, particularly demonstrating superior responsiveness in low-sales months and scenarios with sudden trend changes. The entire training process described above achieves a transformation path from raw data to a high-performance prediction model, laying a high-quality foundation for subsequent ensemble predictions.
[0114] Next, we will provide a possible implementation method for training the meta-model.
[0115] In this embodiment, the server can input the sample feature set and sample historical sales data into the trained first prediction model and second prediction model for processing to obtain the first sample sales prediction result and the second sample sales prediction result; construct a fused sample set based on the first sample sales prediction result, the second sample sales prediction result, the sample feature set and the sample historical sales data, and input the fused sample set into the pre-built meta-model for training to obtain the trained meta-model.
[0116] It should be understood that the construction of sales forecasting models not only depends on the ability of the base learner to capture patterns in historical data, but more importantly, on how to effectively integrate the outputs of different models to form a more robust and accurate final forecast result.
[0117] In this embodiment, in order to achieve complementary advantages of multiple models and overcome the limitations of a single model, a model integration mechanism based on a hierarchical architecture is proposed. Its core is to train a meta-model with nonlinear combination capabilities by constructing a fusion sample set, and then use the first prediction model and the second prediction model as base learners to form a complete integration framework together with the meta-model.
[0118] Specifically, after obtaining the sales forecast results of the first sample and the sales forecast results of the second sample, the key step that the server needs to perform is to construct a fused sample set.
[0119] During the above steps, the generation of the fusion sample set is not simply a matter of splicing the prediction outputs of the two base models. Instead, it involves comprehensive organization and structured processing of the first sample sales prediction result, the second sample sales prediction result, relevant information in the sample feature set, and historical sales data of the sample as input elements.
[0120] The first sample sales forecast result is derived from the modeling output of the first prediction model on the historical sales data and social impact data of the sample, mainly reflecting the trend, seasonality, and periodicity of the time series. The second sample sales forecast result is generated by the second prediction model, focusing on uncovering the complex nonlinear relationships between features and the influence paths of external factors. Furthermore, the fused sample set also incorporates some original sample features, especially key variables selected after feature importance assessment, thereby preserving the integrity of the underlying data and avoiding information loss due to using only the model output.
[0121] Alternatively, instead of using the entire set of sample features, you can selectively use some features from the set of sample features based on the actual application, such as the features with the top ten attention weights.
[0122] Next, the fused sample set is fed into a pre-built meta-model for training. This meta-model is a meta-learner capable of relearning the predictive behavior of multiple base models. Its training process uses real historical sales data as supervision, aiming to learn the mapping relationship between the base model predictions and the true target.
[0123] Through the gradient boosting algorithm, the meta-model can adaptively identify the performance differences of different base models under various input conditions and establish a non-linear weighting mechanism accordingly. This mechanism differs from traditional linear weighted averaging methods; it dynamically adjusts the proportion of contributions from each base model, exhibiting stronger corrective capabilities, especially in the face of market upheavals or abnormal fluctuations. For example, if the first predictive model underestimates the market in a given month while the second predictive model is relatively accurate, the meta-model can learn from historical patterns and assign higher weights to the latter, thereby achieving error compensation.
[0124] In one possible implementation, the metamodel could be CATBoost, whose output is the predicted value. It can be characterized as ,in, The predicted value output by the first prediction model represents the value of the prediction. The predicted value output by the second prediction model represents the value of the prediction. The optimal nonlinear combination function characterizing CATBoost learning.
[0125] Furthermore, after the meta-model is trained, the integration of the entire sales prediction model is achieved. At this point, the server can use the trained first and second prediction models as base learners, and integrate the base learners and the meta-model to obtain the final sales prediction model.
[0126] In this embodiment, the connection between the base learner and the meta-model can form a typical Stacking ensemble structure.
[0127] It should be noted that the “model integration of base learners and meta-models” described here does not refer to the physical assembly of modules, but rather to the logical closed loop formed by a phased training strategy. The first phase uses sample data to train the base learner, the second phase constructs a fused sample set based on the out-of-bag prediction results of the base learner on the training set, and uses this to train the meta-learner, ultimately forming an end-to-end prediction pipeline.
[0128] To facilitate understanding of the training logic of the sales forecasting model in this solution, the following section will take the SARIMAX model as the first forecasting model and the XGBoost model as the second forecasting model as examples, and provide an overall introduction to the training process of the sales forecasting model with illustrations.
[0129] Specifically, Figure 3 For a flowchart of the training process for the sales forecasting model, please refer to [link / reference]. Figure 3 The server can first obtain the historical sales data and social impact data of the target product. The historical sales data refers to the market sales data of the target product, and the social impact data refers to the social consumption data of the target product.
[0130] Subsequently, the server can perform feature extraction, lightweight attention weight calculation, and dynamic adaptive filtering on historical sales data and social impact data respectively to obtain the time features, time period features, and lag features corresponding to historical sales features, as well as the pseudo-monthly time series features corresponding to social impact data. Based on the above features and historical sales data, the server can jointly construct the model input data.
[0131] Based on this, the server can train both the SARIMAX and XGBoost models using the model input data. In this process, on the one hand, for the SARIMAX model, the server can first optimize the hyperparameters using a stepwise search algorithm to train the SARIMAX model, and then combine this with LightGBM residual learning to train the residual prediction model, ultimately obtaining the optimized SARIMAX model. On the other hand, for the XGBoost model, a custom loss function can be set, and its hyperparameters can be optimized using a Bayesian algorithm, ultimately obtaining the optimized XGBoost model.
[0132] Based on this, the server can train a meta-model and perform stacking model integration on the SARIMAX optimized model, the XGBoost optimized model, and the meta-model to obtain an integrated model, namely the sales forecast model in this embodiment of the application. Then, the performance of the final integrated model can be verified.
[0133] It should be noted that, to ensure the model's adaptability to dynamic market changes and the timeliness of its predictions, the server can also use a sliding window prediction mechanism at preset steps to acquire new sample data and update the aforementioned feature set. This updated feature set is then used to retrain or fine-tune the parameters of the SARIMAX and XGBoost models, thereby obtaining a new sales forecasting model to capture the latest market patterns. The predictive performance of the sales forecasting model provided in this application embodiment will be further explained below with reference to specific evaluation metrics.
[0134] To comprehensively evaluate the predictive power of the proposed model, this study selected several representative comparative models and conducted a systematic analysis using evaluation metrics widely adopted in statistical learning. The comparative models encompassed traditional time series methods and modern machine learning algorithms, specifically including unoptimized SARIMAX and XGBoost models, as well as parameter-tuned optimized SARIMAX and XGBoost models. These were used as benchmarks to measure the improvement in prediction accuracy of the proposed sales forecasting model.
[0135] In terms of evaluation metrics, key performance indicators such as mean absolute percentage error (MAPE) and coefficient of determination (R²) were mainly adopted. These indicators can reflect the degree of deviation between the predicted value and the actual observed value and the model's ability to fit the overall trend of the data from different perspectives.
[0136] The formula for calculating MAPE is as follows: Where n is the number of prediction time points, for example, 12 months. Let represent the actual sales volume at the i-th predicted time point, for example, the actual sales volume in October. Let be the sales forecast value at the i-th forecast time point, such as the sales forecast value for October. MAPE effectively eliminates the influence of dimensional differences by normalizing the forecast error relative to the actual value, enabling horizontal comparison of forecast results at different scales or fluctuation levels on a uniform scale. The lower the value, the higher the relative accuracy of the forecast.
[0137] R² is used to measure the model's ability to explain the variability of the target variable, and its calculation formula is: ,in, The arithmetic mean of all actual sales is given. The result reflects the improvement that the model can bring compared to simple mean prediction. The closer the value is to 1, the more fully the model captures the data structure and the higher the quality of the fit.
[0138] Using cigarette sales data from January 2011 to December 2023 as the training set and the entire year of 2024 cigarette sales data as the test set, the performance of each model showed significant differences. Table 4 compares the predictive performance of each parameter on the 2024 test set.
[0139] Table 4
[0140] The original SARIMAX model had a MAPE of 12.6% and an R² of 0.897. After automatic optimization to determine the optimal parameter combination, its predictive performance improved significantly, with the MAPE decreasing to 5.9% and the R² increasing to 0.973, demonstrating the significant impact of parameter optimization on traditional time series models. Similarly, the original XGBoost model had an initial MAPE of 9.4% and an R² of 0.935. After introducing Bayesian hyperparameter optimization and combining it with a customized loss function, the MAPE further decreased to 7.0%, and the R² increased to 0.963, validating the effectiveness of model tuning and business-oriented loss design.
[0141] The final ensemble model (the sales forecast model in this application) achieves a deeper level of integration and synergy based on the baseline model mentioned above. It utilizes the Stacking framework to use the outputs of SARIMAX and XGBoost as input features, and introduces CATBoost as a meta-learner to complete nonlinear weighted integration, while retaining some highly important original features to enhance information transmission. This ensemble strategy achieved optimal performance, reducing the MAPE to 2.9%, further reducing the relative error by more than half compared to the optimized SARIMAX model, with an R² as high as 0.992. This means the model can explain more than 99% of the target variable variance, demonstrating extremely strong data fitting ability and generalization potential.
[0142] Figure 4 Table 5 shows the monthly cigarette sales forecast curve for 2024, and is a detailed table of the results obtained by forecasting cigarette sales using the sales forecasting model provided in the embodiments of this application. Please refer to [link / reference]. Figure 4 And Table 5 below.
[0143] Table 5
[0144] Judging from the trend of the prediction curve, the overall output of the sales prediction model provided in this application embodiment is highly consistent with the actual sales trend, especially maintaining a small deviation in most months. For example, at nodes such as January, February, and September, the absolute percentage error is controlled within 2%, with the error in September being only 0.12%, demonstrating good stability and accuracy. Although there were some underestimations and overestimations in August and October, especially in October when the predicted value exceeded the actual value by nearly 230,000, corresponding to an error of 9.47%, the total predicted sales for the whole year was 33.516 million, which was only 78,000 higher than the actual total. The average absolute percentage error for the whole year remained at 0.23%, indicating that the overall prediction deviation distribution was relatively balanced and no systematic shift occurred.
[0145] In summary, this sales forecasting model not only significantly outperforms various single models in terms of quantitative indicators, but also demonstrates stronger adaptability and robustness in its ability to reproduce actual trends, fully reflecting the advantages of multi-source feature fusion and model collaboration mechanisms in complex sales forecasting scenarios.
[0146] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A sales forecasting method based on multi-source data fusion and ensemble learning, characterized in that, The method includes: Obtain historical sales data and social impact data for the target product and perform data preprocessing; Feature extraction is performed on the historical sales data and the social impact data to obtain multiple initial features. The initial features are then dynamically and adaptively filtered based on the lightweight attention weights of each initial feature and multiple preset features to obtain a feature set. The feature set includes time series features that reflect the time evolution of sales and social impact features that reflect the influence on sales. The feature set and the historical sales data are input into a pre-generated sales prediction model for processing, and the sales prediction result of the target product within a preset time period is output. The sales forecasting model includes a first forecasting model, a second forecasting model, and a meta-model. The first forecasting model is used to extract time series characteristics from the feature set to generate a first sales forecasting result. The second forecasting model is used to extract nonlinear features from the feature set to generate a second sales forecasting result. The meta-model performs nonlinear fitting on the first sales forecasting result and the second sales forecasting result to generate the sales forecasting result. Every preset time step, new sample historical sales data and new sample social impact data are obtained according to a preset sliding window, and the sales prediction model is updated based on the new sample historical sales data and the new sample social impact data to obtain a new sales prediction model.
2. The method according to claim 1, characterized in that, The initial features include time features, time period features, lag features, and pseudo-monthly time series features corresponding to the social impact data; the feature extraction of the historical sales data and the social impact data yields multiple initial features, including: The year and month corresponding to the historical sales data are determined as the time feature; Trigonometric function transformations are performed on the months corresponding to the historical sales data to obtain the time period features corresponding to the historical sales data; the time period features represent the cyclical adjacency relationship between the time features of the months. For each month, a lag feature is constructed from three aspects based on the historical sales data. The lag feature includes lag_1 (sales volume of the previous month), lag_2 (sales volume of the previous two months), and lag_3 (sales volume of the previous three months) to reflect short-term memory; lag_12 (sales volume of the same month of the previous year) to represent annual seasonal memory; and moving average features of the past three months (ma_3), the past six months (ma_6), and the past twelve months (ma_12) to depict short-term and medium-term trends. The lag feature represents the relationship between short-term dependence and long-term seasonal trends in the historical sales data. For the low-frequency social impact data, a weighted allocation method is used to map it to a monthly time granularity, and a pseudo-monthly time series feature is constructed that is aligned with the time series of the historical sales data, so as to achieve the unification of the feature space of internal and external data.
3. The method according to claim 1, characterized in that, The step of dynamically and adaptively filtering the initial features based on lightweight attention weights of each initial feature and multiple preset features to obtain a feature set includes: Multiple initial features are input into the lightweight attention module, and lightweight attention weights corresponding to each initial feature are calculated based on learnable parameters; the calculation formula for the lightweight attention weights is as follows: in, The learnable parameters corresponding to the input vector representing the i-th initial feature are iteratively optimized using the backpropagation algorithm based on the prediction error during model training, in order to adaptively represent the sales contribution of the corresponding initial feature in different time periods. The input vector representing the i-th initial feature. Attention weights that characterize the i-th initial feature; A global statistical analysis is performed on the lightweight attention weights corresponding to all the initial features to obtain the mean and standard deviation that reflect the weight distribution characteristics. Based on the mean, the standard deviation and the preset sensitivity coefficient, a screening threshold adapted to the current data distribution is dynamically constructed. Adaptively identify initial features whose lightweight attention weight is higher than the filtering threshold as target features, and determine the feature set by the union of the target features and multiple preset features.
4. The method according to claim 1, characterized in that, The first prediction model includes a time series model and a residual prediction model, and the first prediction model is trained through the following steps: Obtain the sample historical sales data and sample social impact data corresponding to the target product, and construct a sample feature set based on the sample historical sales data and the sample social impact data; The sample feature set and the sample historical sales data are input into a pre-built time series model. After the hyperparameters of the pre-built time series model are optimized using a stepwise search method, the time series model is trained to obtain a trained time series model. The sample feature set and the sample historical sales data are input into the trained time series model to perform in-sample prediction and obtain the residual values corresponding to each month. The pre-built residual prediction model is trained based on the residual values corresponding to each month and the sample feature set to obtain the trained residual prediction model. The trained time series model and the residual prediction model are integrated to obtain the first prediction model.
5. The method according to claim 4, characterized in that, The step of training the pre-constructed residual prediction model based on the residual values corresponding to each month and the sample feature set to obtain the trained residual prediction model includes: Based on the residual values, determine the corresponding lagged residual values for each month; A residual sample set is constructed based on the lagged residual values corresponding to each month and the sample feature set. The residual sample set and the historical sales data of the samples are then input into the pre-constructed residual prediction model for training, thereby obtaining the trained residual prediction model.
6. The method according to claim 1, characterized in that, The second prediction model is trained through the following steps: The sample feature set and sample historical sales data are input into the pre-built second prediction model. After the model hyperparameters of the pre-built second prediction model are optimized, the second prediction model is trained to obtain the trained second prediction model.
7. The method according to claim 6, characterized in that, The loss function of the second prediction model is , , , Representing historical sales data, Characterizing sales forecast results, The weighting value represents sales volume. Characterize the penalty term, The median of historical sales data is represented by s, and s represents the preset multiple. , Characterizes the preset penalty coefficient.
8. The method according to claim 1, characterized in that, The meta-model is trained through the following steps: The sample feature set and sample historical sales data are input into the trained first prediction model and second prediction model for processing to obtain the first sample sales prediction result and the second sample sales prediction result. Based on the sales prediction results of the first sample, the sales prediction results of the second sample, the sample feature set, and the historical sales data of the sample, a fused sample set is constructed. The fused sample set is then input into a pre-constructed meta-model for training to obtain a trained meta-model. The method further includes: The first and second prediction models, which have been trained, are used as base learners. The base learners and the meta-model are then integrated to obtain the sales prediction model.