Regional drug sales prediction method based on graph attention neural network
By building a drug sales infographic and using a graph attention neural network, the problem of insufficient accuracy of traditional Chinese medicine sales forecasts in the existing technology is solved, more accurate drug sales forecasts are achieved, and supply chain efficiency is improved.
Patent Information
- Application Number
- CN202410848155.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2025-01-10
Smart Images

Figure CN119295130A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of drug sales, and specifically relates to a method for predicting regional drug sales based on a graph attention neural network. Background Art
[0002] In order to ensure the normal operation of the drug supply system, it is necessary to minimize inventory and other operating costs while ensuring a continuous and uninterrupted supply of drugs. To achieve this goal, it is necessary to accurately predict the demand for each drug. If the forecast is much higher than the actual demand, it will inevitably lead to a high inventory level, thereby increasing inventory and other operating costs; conversely, if the forecast quantity is too low, it may lead to frequent stock-outs.
[0003] Sales forecasting is to use sales forecasting models based on past sales to obtain predictions of future sales. At present, sales forecasting mostly uses methods based on time series analysis to make predictions. Time series analysis uses past historical data and further speculates future development trends through statistical analysis; its basis is that everything is developing and changing, and the development and change of things are continuous in time. For example, patent application CN111091241A discloses a drug sales forecasting and decision-making method and system based on BP neural network, which obtains drug historical sales data and performs preprocessing and abnormal data inspection; then uses basic BP neural network to predict based on preprocessed drug historical sales data; then corrects the prediction results of basic BP neural network based on drug sales historical data and drug sales prior data, and finally outputs the final prediction results; patent application CN109785003A discloses a drug sales forecasting system and method for drug retail industry, which establishes a triple exponential smoothing prediction model, a gray prediction model, and an LSTM prediction model; then calculates and obtains the results of the three models respectively, and combines the three models to form a BP neural network prediction model; finally, the BP neural network combination prediction model is trained with the three results as input variables to obtain the combined prediction results based on BP neural network. However, the existing method only predicts based on the input historical sales data, and may not capture important features such as the complex associations between drugs, the influence of sales location and time; the existing learning method is still limited in dealing with complex relationships and features in the medical field, and cannot make good use of the potential relationships between drugs and the time dependence between time series. Summary of the invention
[0004] To solve the above technical problems, the present invention provides a regional drug sales prediction method based on a graph attention neural network, constructs a sales information graph related to drugs, and uses a sales prediction method based on a graph structure for the proposed drug information graph structure. The graph attention neural network is used to learn the constructed graph to predict the sales of each drug in each pharmacy, thereby improving the efficiency of the enterprise supply chain.
[0005] The method for predicting regional drug sales based on a graph attention neural network according to the present invention comprises the following steps:
[0006] Step 1: Collect historical drug sales data and pre-process the data;
[0007] Step 2: Based on the preprocessed data, construct the corresponding time and space feature maps;
[0008] Step 3: construct a graph attention neural network model based on the temporal and spatial feature graphs, and train and optimize the graph attention neural network model;
[0009] Step 4: Use the trained graph attention neural network model to predict drug sales and evaluate the prediction results;
[0010] Step 5: Explain the forecast results, analyze the sales trends of different drugs in different regions and time periods, and obtain the main factors affecting sales; and visualize the forecast results.
[0011] Furthermore, in step 1, the historical sales data includes the sales volume, sales time, sales location of different drugs and external factors that may affect sales.
[0012] Furthermore, in step 1, the collected data is preprocessed, specifically: the collected historical sales data is divided into a training set and a test set, the data in the training set is cleaned, and missing values, outliers and duplicate values are processed; and the data in the training set and the test set are normalized, features are extracted, and the initial input of the model after preprocessing is obtained.
[0013]
[0014] Where max(X train ) and min(X train ) are the maximum and minimum values of the training set, respectively. is the initial input at time t after preprocessing, x t is the initial data at time t after data cleaning.
[0015] Furthermore, in step 2, the initial input of the model obtained after preprocessing is Use a sliding window of size n to slide, and each time you slide, select the initial features x of n consecutive time steps. (t) ∈R n×k :
[0016] x (t) :=[s (t-n) ,s (t-n+1) ,···,s (t-1) ]
[0017] Among them, n is the maximum length of the timestamp, k is the number of features; the target output that the model needs to predict is the sensor data at the current time point, that is, s(t), which represents the predicted k feature values.
[0018] Furthermore, based on the initial features x of the n time steps (t) , construct the corresponding time and space feature maps, specifically:
[0019] Consider k different drugs as nodes, and the sales volume of drugs at each time step as features. Construct a spatial feature graph with k nodes and n node feature dimensions, that is, *v1,v2,···,v i ,···v k ,+, where v i , 1≤i≤k is the feature vector of each node;
[0020] Consider n time steps as nodes, and the number of drugs in each time step as features, and construct a time feature graph with n nodes and k node feature dimensions, that is, *v1,v2,···,v i ,···v n ,+, where v i ,1≤i≤n is the feature vector of each node.
[0021] Furthermore, in step 3, the graph attention neural network model includes two parallel GAT layers and GRU layers;
[0022] Based on initial input The constructed temporal and spatial feature maps are input into two parallel graph attention GAT layers for processing, emphasizing the relationship between multiple features and timestamps in the time series;
[0023] Concatenate the outputs of the 1-D convolutional layer and the two GAT layers and feed them into a GRU layer with a hidden dimension of d1 to capture sequential patterns in the time series;
[0024] The output of the GRU layer is fed into the fully connected network to get the final result.
[0025] Furthermore, the output of each node calculated by the GAT layer is expressed as follows:
[0026]
[0027] Among them, h i is the output representation of node i, with the same dimension as input v i The shapes are the same; σ represents the sigmoid activation function; α ij is the attention score that measures the contribution of node j to node i, where j is one of the neighboring nodes of node i; L represents the number of neighboring nodes of node i;
[0028] Note the fraction α ij Calculated by the following formula:
[0029]
[0030]
[0031] Among them, ⊕ represents the concatenation of two node representations, ω∈R 2m is a column vector of learnable parameters, m is the dimension of each node feature vector, and LeakyReLU is a nonlinear activation function.
[0032] The beneficial effects described in the present invention are as follows: the method described in the present invention utilizes the relevant sales information of different drugs to compose a graph, thereby forming a related drug feature graph, thereby enhancing the potential connection between drugs, and facilitating the simultaneous prediction of the sales of multiple drugs at different sales points; a graph attention neural network is used based on the characteristics of the constructed drug information graph to learn the potential relationship between drugs and capture the time dependency in the time series, and the accuracy of drug sales prediction can be effectively improved through a method based on a graph attention network. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 is a flow chart of the method of the present invention;
[0034] Figure 2 It is a graph attention mechanism diagram;
[0035] Figure 3 It is a network architecture diagram. DETAILED DESCRIPTION
[0036] In order to make the contents of the present invention more clearly understood, the present invention is further described in detail below based on specific embodiments in conjunction with the accompanying drawings.
[0037] like Figure 1 As shown, a regional drug sales prediction method based on graph attention neural network includes the following steps:
[0038] Step 1: Collect historical drug sales data and pre-process the data;
[0039] To improve the robustness of the model, data normalization and cleaning are performed on each individual time series; data normalization is applied to both the training and test sets, while cleaning is only applied to the training set.
[0040] 1) Data cleaning: Prediction-based models are very sensitive to irregularities and abnormal instances in the training data. To alleviate this problem, an advanced univariate anomaly detection method, Spectral Residual (SR), is used to detect abnormal timestamps in each individual time series in the training data. Based on this method, the threshold is set to 3 to generate anomaly detection results. Those detected abnormal timestamps will be replaced with normal values around the timestamp. SR is lightweight and adds little overhead to the entire model;
[0041] 2) Data normalization: Use the maximum and minimum values in the training data to normalize the time series, extract features, and obtain the initial input of the preprocessed model.
[0042]
[0043] Where max(X train ) and min(X train ) are the maximum and minimum values of the training set, respectively. is the initial input at time t after preprocessing, x t is the initial data at time t after data cleaning.
[0044] Step 2: Based on the preprocessed data, construct the corresponding time and space feature maps;
[0045] At time t, a sliding window of size n is slid based on the historical time series data (whether training data or test data), and each sliding selects the initial features x of n consecutive time steps (t) ∈R n×k :
[0046] x (t) ∶=,s (t-n) ,s (t-n+1) ,···,s (t-1) -
[0047] The target output that the model needs to predict is the sensor data at the current time point, that is, s(t).
[0048] Based on the initial features x of the n time steps (t) , construct the corresponding time and space feature maps, specifically:
[0049] Consider k different drugs as nodes, and the sales volume of drugs at each time step as features. Construct a spatial feature graph with k nodes and n node feature dimensions, that is, *v1,v2,···,v i ,···v k ,+, where v i , 1≤i≤k is the feature vector of each node;
[0050] Consider n time steps as nodes, and the number of drugs in each time step as features, and construct a time feature graph with n nodes and k node feature dimensions, that is, *v1,v2,···,v i ,···v n ,+, where v i ,1≤i≤n is the feature vector of each node.
[0051] Step 3: Build a graph attention neural network model based on temporal and spatial feature graphs, such as Figure 3 As shown, the graph attention neural network model is trained and optimized;
[0052] The Graph Attention layer is the core design of the proposed sales prediction method. The GAT layer can model the relationship between nodes in any graph. The output of each node calculated by the GAT layer is expressed as follows:
[0053]
[0054] where h i is the output representation of node i, node i and input v i The shapes are the same; σ represents the sigmoid activation function; α ij is the attention score that measures the contribution of node j to node i, where j is one of the neighboring nodes of node i; L represents the number of neighboring nodes of node i.
[0055] Note the fraction α ij It can be calculated by the following formula:
[0056]
[0057]
[0058] Where ⊕ represents the concatenation of two node representations, ω∈R 2m is a column vector of learnable parameters, where m is the dimension of each node feature vector and LeakyReLU is a nonlinear activation function.
[0059] In the multivariate time series drug sales prediction scenario, the present invention utilizes two types of graph attention layers, namely, a graph attention layer oriented to spatial features and a graph attention layer oriented to temporal features.
[0060] 1) Graph attention layer for spatial features: The present invention needs to detect multivariate correlations without any prior knowledge. Therefore, the multivariate time series is considered as a complete graph, where each node represents a feature and each edge represents the relationship between two corresponding features. In this way, the relationship between adjacent nodes can be carefully captured by the graph attention operation. Specifically, for each node x i The features are represented by a sequential vector x i ={x i,t |t∈,0,n)} means that there are k nodes in total, where n is the total number of timestamps and k is the total number of multivariate features. Figure 2 shown.
[0061] 2) Time-oriented graph attention layer: This paper uses the power of graph attention network to capture the temporal dependencies in time series. By considering all timestamps in the sliding window as a complete graph, specifically, the node x t Represents the feature vector of timestamp t, whose neighbors include all other timestamps in the current sliding window.
[0062] The output of the spatial feature-oriented graph attention layer is a matrix of shape k×n, where each row is an n-dimensional vector, representing the output of each node, with a total of k nodes; similarly, the output of the temporal graph attention layer has an n×k shape. Concatenated into a matrix of shape n×3k, where each row represents a 3k-dimensional feature vector for each timestamp to fuse information from different sources.
[0063] Step 4: Use the trained graph attention neural network model to predict drug sales and evaluate the prediction results;
[0064] The present invention uses a prediction model to predict the value of the next timestamp. During the training process, the loss function for sales forecast optimization is defined as Loss for Three fully connected layers with hidden dimension d2 are stacked after the GRU layer as the prediction model. The loss function can be expressed as the root mean square error (RMSE):
[0065]
[0066] where x n Indicates that the current input x = (x0, x1, ···, x n-1 ); x n,i Indicates that in x n The value of the i-th feature in ; is the value predicted by the model based on the prediction.
[0067] Using Loss during training for To train the prediction network, use the network output in actual application As the predicted value of each characteristic information of each drug.
[0068] Step 5: Explain the forecast results, analyze the sales trends of different drugs in different regions and time periods, and obtain the main factors affecting sales; and visualize the forecast results.
[0069] The method of the present invention is described below by taking Pharmaceutical Company A as an example.
[0070] Assume that pharmaceutical company A wants to build a method for predicting the sales of multiple drugs in a region based on a graph attention neural network to predict the sales of drugs in the next time period and further optimize the warehousing and marketing of drugs. According to the needs of pharmaceutical company A, building a method for predicting the sales of multiple drugs in a region based on a graph attention neural network requires a series of implementation steps, as follows:
[0071] Step 1: Data collection and preparation
[0072] 1) Collect data: Collect the past sales data of Pharmaceutical Company A, including information such as sales volume, sales time, sales location, etc. of different drugs, as well as external factors that may affect sales such as seasonality, holidays, etc.
[0073] 2) Data preprocessing: Clean and organize the collected data, deal with missing values, outliers, and duplicate values. Segment the sales time series, such as by month or quarter, to facilitate time series analysis.
[0074] Step 2: Build graph data representation
[0075] 1) Construct a drug association graph: Different drugs are regarded as nodes in the graph, and the characteristics of drug nodes are constructed based on information such as sales location and time. The relationship between drugs is an edge. The constructed graph relationship is stored by establishing an adjacency matrix, where the elements of the matrix represent the edges between drugs.
[0076] 2) Introducing spatial and temporal information: Introducing spatial information (sales location) and temporal information on the nodes in the graph can be represented by the attributes of the nodes. This helps the model better capture sales patterns in different regions and time periods.
[0077] Step 3: Graph Attention Neural Network Modeling
[0078] 1) Apply one-dimensional convolution with kernel size 7 in the first layer to extract high-level features of each time series input. The convolution operation performs well in local feature engineering within the sliding window;
[0079] 2) The output of the 1-D convolutional layer is processed by two parallel graph attention layers to emphasize the relationship between multiple features and timestamps in the time series;
[0080] 3) Concatenate the outputs of the 1-D convolutional layer and the two GAT layers and input them into a Gated Recurrent Unit (GRU) layer with a hidden dimension of d1. This layer is used to capture sequential patterns in time series;
[0081] 4) Feed the output of the GRU layer into the fully connected network to get the final result.
[0082] Step 4: Sales forecast model training and optimization
[0083] 1) Data partitioning: Divide the data set into training set, validation set and test set in chronological order to ensure the model's predictive ability in the future time period;
[0084] 2) Model training: Use the training set to train the model and optimize the model parameters by minimizing the loss function between the predicted value and the actual sales value, namely the root mean square error (RMSE);
[0085] 3) Hyperparameter adjustment: Evaluate model performance on the validation set and adjust the model’s hyperparameters, such as the number of hidden units, to optimize the model’s generalization ability.
[0086] Step 5: Prediction and evaluation
[0087] 1) Forecast generation: Use the trained model to make sales forecasts on the data in the test set to obtain the sales forecast value of each drug in the next time period;
[0088] 2) Evaluation indicators: The root mean square error (RMSE) is used to measure the gap between the predicted results and the actual sales value.
[0089] Step 6: Model deployment and monitoring
[0090] 1) Model deployment: After the prediction performance reaches an acceptable level, the model is deployed to the actual application environment, which can be an online system or a batch task;
[0091] 2) Continuous Monitoring: Continuously monitor the performance of the model and regularly update the model parameters to respond to possible changes in drug sales patterns.
[0092] Step 7: Result interpretation and visualization
[0093] 1) Result interpretation: Explain the prediction results of the model, analyze the sales trends of different drugs in different regions and time periods, and find out the main factors affecting sales;
[0094] 2) Visualization: Use visualization tools to present forecast results in the form of charts, heat maps, etc. to help business personnel better understand sales trends and forecast changes.
[0095] Through the above implementation steps, Pharmaceutical Company A can build a method for predicting the sales of multiple drugs in a region based on a graph attention neural network, thereby more accurately predicting the sales volume of each drug in the next time period, providing strong support for the company's sales strategy and inventory management. It should be noted that during the implementation process, flexible adjustments need to be made according to specific circumstances to ensure that the model can adapt to different business scenarios and data characteristics.
[0096] The above description is only a preferred embodiment of the present invention and is not intended to be a further limitation of the present invention. All equivalent changes made using the contents of the present specification and drawings are within the protection scope of the present invention.
Claims
1. A regional drug sales prediction method based on graph attention neural network, characterized in that: The following steps are involved: Step 1: Collect historical drug sales data and pre-process the data; Step 2: Based on the preprocessed data, construct the corresponding time and space feature maps; Step 3: construct a graph attention neural network model based on the temporal and spatial feature graphs, and train and optimize the graph attention neural network model; Step 4: Use the trained graph attention neural network model to predict drug sales and evaluate the prediction results; Step 5: Explain the forecast results, analyze the sales trends of different drugs in different regions and time periods, and obtain the main factors affecting sales; and visualize the forecast results.
2. According to claim 1, a method for predicting regional drug sales based on graph attention neural network is characterized in that: In step 1, the historical sales data includes the sales volume, sales time, sales location of different drugs and external factors that may affect sales.
3. According to claim 2, a method for predicting regional drug sales based on graph attention neural network is characterized in that: In step 1, the collected data is preprocessed, specifically: the collected historical sales data is divided into a training set and a test set, the data in the training set is cleaned, and missing values, outliers and duplicate values are processed; and the data in the training set and the test set are normalized, and features are extracted to obtain the initial input of the preprocessed model. Where max(X train ) and min(X train ) are the maximum and minimum values of the training set, respectively. is the initial input at time t after preprocessing, x t is the initial data at time t after data cleaning.
4. According to claim 1, a method for predicting regional drug sales based on graph attention neural network is characterized in that: In step 2, the initial input of the model obtained after preprocessing is Use a sliding window of size n to slide, and each time you slide, select the initial features x of n consecutive time steps. (t) ∈R n×k : x (t) :=[s (t-n) ,s (t-n+1) ,···,s (t-1) ] Among them, n is the maximum length of the timestamp, k is the number of features; the target output that the model needs to predict is the sensor data at the current time point, that is, s(t), which represents the predicted k feature values.
5. According to claim 4, a method for predicting regional drug sales based on graph attention neural network is characterized in that: Based on the initial features x of the n time steps (t) , construct the corresponding time and space feature maps, specifically: Consider k different drugs as nodes, and the sales volume of drugs at each time step as features. Construct a spatial feature graph with k nodes and n node feature dimensions, that is, *v1,v2,···,v i ,···v k ,+, where v i , 1≤i≤k is the feature vector of each node; Consider n time steps as nodes, and the number of drugs in each time step as features, and construct a time feature graph with n nodes and k node feature dimensions, that is, *v1,v2,···,v i ,···v n ,+, where v i ,1≤i≤n is the feature vector of each node.
6. According to claim 5, a method for predicting regional drug sales based on graph attention neural network is characterized in that: In step 3, the graph attention neural network model includes two parallel GAT layers and GRU layers; Based on initial input The constructed temporal and spatial feature maps are input into two parallel graph attention GAT layers for processing, emphasizing the relationship between multiple features and timestamps in the time series; Concatenate the outputs of the 1-D convolutional layer and the two GAT layers and feed them into a GRU layer with a hidden dimension of d1 to capture sequential patterns in the time series; The output of the GRU layer is fed into the fully connected network to get the final result.
7. The method for predicting regional drug sales based on graph attention neural network according to claim 6 is characterized in that: The output of each node calculated by the GAT layer is expressed as follows: Among them, h i is the output representation of node i, with the same dimension as input v i The shapes are the same; σ represents the sigmoid activation function; α ij is the attention score that measures the contribution of node j to node i, where j is one of the neighboring nodes of node i; L represents the number of neighboring nodes of node i; Note the fraction α ij Calculated by the following formula: Among them, ⊕ represents the concatenation of two node representations, ω∈R 2m is a column vector of learnable parameters, m is the dimension of each node feature vector, and LeakyReLU is a nonlinear activation function.
Citation Information
Patent Citations
Drug retail industry drug sales prediction system and method
CN109785003A
BP neural network-based drug sales prediction and decision-making method and system
CN111091241A