A disease prediction method using self-attention mechanism
By introducing a self-attention mechanism into disease prediction methods to perform feature screening on multi-source data, the problem of insufficient differentiation of feature importance in the existing technology is solved, the accuracy of disease prediction and model effect are improved, and auxiliary diagnosis support is provided for medical treatment. .
Patent Information
- Application Number
- CN202210724102.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-23
- Publication Date
- 2024-09-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing disease prediction methods, especially those based on deep learning, cannot effectively distinguish and filter the importance of data features, resulting in limited model prediction effects.
The self-attention mechanism is used to extract and filter features of climate data, hospital visit data and patient examination data. Data analysis is performed through the LSTM network and multi-layer perceptron, and the self-attention mechanism is used to obtain important feature vectors and suppress unimportant or interference. Features to improve the prediction effect of the model.
By comprehensively analyzing climate, hospital and physical examination data, important features are effectively screened out, improving the accuracy of disease prediction and the prediction effect of the model, and providing doctors with auxiliary diagnosis and prevention suggestions.
Smart Images

Figure CN115064276B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data processing technology, and in particular relates to a disease prediction method using a self-attention mechanism. Background Art
[0002] With the development of big data, the prediction algorithms for diseases have also been greatly improved. In some existing methods, a multivariate linear regression decision tree model is used to analyze and predict the patient's condition through meteorological data, but traditional machine learning models such as decision tree models cannot obtain the hidden features of the data and have poor fit to the problem. In addition, a deep spatiotemporal residual network is used to predict diseases, and the model is trained using relevant disease data and a variety of external data. In addition, a deep neural network is used to predict and analyze stroke diseases, in which only the patient's disease data is used for analysis.
[0003] Among the prediction methods that combine the medical and health fields with the machine learning fields, they can be roughly divided into prediction methods based on traditional machine learning and prediction methods based on deep learning. The decision tree method used belongs to the traditional machine learning method. This method is mostly based on statistical analysis and information entropy calculation, and has poor fit for nonlinear problems. The disease prediction method based on deep learning uses deep neural networks to extract features from data, analyze hidden information in the data, and re-characterize the data. Although deep neural networks can effectively extract features from input data, it is impossible to know whether these features are effective, or only some features may be more important, some features are not important, and even interfere with the prediction effect of the model. The existing method can only complete the feature extraction of data, and cannot effectively distinguish and screen the importance of features. Summary of the invention
[0004] In order to solve the above problems, the present invention proposes a disease prediction method using a self-attention mechanism, which extracts features of climate data of a certain area, hospital visit data and patient test data through a deep neural network, and uses the self-attention mechanism to screen these features, further extract important features, suppress or eliminate unimportant features or even interfering features, and improve the prediction effect of the model.
[0005] To achieve the above object, the technical solution adopted by the present invention is: a disease prediction method using a self-attention mechanism, constructing a disease prediction model based on the attention mechanism, comprising the steps of:
[0006] S10, inputting the climate data of a time period into the first LSTM network for data analysis and feature extraction to obtain a feature vector h1;
[0007] S20, inputting the hospital visit data in the same time period into the second LSTM network for data analysis and feature extraction to obtain a feature vector h2;
[0008] S30, concatenate the patient's physical examination data with the feature vectors h1 and h2, input them into the MLP multi-layer perceptron, analyze the multi-source data, and extract the feature vector h MLP ;
[0009] S40, using the improved self-attention mechanism, the feature vector h MLP Perform feature screening to obtain the more important feature vector h Att ;
[0010] S50, h Att Input into a fully connected layer network FC to obtain the final prediction result.
[0011] Furthermore, a data set is constructed as input data for a disease prediction model. Each piece of input data of the disease prediction model includes the physical examination data of a patient's visit to the hospital, as well as the climate data of the t days before the visit and the hospital data of the t days before the visit. The label of the data is the disease diagnosed by the hospital.
[0012] Furthermore, a data set is constructed, which includes climate data, hospital visit data, and patient physical examination data;
[0013] Define a climate data set D1, which contains the climate data of a region or city within a period of T days. That is, D1 contains data for T days. The climate data for each day includes temperature, humidity, air quality, and wind speed data.
[0014] Define the hospital dataset D2, which contains data from one or more hospitals in the same region or city within T days. That is, D2 contains data from T days. The hospital data for each day includes the number of patients with a certain disease and the sales volume of drugs related to the disease.
[0015] Define the physical examination data set D3, which contains the data of the patient's physical examination, including the patient's age, height, weight and other biochemical test data.
[0016] Furthermore, the first LSTM network and the second LSTM network have the same structure, including a forget gate, an input gate, an output gate, and a cell state.
[0017] Furthermore, the patient's physical examination data is concatenated with the feature vectors h1 and h2 to obtain a new feature vector h in ,formula:
[0018] h in =contact[x in ,h1,h2];
[0019] Among them, x in This is the patient's physical examination data.
[0020] Furthermore, the new feature vector h in Input into the multi-layer perceptron to get the output result h MLP ;
[0021] The multilayer perceptron contains l layers, and the i-th layer has n i neurons, l and n i is a hyperparameter; since the output layer of the multilayer perceptron has n l neurons, so h MLP The dimension is n l ×1.
[0022] Furthermore, using the self-attention mechanism method, the feature vector h MLP Perform feature screening to obtain the more important feature vector h Att , including the steps of:
[0023] Define three matrices W according to the required standards Q , W K and W V , whose dimension is n l ×n l ;
[0024] Three new vectors are obtained by the following calculations:
[0025] h Q =W Q ·h MLP ;
[0026] h K =W K ·h MLP ;
[0027] h V =W V ·h MLP ;
[0028] The obtained h Q and h K Calculate and get a new feature matrix M, the calculation method is:
[0029]
[0030] Among them, R(·) is the transposition operation. The characteristic matrix M can be obtained by calculation, and its dimension is n l ×n l ;
[0031] Finally, the characteristic matrix M and the characteristic vector h V Calculate the new eigenvector h Att , the calculation method is:
[0032] h Att =Mh V ;
[0033] The final feature vector h Att After inputting into a fully connected layer, the output is calculated by Softmax. The calculation method is:
[0034]
[0035] Represents the model output, W fc and b fc is the parameter matrix and bias of a fully connected layer.
[0036] Furthermore, when training the model, the root mean square error function is used as the loss function, and the formula is:
[0037]
[0038] Among them, D train Represents the training dataset.
[0039] The beneficial effects of adopting this technical solution are:
[0040] The present invention conducts a comprehensive analysis of climate data, hospital visit data, and the patient's personal physical examination data, not only taking their personal health conditions into consideration, but also incorporating multiple external factors into the reference range, to conduct a predictive analysis of the patient's illness, provide auxiliary diagnosis for doctors, and actively guide patients to take prevention or treatment.
[0041] The present invention proposes to use a self-attention mechanism in the model to further screen the feature vector, extract important feature information, suppress unimportant features, complete the re-characterization of the feature vector, and improve the prediction effect of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A flowchart of a disease prediction method using a self-attention mechanism of the present invention;
[0043] Figure 2 is a schematic diagram of a disease prediction model based on an attention mechanism in an embodiment of the present invention;
[0044] Figure 3 This is a schematic diagram of an LSTM unit in an embodiment of the present invention;
[0045] Figure 4Schematic diagram of the self-attention mechanism in an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described below with reference to the accompanying drawings.
[0047] In this embodiment, see Figure 1 and Figure 2 As shown, the present invention proposes a disease prediction method using a self-attention mechanism, comprising the steps of:
[0048] S10, inputting the climate data of a time period into the first LSTM network for data analysis and feature extraction to obtain a feature vector h1;
[0049] S20, inputting the hospital visit data in the same time period into the second LSTM network for data analysis and feature extraction to obtain a feature vector h2;
[0050] S30, concatenate the patient's physical examination data with the feature vectors h1 and h2, input them into the MLP multi-layer perceptron, analyze the multi-source data, and extract the feature vector h MLP ;
[0051] S40, using the improved self-attention mechanism, the feature vector h MLP Perform feature screening to obtain the more important feature vector h Att ;
[0052] S50, h Att Input into a fully connected layer network FC to obtain the final prediction result.
[0053] Construct a data set as the input data of the disease prediction model. Each input data of the disease prediction model includes the physical examination data of a patient's visit, as well as the climate data of the t days before the visit and the hospital data of the t days before the visit. The label of this data is the disease diagnosed by the hospital.
[0054] Specifically, the dataset contains climate data, hospital visit data, and patients’ physical examination data;
[0055] Define a climate data set D1, which contains the climate data of a region or city within a period of T days. That is, D1 contains data for T days. The climate data for each day includes temperature, humidity, air quality, and wind speed data.
[0056] Define the hospital dataset D2, which contains data from one or more hospitals in the same region or city within T days. That is, d2 contains data from t days. The hospital data for each day includes the number of patients with a certain disease and the sales volume of drugs related to the disease.
[0057] Define the physical examination data set d3, which contains the patient's physical examination data, including the patient's age, height, weight, and other biochemical test data.
[0058] The first LSTM network and the second LSTM network have the same structure, including a forget gate, an input gate, an output gate, and a cell state.
[0059] The preliminary feature extraction of climate data and hospital data is completed using LSTM network. The LSTM unit structure is as follows: Figure 3 Where f t 、i t , o t 、c t They represent the forget gate, input gate, output gate and cell state in LSTM respectively.
[0060] By adding these gate structures, LSTM can control the flow of information, that is, selectively store, lose, and update information at a certain moment, thereby solving the problem of long-distance information transmission of RNN, but it also leads to more parameters and longer training time.
[0061] Forget Gate t Determines whether the information in the cell state is lost. This gate will input the input layer x t And the data t of the previous hidden layer t-1 , the output is a value in the interval [0,1] and is fed back to the cell state c t-1 . 1 means "totally retain" and 0 means "totally discard".
[0062] f t =σ(W f x t +U f h t-1 +b f ;
[0063] Input Gate i t Determine the data that needs to be updated in the cell state. Update the cell state and compare the previous state with f t Multiply to discard the information that needs to be discarded, and then add the newly updated cell state:
[0064] i t =σ(W i x t +U i h t-1 +b i );
[0065] Output gate o t Determine the output of some cell states, the calculation formula is as follows:
[0066] ct =f i c t-1 +i t ×(tanh(W c x t +U c h t-1 +b c ));
[0067] o t =σ(W o x t +U o h t-1 +b o );
[0068] h t =o t ×tanh(c t ).
[0069] As an optimization solution of the above embodiment, the patient's physical examination data is concatenated with the feature vectors h1 and h2 to obtain a new feature vector h in ,formula:
[0070] h in =contact[x in ,h1,h2];
[0071] Among them, x in This is the patient's physical examination data.
[0072] The new feature vector h in Input into the multi-layer perceptron to get the output result h MLP ;
[0073] The multilayer perceptron contains l layers, and the i-th layer has n i neurons, l and n i is a hyperparameter; since the output layer of the multilayer perceptron has n l neurons, so h MLP The dimension is n l ×1.
[0074] As an optimization solution of the above embodiment, Figure 4 As shown, using the self-attention mechanism method (Self-Att), the feature vector h MLP Perform feature screening to obtain the more important feature vector h Att , including the steps of:
[0075] Define three matrices W according to the required standards Q , W K and W V , whose dimension is nl ×n l ;
[0076] Three new vectors are obtained by the following calculations:
[0077] h Q =W Q ·h MLP ;
[0078] h K =W K ·h MLP ;
[0079] h V =W V ·h MLP ;
[0080] The obtained h Q and h K Calculate and get a new feature matrix M, the calculation method is:
[0081]
[0082] Among them, R(·) is the transposition operation. The characteristic matrix M can be obtained by calculation, and its dimension is n l ×n l ;
[0083] Finally, the characteristic matrix M and the characteristic vector h V Calculate the new eigenvector h Att , the calculation method is: Att =Mh V ;
[0084] The final feature vector h Att After inputting into a fully connected layer, the output is calculated by Softmax. The calculation method is:
[0085]
[0086] Represents the model output, W fc and b fc is the parameter matrix and bias of a fully connected layer.
[0087] Preferably, during model training, the root mean square error function is used as the loss function, and the formula is:
[0088]
[0089] Among them, D train Represents the training dataset.
[0090] The above shows and describes the basic principles and main features of the present invention and the advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. A disease prediction method using a self-attention mechanism, characterized in that: Constructing a disease prediction model based on attention mechanism includes the following steps: S10, inputting the climate data of a time period into the first LSTM network for data analysis and feature extraction to obtain a feature vector h1; S20, inputting the hospital visit data in the same time period into the second LSTM network for data analysis and feature extraction to obtain a feature vector h2; S30, concatenate the patient's physical examination data with the feature vectors h1 and h2, input them into the MLP multi-layer perceptron, analyze the multi-source data, and extract the feature vector h MLP ; S40, using the improved self-attention mechanism, the feature vector h MLP Perform feature screening to obtain the more important feature vector h Att ; S50, h Att Input to a fully connected layer network FC to obtain the final prediction result; Among them, a data set is constructed as the input data of the disease prediction model. Each piece of input data of the disease prediction model includes the physical examination data of a patient's visit, as well as the climate data of the t days before the visit and the hospital data of the t days before the visit. The label of this piece of data is the disease diagnosed by the hospital; a data set is constructed, and the data set includes climate data, hospital visit data and the patient's physical examination data; Define a climate data set D1, which contains the climate data of a region or city within a period of T days. That is, D1 contains data for T days. The climate data for each day includes temperature, humidity, air quality, and wind speed data. Define the hospital dataset D2, which contains data from one or more hospitals in the same region or city within T days. That is, D2 contains data from T days. The hospital data for each day includes the number of patients with a certain disease and the sales volume of drugs related to the disease. Define the physical examination data set D3, which contains the patient's physical examination data, including the patient's age, height, weight, and other biochemical test data; Using the self-attention mechanism method, the feature vector h MLP Perform feature screening to obtain the more important feature vector h Att , including the steps of: Define three matrices W according to the required standards Q , W K and W V , whose dimension is n l ×n l ; Three new vectors are obtained by the following calculations: h Q =W Q ·h MLP ; h K =W K ·h MLP ; h V =W V ·h MLP ; The obtained h Q and h K Calculate and get a new feature matrix M, the calculation method is: Among them, R(·) is the transposition operation. The characteristic matrix M can be obtained by calculation, and its dimension is n l ×n l ; Finally, the characteristic matrix M and the characteristic vector h V Calculate the new eigenvector h Att , the calculation method is: h Att =Mh V ; The final feature vector h Att After inputting into a fully connected layer, the output is calculated by Softmax. The calculation method is: Represents the model output, W fc and b fc is the parameter matrix and bias of a fully connected layer.
2. A disease prediction method using a self-attention mechanism according to claim 1, characterized in that: The first LSTM network has the same structure as the second LSTM network, including a forget gate, an input gate, an output gate, and a cell state.
3. A disease prediction method using a self-attention mechanism according to claim 1, characterized in that: The patient's physical examination data is concatenated with the feature vectors h1 and h2 to obtain a new feature vector h in ,formula: h in =contact[x in ,h1,h2]; Among them, x in This is the patient's physical examination data.
4. A disease prediction method using a self-attention mechanism according to claim 3, characterized in that: The new feature vector h in Input into the multi-layer perceptron to get the output result h MLP ; The multilayer perceptron contains l layers, and the i-th layer has n i neurons, l and n i is a hyperparameter; since the output layer of the multilayer perceptron has n l neurons, so h MLP The dimension is n l ×1.
5. A disease prediction method using a self-attention mechanism according to claim 1, characterized in that: When training the model, the root mean square error function is used as the loss function, and the formula is: Among them, D train Represents the training dataset.
