Method and system for predicting sales volume of multiple retail stores based on improved Transform architecture
By improving the Transformer architecture and deep learning algorithm, combining the multi-level attention mechanism and dynamic features fusion, the dynamic relationship and long-term series problems in multi-store sales forecasting are solved, and more accurate sales forecasting and operation optimization are achieved.
Patent Information
- Application Number
- CN202510100999.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-08-29
AI Technical Summary
The existing technology cannot effectively capture the dynamic and complex relationships between stores, the multi-dimensional feature fusion capability is insufficient, and it is difficult to handle the long-term series characteristics of retail sales data, resulting in low sales prediction accuracy in multi-stores.
Adopting an improved Transformer architecture, combining deep learning algorithms and dynamic feature fusion technology, we use a multi-level attention mechanism to capture the mutual relationship and timing dependence between stores and products, integrate external environment variables, and build a multi-retail store sales forecast model.
It improves the accuracy and comprehensiveness of sales forecasts, optimizes resource allocation and collaborative management, reduces inventory costs and human judgment errors, and improves the operational efficiency of retail stores.
Smart Images

Figure CN120563160A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of smart retail and big data analysis technologies, and in particular to a multi-retail store sales forecasting method and system based on an improved Transformer architecture. Background Art
[0002] With the continued development of chain stores and large-scale operations in the retail industry, the need for refined multi-store management is becoming increasingly prominent. This is particularly crucial in sales forecasting and replenishment decision-making. In traditional store operations, sales forecasts and replenishment plans often rely on the experience and judgment of managers, resulting in decision-making quality affected by individual abilities and experience. Under-forecasting can lead to inventory shortages and an inability to meet consumer demand; while over-forecasting can lead to inventory backlogs, wasted resources, and increased operating costs. Furthermore, regional differences between stores, dynamic competitive dynamics, and external environmental factors (such as weather and holidays) further complicate forecasting. Therefore, accurately forecasting sales demand across multiple stores through scientific and intelligent algorithms has become a crucial issue for retail companies in improving operational efficiency and competitiveness.
[0003] One existing technology, patent publication number CN111882278A, discloses a multi-factor sales forecasting system. This system primarily constructs different sales forecasting models based on the store type of fast-moving consumer goods brands. Within the same model, independent models are created based on the split results of three dimensions: store sales channel, member grouping, and product type. However, this method primarily focuses on the extraction and utilization of spatiotemporal features, and its ability to interactively process multidimensional features is relatively weak. This makes it difficult to fully and deeply capture the complex dynamic relationships across stores and products, as well as the hidden information in high-dimensional heterogeneous data. This impacts its forecasting performance in a more complex and volatile retail market environment, particularly in multi-store scenarios. Furthermore, patent publication number CN118982383A identifies product clusters, determines feature sets based on the historical sales figures and attribute information of other products in the cluster, and then predicts the sales of the product to be forecasted, thereby improving the accuracy of sales forecast results. However, this technical solution fails to capture the impact of factors such as weather and holidays on sales. In particular, this patent struggles to capture the dynamic and complex relationships between stores and products, particularly how weather and holidays affect them.
[0004] As can be seen, existing technologies suffer from the following major issues: First, they fail to effectively capture the complex dynamic relationships between stores. In multi-store operations, inter-store competition and synergy have a significant impact on sales forecasting. For example, customer flow between same-brand stores and competition from external brand stores can significantly impact individual store sales performance. However, most existing technologies rely on independent predictions for each store, failing to fully consider the dynamic interdependencies between stores, resulting in a lack of a holistic perspective in forecasting results. Second, they lack the ability to integrate multidimensional features. Retail sales are influenced by a variety of internal and external factors, including complex variables such as weather, holidays, and promotions. Traditional statistical models and some machine learning methods have limited performance when handling high-dimensional, heterogeneous features, making it difficult to exploit the nonlinear relationships and interactions between these factors, thereby reducing forecast accuracy. Third, sales data exhibits strong long-term characteristics, such as seasonal fluctuations and long-term trends. Traditional methods such as ARIMA and support vector machines cannot effectively capture long-term dependencies. While some deep learning models, such as LSTM and GRU, can handle time series, they still face performance bottlenecks when modeling long-term dependencies and integrating features at multiple time scales. Summary of the Invention
[0005] The present invention aims to address the shortcomings of the aforementioned prior art by providing a multi-retail store sales forecasting method and system based on an improved Transformer architecture. This method and system, based on an improved Transformer architecture, combines deep learning algorithms with dynamic feature fusion technology to accurately forecast sales data for multiple stores. Furthermore, through interactive analysis of stores and products and comprehensive modeling of external environmental variables, a more comprehensive and accurate sales forecast is achieved, thereby improving the operational management of multiple stores in the retail industry.
[0006] On the one hand, a multi-retail store sales forecasting method based on an improved Transformer architecture is provided, which includes the following steps: S1: Collect historical retail store sales data, historical weather characteristics, and holiday data, correlate them, and preprocess the collected data, including data structuring, dimensionality reduction aggregation, and data windowing; S2: Using the collected multi-dimensional data as input, a store sales forecasting model is dynamically constructed and trained based on a deep learning neural network. Through a multi-level attention mechanism, the model captures the interrelationships and temporal dependencies between different stores, as well as the mutual influence and synergy between different product clusters. This allows the model to obtain gated store-level features and product cluster features that have a significant impact on sales forecasting. S3: Fusing external covariates with the gated store-level features and the product cluster features to enhance the model's predictive capabilities, and predicting sales of multiple retail stores based on the trained store sales prediction model.
[0007] Furthermore, in step S1, the collecting and correlating historical retail store sales data, historical weather characteristics, and holiday data includes: Collect retail store sales data, each data item includes: order time, store ID, product ID and order quantity; Obtain historical weather characteristic data based on the time range of sales records, including three dimensions: maximum temperature, minimum temperature, and wind speed; Get holiday data, including holiday identifier and week number. Integrate sales data with external influencing factors, including historical weather characteristics and holiday data, and construct feature engineering for subsequent analysis and model training by correlating different types of data to form a complete data set.
[0008] Preferably, in step S1, the data is structured to represent the collected multi-source heterogeneous data as a unified tensor for batch reading and processing during model training and prediction, specifically including: Initialize a tensor with all 0s ,in, represents the total number of days in the sales data, Represents the number of all stores in the sales data, Indicates the number of products in the sales data, according to the collected sales data Fill in data; Initialize an all-0 matrix ,in, Represents the weather feature dimension, according to the collected weather feature data Fill in data; Initialize an all-0 matrix ,in, Indicates the holiday feature dimension, according to the collected holiday data Fill in the data.
[0009] More preferably, in step S1, the dimensionality reduction aggregation is to reduce the dimensional space of the product data and group and aggregate products that are similar or have similar sales, specifically including: right Sum and sort on the time dimension and store dimension to get each product The total sales volume is expressed as follows: ; Assign the first a product IDs to independent groups and number them sequentially starting from 0, and assign the product IDs of a+1 to The IDs of the products are ranked by the folding factor Assigned to separate groups, where represents the initial folding factor, represents the cumulative folding factor; Finally, we get a dictionary whose key is product ID and value is group ID. Map the dictionary to In the new tensor ,in, The number of new product groups.
[0010] In addition, in step S1, the data windowing is to divide the data into samples according to the time window, which specifically includes: Set the sliding window width to , and through the sliding window , , Divide the samples separately to obtain the data set It is expressed as follows: , in, Indicates the The samples input into the model in time windows.
[0011] Furthermore, in step S2, the store sales prediction model is composed of several layers, each of which includes a gated store-level Transformer module, a product cluster Transformer module, and a covariate fusion module, which respectively perform gated store-level attention, product cluster attention, and covariate fusion calculations. Constructing and training the store sales prediction model specifically includes: S21: Define the current number of iterations as epoch, initialize epoch=1, and define the iteration threshold as , while initializing the parameters in the neural network; S22: Input samples into the store sales prediction model ,Will Input into the gated store level Transformer module to obtain gated store level features , the gated store level features Input the product cluster Transformer module to obtain product cluster features , then cluster the product features Weather characteristics and holiday characteristics Input into the covariate fusion module to perform fusion calculation and obtain the prediction result ; S23: Traverse all modules in the store sales prediction model, accumulate the output of each module, and obtain the final prediction result, which is expressed as: in, Represents each layer of the store sales forecasting model; S24: Use the mean square error (MSE) as the loss function, use the gradient descent algorithm to train the store sales prediction model, and minimize the loss function as the goal, and optimize and update the parameters in the model through the time back propagation algorithm until the number of iterations is The training is stopped until the trained store sales prediction model is obtained, which is used to predict the sales of stores in the future time period. Among them, the loss function It is expressed as follows: in, is the sample size, i.e. the number of stores, Indicates the Stores in The actual demand value at the moment, Indicates the stores in The predicted demand value at the time.
[0012] Furthermore, in step S2, capturing the mutual relationships and temporal dependencies between different stores, and the mutual influence and synergy between different product clusters through the multi-level attention mechanism further includes: S100: The gated store-level Transformer module uses an improved self-attention mechanism to measure the importance of different stores to the current store sales forecast by calculating the attention weights between each store, identifying and emphasizing the most critical store features for sales forecasting, thereby improving the accuracy of the forecast; S200: The product cluster Transformer module uses a multi-head self-attention mechanism to evaluate the correlation and influence between product clusters, reflects the importance of different product clusters to the sales forecast of the current product cluster through attention scores, and identifies and strengthens product cluster features that have an important impact on sales forecasts.
[0013] Preferably, in step S100, the step of calculating the attention weights between stores to measure the importance of different stores to the current store sales forecast further includes: S101: Time series data , changing its dimension to , calculate the query matrix of store dimension , key matrix Sum Matrix , the calculation formula is as follows: , , , in, , and Both are learnable parameter matrices, input store dimension query matrix and bond matrix Get store attention energy , and then Input into the Softmax activation function to query and calculate the attention score between stores, , the calculation formula is as follows: , , in, Represents the store query vector The dimension of , and then the gating mechanism is used to control the flow of information, which is expressed as follows: , , in, represents the gating matrix, represents the activation function, represents the store attention output under the gating mechanism; S102: Residual connections are used to retain the original feature information to prevent information from being gradually lost in the multi-layer network. Perform residual connection and layer normalization, as shown below: , in, Represents the store dimension time series characteristics after residual link and normalization; S103: Gating store-level features through feedforward neural networks Perform nonlinear transformation to further extract and combine feature information. The formula is as follows: , , in, and Represents the weight matrix in the feedforward neural network, specifically used for gated store-level feature conversion, Dropout represents regularization to prevent overfitting, and the ReLU activation function introduces nonlinearity. and Respectively represent the bias after the first and second linear changes, Representation layer normalization, Represents the final output features.
[0014] More preferably, in step S200, reflecting the importance of different product clusters to the sales forecast of the current product cluster through attention scores further includes: S201: Time series data The shape changes to , calculate the query matrix of product dimension , key matrix Sum Matrix , the calculation formula is as follows: , , , in, , and All are learnable parameter matrices, and then enter the query matrix of the product dimension and bond matrix Get product attention energy , and then Input to the Softmax activation function to query and calculate the attention score between products, , the calculation formula is as follows: , , in, Represents the product query vector Dimension, and then calculate the attention output under the product dimension mechanism , the calculation formula is as follows: ; S202: Residual connections are used to retain original feature information, preventing information from being gradually lost in multi-layer networks and promoting effective gradient propagation. Normalization is then used to speed up training. The representation of residual connections and normalization is as follows: , in, Represents the product dimension time series characteristics obtained after residual linking and normalization; S203: Gating store-level features through feedforward neural networks Perform nonlinear transformation to further extract and combine feature information. The formula is as follows: , , in, and Represents the weight matrix in the feedforward neural network, which is specifically used for feature conversion at the product dimension level. Dropout represents regularization to prevent overfitting, and the ReLU activation function introduces nonlinearity. and Respectively represent the bias after the first and second linear changes, Representation layer normalization, Represents the final output features.
[0015] Furthermore, in step S3, fusing the external covariates with the gated store-level features and the product cluster features further includes: S31: Extract the prediction features output by the gated store level Transformer module and the product cluster Transformer module Weather characteristics and holiday characteristics Perform splicing to obtain the spliced features , expressed as: , ; S32: The concatenated high-dimensional features are processed through the fully connected layer and activation function To process, first linear transformation and activation are performed to concatenate the high-dimensional features Mapped to a new feature space, the first linear transformation feature is obtained , capturing the linear relationship between features, expressed as: , and then the features after the first transformation The input undergoes a second linear transformation and activation to obtain the second linear transformation feature , expressed as: ,in, represents the activation function, and represents the learnable parameter matrix, and represents a linearly varying bias; S33: Utilizing covariate features The forecast results are adjusted as follows: , in, represents the Sigmoid function, is part of the covariate characteristics, represents element-wise multiplication, express Layer prediction module in The forecast value of future demand at any time On the other hand, a multi-retail store sales forecasting system based on an improved Transformer architecture is provided, including: The data collection and preprocessing module is used to collect and correlate historical retail store sales data, historical weather characteristics, and holiday data, and preprocess the collected data, including data structuring, dimensionality reduction aggregation, and data windowing; The model building and feature capture module uses the collected multi-dimensional data as input to dynamically build and train a store sales forecasting model based on a deep learning neural network. Through a multi-level attention mechanism, it captures the interrelationships and temporal dependencies between different stores, as well as the mutual influence and synergy between different product clusters. This module obtains gated store-level features and product cluster features that have a significant impact on sales forecasting. The feature fusion and prediction module is used to fuse external covariates with the gated store-level features and the product cluster features to enhance the model's predictive ability and predict sales of multiple retail stores based on the trained store sales prediction model.
[0016] Compared with the prior art, the present invention has the following beneficial effects: By combining intelligent forecasting capabilities with historical sales data, weather, holidays, and other multi-dimensional heterogeneous factors, this invention can effectively improve the accuracy and comprehensiveness of forecasts, avoid stockouts caused by insufficient sales forecasts, and reduce the risk of inventory backlogs caused by excessive forecasts, thereby reducing inventory costs and overall operating costs. This invention uses an improved multi-layer attention mechanism to construct a complex interaction model between stores and products, which can more accurately capture these influencing factors, thereby optimizing store resource allocation and collaborative management. This paper constructs a unified feature fusion framework to comprehensively model multi-dimensional heterogeneous data (such as store characteristics, product characteristics, and external environment characteristics), effectively improving sales forecast accuracy. Furthermore, the forecast model has strong generalization capabilities and can be applied to operational scenarios in different regions and stores. Through the intelligent sales forecasting system, the present invention enables retail store managers to quickly and accurately complete sales forecasts and operational decisions even if they lack professional forecasting experience, greatly improving the store's operational efficiency and reducing errors in human judgment. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings: Figure 1 This is a flow chart of a multi-retail store sales forecasting method based on an improved Transformer architecture in the present invention; Figure 2 This is a schematic diagram of the structure of a store sales prediction model of the present invention; Figure 3 This is a schematic diagram of the structure of each prediction module in a store sales prediction model of the present invention; Figure 4 This is a flow chart of the data set training, testing and evaluation of the store sales forecasting model of the present invention. DETAILED DESCRIPTION
[0018] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0019] The present invention designs a unified feature fusion framework that dynamically integrates multi-dimensional features such as historical sales data, weather, and holidays, thereby fully exploring the key variables that affect sales and their nonlinear relationships to improve the model's prediction accuracy. At the same time, through improved feature learning and Transformer module mechanisms, the model of the present invention can be applied to scenarios in different regions and different stores, has strong generalization capabilities, and provides retail companies with flexible deployment and application solutions. In addition, a dynamic adjustment mechanism based on prediction is adopted to dynamically optimize the prediction results according to the real-time data and historical data of stores and products, ensuring the scientificity and rationality of replenishment plans and operation strategies.
[0020] The specific implementation of the present invention is described below with reference to the accompanying drawings and embodiments.
[0021] Example 1 See also Figure 1 , which is a multi-retail store sales forecasting method based on an improved Transformer architecture provided in this embodiment. The technical solution includes the following steps: S1: Collect historical retail store sales data, historical weather characteristics, and holiday data, correlate them, and preprocess the collected data, including data structuring, dimensionality reduction aggregation, and data windowing; S2: Using the collected multi-dimensional data as input, a store sales forecasting model is dynamically constructed and trained based on a deep learning neural network. Through a multi-level attention mechanism, the model captures the interrelationships and temporal dependencies between different stores, as well as the mutual influence and synergy between different product clusters. This allows the model to obtain gated store-level features and product cluster features that have a significant impact on sales forecasting. S3: Fusing external covariates with the gated store-level features and the product cluster features to enhance the model's predictive capabilities, and predicting sales of multiple retail stores based on the trained store sales prediction model.
[0022] Wherein, in step S1, the collecting of historical retail store sales data, historical weather characteristics and holiday data and correlating them further includes: Collect retail store sales data, each data item includes: order time, store ID, product ID and order quantity; Obtain historical weather characteristic data based on the time range of sales records, including three dimensions: maximum temperature, minimum temperature, and wind speed; Get holiday data, including holiday identifier and week number. Integrate core business data sales data with external influencing factor data, including historical weather characteristics and holiday data. By correlating different types of data, construct feature engineering for subsequent analysis and model training to form a complete data set, providing sufficient feature support for subsequent data analysis and model training.
[0023] The collected data is then preprocessed, where the data is structured to represent the collected multi-source heterogeneous data as a unified tensor for batch reading and processing during model training and prediction. Specifically, the following steps are performed: Initialize a tensor with all 0s ,in, represents the total number of days in the sales data, Represents the number of all stores in the sales data, Indicates the number of products in the sales data, according to the collected sales data Fill in data, such as sales data in time , store ,product The sales volume is , then it is recorded as ; Initialize an all-0 matrix ,in, Represents the weather feature dimension, according to the collected weather feature data Fill in data, such as weather data at time , the maximum temperature, minimum temperature, and wind speed are , , ,but ; Initialize an all-0 matrix ,in, Indicates the holiday feature dimension, according to the collected holiday data Fill in data, such as holiday characteristic weather data at time The two dimensions of whether it is a holiday and the day of the week are , ,but .
[0024] The dimensionality reduction aggregation is to reduce the dimensional space of product data and group and aggregate products with similar or close sales volume, specifically including: right Sum and sort on the time dimension and store dimension to get each product The total sales volume is expressed as follows: ; Assign the first a product IDs to independent groups and number them sequentially starting from 0, and assign the product IDs of a+1 to The IDs of the products are ranked by the folding factor Assigned to separate groups, where represents the initial folding factor, represents the cumulative folding factor; Finally, we get a dictionary whose key is product ID and value is group ID. Map the dictionary to In the new tensor ,in, The number of new product groups.
[0025] The data windowing is to divide the data into samples according to the time window, which specifically includes: Set the sliding window width to , and through the sliding window , , Divide the samples separately to obtain the data set It is expressed as follows: , in, Indicates the The samples input into the model in time windows.
[0026] In step S2, the store sales forecast model consists of several layers, such as Figure 2As shown, each layer consists of a gated store-level Transformer module, a product cluster Transformer module, and a covariate fusion module, which perform gated store-level attention, product cluster attention, and covariate fusion computations, respectively. The gated store-level Transformer module primarily captures and models the interrelationships and temporal dependencies between stores. Through an improved self-attention mechanism, this module identifies and emphasizes the most critical store features for sales forecasting, thereby improving forecast accuracy. The product cluster Transformer module aims to capture the mutual influence and synergy between different product clusters. Through a multi-head self-attention mechanism, this module identifies and enhances product cluster features that have a significant impact on sales forecasting. The covariate fusion module is responsible for fusing external covariates (such as weather and holiday characteristics) with store-level and product cluster-level features to enhance the model's predictive capabilities. This module integrates and learns from multiple sources of information using a multi-layer perceptron (MLP) or other fusion methods.
[0027] Specifically, building and training the store sales prediction model includes: S21: Define the current number of iterations as epoch, initialize epoch=1, and define the iteration threshold as , while initializing the parameters in the neural network; S22: Input samples into the store sales prediction model ,Will Input into the gated store level Transformer module to obtain gated store level features , the gated store level features Input the product cluster Transformer module to obtain product cluster features , then cluster the product features Weather characteristics and holiday characteristics Input into the covariate fusion module to perform fusion calculation and obtain the prediction result ; S23: Traverse all modules in the store sales prediction model, accumulate the output of each module, and obtain the final prediction result, which is expressed as: in, Represents each layer of the store sales forecasting model; S24: Use the mean square error (MSE) as the loss function, use the gradient descent algorithm to train the store sales prediction model, and minimize the loss function as the goal, and optimize and update the parameters in the model through the time back propagation algorithm until the number of iterations is The training is stopped until the trained store sales prediction model is obtained, which is used to predict the sales of stores in the future time period. Among them, the loss function It is expressed as follows: in, is the sample size, i.e. the number of stores, Indicates the Stores in The actual demand value at the moment, Indicates the stores in The predicted demand value at the time.
[0028] In step S2, the multi-level attention mechanism is used to capture the mutual relationships and temporal dependencies between different stores, and the mutual influence and synergy between different product clusters, further including: S100: The gated store-level Transformer module uses an improved self-attention mechanism to measure the importance of different stores to the current store sales forecast by calculating the attention weights between each store, identifying and emphasizing the most critical store features for sales forecasting, thereby improving the accuracy of the forecast; S200: The product cluster Transformer module uses a multi-head self-attention mechanism to evaluate the correlation and influence between product clusters, reflects the importance of different product clusters to the sales forecast of the current product cluster through attention scores, and identifies and strengthens product cluster features that have an important impact on sales forecasts.
[0029] In step S100, the step of calculating the attention weights between stores to measure the importance of different stores to the current store sales forecast further includes: S101: Time series data , changing its dimension to , calculate the query matrix of store dimension , key matrix Sum Matrix , the calculation formula is as follows: , , , in, , and Both are learnable parameter matrices, input store dimension query matrix and bond matrix Get store attention energy , and then Input into the Softmax activation function to query and calculate the attention score between stores, , the calculation formula is as follows: , , in, Represents the store query vector The dimension of , and then the gating mechanism is used to control the flow of information, which is expressed as follows: , , in, represents the gating matrix, represents the activation function, represents the store attention output under the gating mechanism; S102: Residual connections are used to retain the original feature information to prevent information from being gradually lost in the multi-layer network. Perform residual connection and layer normalization, as shown below: , in, Represents the store-dimensional time series features after residual link and normalization. Layer normalization helps speed up training, stabilize the model, and improve overall prediction performance. S103: Gating store-level features through feedforward neural networks Perform nonlinear transformation to further extract and combine feature information. The formula is as follows: , , in, and Represents the weight matrix in the feedforward neural network, specifically used for gated store-level feature conversion, Dropout represents regularization to prevent overfitting, and the ReLU activation function introduces nonlinearity. and Respectively represent the bias after the first and second linear changes, Representation layer normalization, Represents the final output features.
[0030] In this example, the Softmax activation function ensures normalized attention scores, making the influence of each store comparable and weighted. Based on the calculated attention scores, the information in the value matrix is weighted and aggregated. A gating mechanism regulates the flow of information, preventing over-reliance on data from certain stores, thereby improving the model's stability and generalization capabilities.
[0031] In addition, in step S200, reflecting the importance of different product clusters to the sales forecast of the current product cluster through attention scores further includes: S201: Time series data The shape changes to , calculate the query matrix of product dimension , key matrix Sum Matrix , the calculation formula is as follows: , , , in, , and All are learnable parameter matrices, and then enter the query matrix of the product dimension and bond matrix Get product attention energy , and then Input to the Softmax activation function to query and calculate the attention score between products, , the calculation formula is as follows: , , in, Represents the product query vector Dimension, and then calculate the attention output under the product dimension mechanism , the calculation formula is as follows: ; S202: Residual connections are used to retain original feature information, prevent information from being gradually lost in multi-layer networks, and promote effective gradient propagation. Normalization is then used to speed up training, stabilize the model, and improve overall prediction performance. The representation of residual connections and normalization is as follows: , in, Represents the product dimension time series characteristics obtained after residual linking and normalization; S203: Gating store-level features through feedforward neural networks Perform nonlinear transformation to further extract and combine feature information. The formula is as follows: , , in, and Represents the weight matrix in the feedforward neural network, which is specifically used for feature conversion at the product dimension level. Dropout represents regularization to prevent overfitting, and the ReLU activation function introduces nonlinearity. and Respectively represent the bias after the first and second linear changes, Representation layer normalization, Represents the final output features.
[0032] In this embodiment, this step helps the model identify the product clusters that have the greatest impact on sales forecasts, thereby improving forecast accuracy.
[0033] In step S3, fusing the external covariates with the gated store-level features and the product cluster features further includes: S31: Extract the prediction features output by the gated store level Transformer module and the product cluster Transformer module Weather characteristics and holiday characteristics Perform splicing to obtain the spliced features , expressed as: , ; S32: The concatenated high-dimensional features are processed through the fully connected layer and activation function To process, first linear transformation and activation are performed to concatenate the high-dimensional features Mapped to a new feature space, the first linear transformation feature is obtained , capturing the linear relationship between features, expressed as: , and then the features after the first transformation The input undergoes a second linear transformation and activation to obtain the second linear transformation feature , expressed as: ,in, represents the activation function, and represents the learnable parameter matrix, and represents a linearly varying bias; S33: Utilizing covariate features The forecast results are adjusted as follows: , in, represents the Sigmoid function, is part of the covariate characteristics, represents element-wise multiplication, express Layer prediction module in The forecast value of future demand at any time.
[0034] In this embodiment, the feature concatenation algorithm combines internal forecast information with external environmental factors, enhancing understanding and capture of sales fluctuations, thereby improving forecast accuracy and robustness. The covariate features processed by the sigmoid function are then element-wise multiplied with the initial forecast results to dynamically adjust the forecast values. This step ensures that the model can flexibly adjust sales forecasts based on changes in exogenous variables (such as weather and holidays), improving forecast accuracy and adaptability.
[0035] In the above content, the collected data is used to conduct forecast analysis through the three forecast modules of the store sales model. Figure 3 shown.
[0036] This embodiment provides a data set for building and training a store sales model process, such as Figure 4 As shown in the figure, the training process of the training samples and the prediction process of the test samples are included. The model is optimized through continuous iterative training and evaluated on the validation set to ensure the effectiveness and accuracy of the model. The specific steps include the following: (1) Split the preprocessed multi-source and multi-dimensional data into training sets, test sets, and experimental sets in proportion; (2) First, input the training set into the model for pre-training, initialize the relevant parameters, set the initial state of the model, divide the training data into small batches for training, extract the current small batch data from the training data, perform forward propagation calculation through the model, and then update the model weights based on the calculated loss, record the loss of each training, and accumulate it. Then check whether the training of all small batches has been completed. If not, continue to return to the "extract batch data" step to train the next batch. If so, calculate the average training loss, and then evaluate the model on the validation set; (3) Preprocess the test set and input the preprocessed test samples into the prediction model, which then outputs the prediction results for shared bicycles.
[0037] On the other hand, this embodiment also discloses a multi-retail store sales forecasting system based on an improved Transformer architecture, including: The data collection and preprocessing module is used to collect and correlate historical retail store sales data, historical weather characteristics, and holiday data, and preprocess the collected data, including data structuring, dimensionality reduction aggregation, and data windowing; The model building and feature capture module uses the collected multi-dimensional data as input to dynamically build and train a store sales forecasting model based on a deep learning neural network. Through a multi-level attention mechanism, it captures the interrelationships and temporal dependencies between different stores, as well as the mutual influence and synergy between different product clusters. This module obtains gated store-level features and product cluster features that have a significant impact on sales forecasting. The feature fusion and prediction module is used to fuse external covariates with the gated store-level features and the product cluster features to enhance the model's predictive ability and predict sales of multiple retail stores based on the trained store sales prediction model.
[0038] Among them, the functional implementation of each module and unit of the multi-retail store sales forecasting system based on the improved Transformer architecture corresponds to the steps in the above-mentioned multi-retail store sales forecasting method based on the improved Transformer architecture embodiment, and its functions and implementation process will not be repeated here one by one.
[0039] Finally, it should be noted that the above description is merely a preferred embodiment of the present invention, and the scope of protection of the present invention is not limited to the above embodiment. All technical solutions based on the principles of the present invention are within the scope of protection of the present invention. It should be noted that improvements and modifications that do not depart from the principles of the present invention, which are apparent to those skilled in the art, should also be considered within the scope of protection of the present invention.
[0040] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A multi-retail store sales forecasting method based on an improved Transformer architecture, characterized by: The steps include: S1: Collect historical retail store sales data, historical weather characteristics, and holiday data, correlate them, and preprocess the collected data, including data structuring, dimensionality reduction aggregation, and data windowing; S2: Using the collected multi-dimensional data as input, a store sales forecasting model is dynamically constructed and trained based on a deep learning neural network. Through a multi-level attention mechanism, the model captures the interrelationships and temporal dependencies between different stores, as well as the mutual influence and synergy between different product clusters. This allows the model to obtain gated store-level features and product cluster features that have a significant impact on sales forecasting. S3: Fusing external covariates with the gated store-level features and the product cluster features to enhance the model's predictive capabilities, and predicting sales of multiple retail stores based on the trained store sales prediction model.
2. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 1 is characterized in that: In step S1, the collecting of historical retail store sales data, historical weather characteristics, and holiday data and correlating them further includes: Collect retail store sales data, each data item includes: order time, store ID, product ID and order quantity; Obtain historical weather characteristic data based on the time range of sales records, including three dimensions: maximum temperature, minimum temperature, and wind speed; Get holiday data, including holiday identifier and week number. Integrate sales data with external influencing factors, including historical weather characteristics and holiday data, and construct feature engineering for subsequent analysis and model training by correlating different types of data to form a complete data set.
3. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 1 is characterized in that: In step S1, the data is structured to represent the collected multi-source heterogeneous data as a unified tensor for batch reading and processing during model training and prediction, specifically including: Initialize a tensor with all 0s ,in, represents the total number of days in the sales data, Represents the number of all stores in the sales data, Indicates the number of products in the sales data, according to the collected sales data Fill in data; Initialize an all-0 matrix ,in, Represents the weather feature dimension, according to the collected weather feature data Fill in data; Initialize an all-0 matrix ,in, Indicates the holiday feature dimension, according to the collected holiday data Fill in the data.
4. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 3 is characterized in that: In step S1, the dimensionality reduction aggregation is to reduce the dimensional space of the product data and group and aggregate similar products or products with similar sales volume, specifically including: right Sum and sort on the time dimension and store dimension to get each product The total sales volume is expressed as follows: ; Assign the first a product IDs to independent groups and number them sequentially starting from 0, and assign the product IDs of a+1 to The IDs of the products are ranked by the folding factor Assigned to separate groups, where represents the initial folding factor, represents the cumulative folding factor; Finally, we get a dictionary whose key is product ID and value is group ID. Map the dictionary to In the new tensor ,in, The number of new product groups.
5. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 4 is characterized in that: In step S1, the data windowing is to divide the data into samples according to the time window, which specifically includes: Set the sliding window width to , and through the sliding window , , Divide the samples separately to obtain the data set It is expressed as follows: , in, Indicates the The samples input into the model in time windows.
6. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 5 is characterized in that: In step S2, the store sales prediction model consists of several layers. Each layer includes a gated store-level Transformer module, a product cluster Transformer module, and a covariate fusion module, which respectively perform gated store-level attention, product cluster attention, and covariate fusion calculations. Constructing and training the store sales prediction model specifically includes: S21: Define the current number of iterations as epoch, initialize epoch=1, and define the iteration threshold as , while initializing the parameters in the neural network; S22: Input samples into the store sales prediction model ,Will Input into the gated store level Transformer module to obtain gated store level features , the gated store level features Input the product cluster Transformer module to obtain product cluster features , then cluster the product features Weather characteristics and holiday characteristics Input into the covariate fusion module to perform fusion calculation and obtain the prediction result ; S23: Traverse all modules in the store sales prediction model, accumulate the output of each module, and obtain the final prediction result, which is expressed as: in, Represents each layer of the store sales forecasting model; S24: Use the mean square error (MSE) as the loss function, use the gradient descent algorithm to train the store sales prediction model, and minimize the loss function as the goal, and optimize and update the parameters in the model through the time back propagation algorithm until the number of iterations is The training is stopped until the trained store sales prediction model is obtained, which is used to predict the sales of stores in the future time period. Among them, the loss function It is expressed as follows: in, is the sample size, i.e. the number of stores, Indicates the Stores in The actual demand value at the moment, Indicates the stores in The predicted demand value at the time.
7. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 6 is characterized in that: In step S2, the multi-level attention mechanism is used to capture the mutual relationships and temporal dependencies between different stores, and the mutual influence and synergy between different product clusters, further including: S100: The gated store-level Transformer module uses an improved self-attention mechanism to measure the importance of different stores to the current store sales forecast by calculating the attention weights between each store, identifying and emphasizing the most critical store features for sales forecasting, thereby improving the accuracy of the forecast; S200: The product cluster Transformer module uses a multi-head self-attention mechanism to evaluate the correlation and influence between product clusters, reflects the importance of different product clusters to the sales forecast of the current product cluster through attention scores, and identifies and strengthens product cluster features that have an important impact on sales forecasts.
8. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 7 is characterized in that: In step S100, the step of calculating the attention weights between stores to measure the importance of different stores to the current store sales forecast further includes: S101: Time series data , changing its dimension to , calculate the query matrix of the store dimension , key matrix Sum Matrix , the calculation formula is as follows: , , , in, , and Both are learnable parameter matrices, input store dimension query matrix and bond matrix Get store attention energy , and then Input into the Softmax activation function to query and calculate the attention score between stores, , the calculation formula is as follows: , , in, Represents the store query vector The dimension of , and then the gating mechanism is used to control the flow of information, which is expressed as follows: , , in, represents the gating matrix, represents the activation function, represents the store attention output under the gating mechanism; S102: Residual connections are used to retain the original feature information to prevent information from being gradually lost in the multi-layer network. Perform residual connection and layer normalization, as shown below: , in, Represents the store dimension time series characteristics after residual link and normalization; S103: Gating store-level features through feedforward neural networks Perform nonlinear transformation to further extract and combine feature information. The formula is as follows: , , in, and Represents the weight matrix in the feedforward neural network, specifically used for gated store-level feature conversion, Dropout represents regularization to prevent overfitting, and the ReLU activation function introduces nonlinearity. and Respectively represent the bias after the first and second linear changes, Representation layer normalization, Represents the final output features.
9. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 8 is characterized in that: In step S200, reflecting the importance of different product clusters to the sales forecast of the current product cluster through attention scores further includes: S201: Time series data The shape changes to , calculate the query matrix of product dimension , key matrix Sum Matrix , the calculation formula is as follows: , , , in, , and All are learnable parameter matrices, and then enter the query matrix of the product dimension and bond matrix Get product attention energy , and then Input to the Softmax activation function to query and calculate the attention score between products, , the calculation formula is as follows: , , in, Represents the product query vector Dimension, and then calculate the attention output under the product dimension mechanism , the calculation formula is as follows: ; S202: Residual connections are used to retain original feature information, preventing information from being gradually lost in multi-layer networks and promoting effective gradient propagation. Normalization is then used to speed up training. The representation of residual connections and normalization is as follows: , in, Represents the product dimension time series characteristics obtained after residual linking and normalization; S203: Gating store-level features through feedforward neural networks Perform nonlinear transformation to further extract and combine feature information. The formula is as follows: , , in, and Represents the weight matrix in the feedforward neural network, which is specifically used for feature conversion at the product dimension level. Dropout represents regularization to prevent overfitting, and the ReLU activation function introduces nonlinearity. and Respectively represent the bias after the first and second linear changes, Representation layer normalization, Represents the final output features.
10. The multi-retail store sales forecasting method based on the improved Transformer architecture according to claim 9 is characterized in that: In step S3, fusing the external covariates with the gated store-level features and the product cluster features further includes: S31: Extract the prediction features output by the gated store level Transformer module and the product cluster Transformer module Weather characteristics and holiday characteristics Perform splicing to obtain the spliced features , expressed as: , ; S32: The concatenated high-dimensional features are processed through the fully connected layer and activation function To process, first linear transformation and activation are performed to concatenate the high-dimensional features Mapped to a new feature space, the first linear transformation feature is obtained , capturing the linear relationship between features, expressed as: , and then the features after the first transformation The input undergoes a second linear transformation and activation to obtain the second linear transformation feature , expressed as: ,in, represents the activation function, and represents the learnable parameter matrix, and represents a linearly varying bias; S33: Utilizing covariate features The forecast results are adjusted as follows: , in, represents the Sigmoid function, is part of the covariate characteristics, represents element-wise multiplication, express Layer prediction module in The forecast value of future demand at any time.
11. A multi-retail store sales forecasting system based on an improved Transformer architecture, characterized by: include: The data collection and preprocessing module is used to collect and correlate historical retail store sales data, historical weather characteristics, and holiday data, and preprocess the collected data, including data structuring, dimensionality reduction aggregation, and data windowing; The model building and feature capture module uses the collected multi-dimensional data as input to dynamically build and train a store sales forecasting model based on a deep learning neural network. Through a multi-level attention mechanism, it captures the interrelationships and temporal dependencies between different stores, as well as the mutual influence and synergy between different product clusters. This module obtains gated store-level features and product cluster features that have a significant impact on sales forecasting. The feature fusion and prediction module is used to fuse external covariates with the gated store-level features and the product cluster features to enhance the model's predictive ability and predict sales of multiple retail stores based on the trained store sales prediction model.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the multi-retail store sales prediction method based on the improved Transformer architecture as described in any one of claims 1 to 10 is implemented.
13. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the multi-retail store sales forecasting method based on the improved Transformer architecture as described in any one of claims 1-10.
Citation Information
Patent Citations
Intelligent replenishment method and system
CN111882278A
Cited By
Retail store goods reporting data processing method and system based on sales prediction model
CN120807030A
Advertisement ROI prediction method and system based on multi-modal data fusion and machine learning
CN121169492A
