PyTorch-based air quality and health index prediction method
Through the deep learning neural network prediction model based on PyTorch, combining air monitoring data and case information data, real-time air quality and health indexes are generated, and the user's risk value is calculated, the problem of difficulty in personalized risk warning in the existing technology is solved, and effective risk reminders and health protection are achieved for users.
Patent Information
- Application Number
- CN202411648724.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-02-28
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
It is difficult for the prior art to provide personalized risk warnings to users based on air quality and health index.
The deep learning neural network prediction model based on PyTorch is adopted to obtain air monitoring data and case information data through an external platform, perform data preprocessing and model training, generate real-time air quality and health index, and calculate risk values based on the user's sensitivity and health index to determine whether users need to be warned.
It realizes personalized risk reminders to users, helping users understand the specific risks of current air quality and health index to their health, and promoting users to take preventive measures to avoid health damage.
Smart Images

Figure CN119539183A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of prediction of air quality and health index, and in particular to a prediction method of air quality and health index based on PyTorch. Background Art
[0002] With the rapid development of global industrialization and urbanization, air pollution is becoming increasingly serious, causing millions of deaths each year, especially in low- and middle-income countries. Currently, pollutants such as fine particulate matter, sulfur dioxide and nitrogen dioxide in the air have been shown to be associated with a variety of acute and chronic health problems, such as respiratory diseases, cardiovascular diseases and cancer.
[0003] At present, in order to reduce the impact of pollutants in the air on the health of citizens, the air quality and health index are obtained by analyzing the real-time concentration of various pollutants in the air, so that residents can intuitively feel the current quality and health of the air.
[0004] However, the health index currently calculated is based on the corresponding indicators of residents' health conditions. Residents have different physical conditions and react differently to pollutants in the air. Residents cannot understand their own risks in the current air quality and health index. Summary of the invention
[0005] The purpose of this invention is to provide a prediction method for air quality and health index based on PyTorch to solve the following technical problems: How to provide risk warnings to users based on air quality and health indexes.
[0006] The purpose of the present invention can be achieved by the following technical solutions: A PyTorch-based air quality and health index prediction method includes the following steps: S1: Obtain initial air monitoring data and case information data through external platform docking; S2: preprocessing the initial air monitoring data and case information data through a data preprocessing module to obtain processed air monitoring data and case information data; S3: construct a PyTorch deep learning neural network prediction model through a model construction module; the neural network prediction model includes a model training and evaluation module; the model training and evaluation module includes an input layer, a hidden layer, and an output layer; S4: by importing the processed air monitoring data and case information data into the input layer of the model training and evaluation module, and sending the processed air monitoring data and case information data into the hidden layer; S5: The hidden layer processes the complex features of air monitoring data and case information data through nonlinear transformation learning; the output layer generates the predicted values of output health index and air quality through forward propagation; S6: Calculate the error according to the loss function and optimize the model through the optimization module; return to step S5; until the training cycle is completed; enter step S7; S7: Perform real-time analysis on the initial monitoring data through the trained neural network prediction model to obtain real-time air quality and health index; S8: Obtain the user's sensitivity to each pollutant monitoring indicator through the user's case information data; obtain the risk value by substituting the user's sensitivity and health index into the preset risk value calculation rules; determine whether the user needs to be warned based on the risk value As a further solution of the present invention: the air monitoring data includes a plurality of pollutant monitoring indicators; The input layer, hidden layer and output layer respectively include a number of artificial neurons, and the neurons are connected through learnable weights and parameters.
[0007] As a further solution of the present invention: the working process of the hidden layer includes the following steps: S10: The neuron performs linear transformation on the received air monitoring data; S20: Introducing nonlinear relationships through activation functions; As a further solution of the present invention: the activation function is a ReLU activation function.
[0008] As a further solution of the present invention: the optimization step of the optimization model includes: S100: calculate momentum and gradient estimation; S200: Deviation correction; S300: Parameter update.
[0009] As a further solution of the present invention: the loss function is a cross entropy loss function.
[0010] As a further solution of the present invention: the preset risk value calculation rule is through the formula: Calculation number User's risk value ; in, is the judgment function, when hour, ;when hour, ; is the total number of pollutant monitoring indicators, ; For the The weight coefficient of each pollutant monitoring indicator; Number User No. The sensitivity of each pollutant monitoring indicator; For the The standard sensitivity of each pollutant monitoring indicator; is the first preset constant; It is a real-time health index.
[0011] As a further solution of the present invention: the process of determining whether a warning is required for the user is as follows: Number User's risk value With preset threshold Make a comparison; when There is no risk and no need for early warning; when When there is a low risk, a Level 1 warning is issued; when When there is a high risk, a level 2 warning is issued.
[0012] Beneficial effects of the present invention: (1) The present invention first obtains initial air monitoring data and case information data through an external platform docking; then pre-processes the initial air monitoring data and case information data through a data pre-processing module to obtain processed air monitoring data and case information data; then constructs a PyTorch deep learning neural network prediction model through a model building module; the neural network prediction model includes a model training and evaluation module; then the processed air monitoring data and case information data are imported into the input layer of the model training and evaluation module, and the processed air monitoring data and case information data are sent to the hidden layer; training begins, and the hidden layer learns the complex features of the processed air monitoring data and case information data through nonlinear transformation; the output layer generates output health index and air quality prediction values through forward propagation; the error is calculated according to the loss function, and the model is optimized through the optimization module; cyclic training is performed until the training cycle is completed; finally, the initial monitoring data is analyzed in real time through the trained neural network prediction model to obtain real-time air quality and health index; in the process of training the neural network, the loss function uses a cross entropy loss function to measure the difference between the model output and the actual label; through adaptive adjustment, the prediction accuracy is optimized by minimizing the error; (2) The present invention obtains the user's case information data through an external platform; obtains the user's sensitivity to various pollutant monitoring indicators through the user's case information data; obtains the risk value by substituting the user's sensitivity and health index into a preset risk value calculation rule; determines whether it is necessary to warn the user based on the risk value; and automatically issues risk reminders based on the user's situation, reminding the user to take precautions to avoid affecting the user's health. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The present invention will be further described below in conjunction with the accompanying drawings.
[0014] Figure 1 The present invention is a method flow chart of an embodiment of the present invention. DETAILED DESCRIPTION
[0015] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0016] See also Figure 1 As shown, in one embodiment, a method for predicting air quality and health index based on PyTorch is provided, comprising the following steps: S1: Obtain initial air monitoring data and case information data through external platform docking; S2: preprocessing the initial air monitoring data and case information data through a data preprocessing module to obtain processed air monitoring data and case information data; S3: construct a PyTorch deep learning neural network prediction model through a model construction module; the neural network prediction model includes a model training and evaluation module; the model training and evaluation module includes an input layer, a hidden layer, and an output layer; S4: by importing the processed air monitoring data and case information data into the input layer of the model training and evaluation module, and sending the processed air monitoring data and case information data into the hidden layer; S5: The hidden layer processes the complex features of air monitoring data and case information data through nonlinear transformation learning; the output layer generates the predicted values of output health index and air quality through forward propagation; S6: Calculate the error according to the loss function and optimize the model through the optimization module; return to step S5; until the training cycle is completed; enter step S7; S7: Perform real-time analysis on the initial monitoring data through the trained neural network prediction model to obtain real-time air quality and health index; S8: Obtain the user's sensitivity to each pollutant monitoring indicator through the user's case information data; obtain the risk value by substituting the user's sensitivity and health index into the preset risk value calculation rule; determine whether it is necessary to warn the user based on the risk value; Through the above technical solution, this embodiment first obtains initial air monitoring data and case information data through external platform docking; these data are recorded and released in real time by the city monitoring station. In addition, the case information data mainly comes from the records of hospitals and public health institutions; including the number of cases of respiratory diseases, the number of cases of cardiovascular diseases and the number of hospital admissions, etc.; then the initial air monitoring data and case information data are preprocessed by the data preprocessing module to obtain processed air monitoring data and case information data; then a PyTorch deep learning neural network prediction model is constructed through the model construction module; the neural network prediction model includes a model training and evaluation module; then the processed air monitoring data and case information data are imported into the input layer of the model training and evaluation module, and the processed air monitoring data and case information data are sent to the hidden layer; training begins, and the hidden layer learns the processed air monitoring data and case information data through nonlinear transformation The complex characteristics of the information data; through forward propagation, the output layer generates the predicted value of the output health index and air quality; according to the loss function, the error is calculated, and the model is optimized through the optimization module; the training is carried out in a loop; until the training cycle is completed; finally, the initial monitoring data is analyzed in real time through the trained neural network prediction model to obtain the real-time air quality and health index; in the process of training the neural network, the loss function uses the cross entropy loss function to measure the difference between the model output and the actual label; through adaptive adjustment, the prediction accuracy is optimized by minimizing the error; the user's case information data is obtained through the external platform; the user's sensitivity to each pollutant monitoring indicator is obtained through the user's case information data; the risk value is obtained by substituting the user's sensitivity and health index into the preset risk value calculation rules; the risk value is used to determine whether the user needs to be warned; risk reminders are automatically issued according to the user's situation, reminding the user to take precautions to avoid affecting the user's health; It should be noted that obtaining the user's sensitivity to various pollutant monitoring indicators through case information data is an existing technology and will not be described in detail here.
[0017] As an embodiment of the present invention, the air monitoring data includes a plurality of pollutant monitoring indicators; The input layer, hidden layer and output layer respectively include a number of artificial neurons, and the neurons are connected through learnable weights and parameters; Through the above technical solution, a pollutant monitoring indicator is a feature of the initial air monitoring data. Specifically, the features include PM2.5, PM10, sulfur dioxide, nitrogen dioxide and ozone; the number of neurons in the input layer is equal to the number of features of the input air monitoring data; the depth of the hidden layer and the number of neurons determine the expressive power of the model, that is, the ability to learn complex patterns.
[0018] As an implementation mode of the present invention, the working process of the hidden layer includes the following steps: S10: The neuron performs linear transformation on the received air monitoring data; S20: introducing a nonlinear relationship through an activation function; the activation function is a ReLU or SELU activation function; Through the above technical solution, the hidden layer of this embodiment includes three layers. The hidden layer is mainly used for nonlinear transformation. By introducing the activation function, self-normalization can be achieved, so that the model can more stably handle the complex relationship between air quality and health impact; the first layer converts the 9-dimensional input into 6 dimensions, the second layer further processes it into 3 dimensions, and the third layer processes it into 4 dimensions; the purpose of these hidden layers is to gradually extract important features and reduce noise. Each layer uses the ReLU activation function for calculation. The ReLU activation function can not only provide nonlinear transformation, but also maintain the normalization of the output value, thereby improving the stability of the model training process; As an implementation mode of the present invention, the optimization step of the optimization model includes: S100: calculate momentum and gradient estimation; S200: Deviation correction; S300: parameter update; Through the above technical solution, this embodiment calculates the momentum and gradient estimation through the formula:
[0019]
[0020] in, For the The gradient value of the step; is the exponential decay rate of the first-order moment estimate; is the exponential decay rate of the second-order moment estimate; For the The first moment estimate of step; For the The second moment estimate of the step; For the The first moment estimate of the step; For the The second moment estimate of the step; The bias correction is given by the formula: in, is the corrected first-order moment estimate; is the corrected second-order moment estimate; it is used to correct the bias of momentum estimation, especially in the initial training stage.
[0021] The parameters are updated by the formula: in, is the learning rate; is the adjustment coefficient; is the weight decay factor; For the Step parameters; For the Step parameters; In order to optimize the model parameters, the AdamW optimizer is used. AdamW is an improved version of the Adam optimizer that combines momentum and adaptive learning rate. On this basis, a weight decay term is introduced to control the scale of model parameters to prevent overfitting. AdamW is different from the Adam optimizer in that it explicitly applies the weight decay term to parameter updates instead of embedding it into gradient updates, thereby more effectively preventing overfitting. The AdamW optimizer can accelerate convergence when processing high-dimensional data and prevent overfitting of model parameters to training data through weight decay. To prevent the model from overfitting during training, this model introduces the L2 regularization (i.e. weight decay) strategy. L2 regularization limits the complexity of the model by imposing penalties on weight parameters. The specific regularization loss function is: in, is the total loss after adding the regularization term; is the original loss function; is the regularization coefficient, which controls the weight of the regularization term; is the weight parameter in the neural network, indicating the The weights of the neurons in the layer; is the total number of parameters in all network layers; The formula of the loss function is: in, is the loss function value; is the sample size; is the number of categories; For sample The true label of For sample The predicted probability of .
[0022] It should be noted that the learning rate The number of samples input into the model and the training cycle during each training are preset values, which are obtained based on experience and will not be described in detail here.
[0023] As an implementation mode of the present invention, the preset risk value calculation rule is through the formula: Calculation number User's risk value ; in, is the judgment function, when hour, ;when hour, ; is the total number of pollutant monitoring indicators, ; For the The weight coefficient of each pollutant monitoring indicator; Number User No. The sensitivity of each pollutant monitoring indicator; For the The standard sensitivity of each pollutant monitoring indicator; is the first preset constant; It is a real-time health index; Through the above technical solution, this embodiment Number User No. The sensitivity of the pollutant monitoring indicators is The sensitivity difference of the standard sensitivity of the pollutant monitoring indicators; judgment function In Refers to the sensitivity difference ; when When; Description No. User's The sensitivity of the pollutant monitoring indicators is low, and the current health index Pair Number The lower the risk to the user, the less impact; therefore ; when When; Description No. User's The pollutant monitoring indicators are highly sensitive, so ; Sensitivity difference The higher; Current health index Pair Number The higher the risk to the user; The bigger; Current health index Pair Number The higher the risk to the user; No. User's risk value The bigger; It should be noted that Weight coefficient of each pollutant monitoring indicator , No. Standard sensitivity of each pollutant monitoring indicator and the first preset constant It is a preset value obtained based on experience and will not be described in detail here.
[0024] As an implementation mode of the present invention, the process of determining whether a warning is required for a user is as follows: Number User's risk value With preset threshold Make a comparison; when There is no risk and no need for early warning; when When there is a low risk, a Level 1 warning is issued; when When there is a high risk, a Level 2 warning is issued; Through the above technical solution, this embodiment When Users are not at risk under the current air quality and health index and can do more outdoor exercise and ventilate more without warning; when When Users are at low risk under the current air quality and health index, and are subject to a Level 1 warning. They should avoid outdoor exercise and ventilate the room in small amounts. When Users are at high risk under the current air quality and health index, so try not to go out. If you go out, you need to take protective measures and keep doors and windows closed; It should be noted that the preset threshold It is a preset value obtained based on experience and will not be described in detail here.
[0025] The above is a detailed description of an embodiment of the present invention, but the content is only a preferred embodiment of the present invention and cannot be considered to limit the scope of implementation of the present invention. All equivalent changes and improvements made within the scope of the present invention should still fall within the scope of the patent coverage of the present invention.
Claims
1. A method for predicting air quality and health index based on PyTorch, characterized in that: The following steps are involved: S1: Obtain initial air monitoring data and case information data through external platform docking; S2: preprocessing the initial air monitoring data and case information data through a data preprocessing module to obtain processed air monitoring data and case information data; S3: construct a PyTorch deep learning neural network prediction model through a model construction module; the neural network prediction model includes a model training and evaluation module; the model training and evaluation module includes an input layer, a hidden layer, and an output layer; S4: by importing the processed air monitoring data and case information data into the input layer of the model training and evaluation module, and sending the processed air monitoring data and case information data into the hidden layer; S5: The hidden layer processes the complex features of air monitoring data and case information data through nonlinear transformation learning; Through forward propagation, the output layer generates the predicted values of output health index and air quality; S6: Calculate the error according to the loss function and optimize the model through the optimization module; return to step S5; Until the training cycle is completed; go to step S7; S7: Perform real-time analysis on the initial monitoring data through the trained neural network prediction model to obtain real-time air quality and health index; S8: Obtain the user's sensitivity to each pollutant monitoring indicator through the user's case information data; obtain the risk value by substituting the user's sensitivity and health index into the preset risk value calculation rules; determine whether it is necessary to warn the user based on the risk value.
2. The method for predicting air quality and health index based on PyTorch according to claim 1, characterized in that: The air monitoring data includes multiple pollutant monitoring indicators; The input layer, hidden layer and output layer respectively include a number of artificial neurons, and the neurons are connected through learnable weights and parameters.
3. The method for predicting air quality and health index based on PyTorch according to claim 2, characterized in that: The working process of the hidden layer includes the following steps: S10: The neuron performs linear transformation on the received air monitoring data; S20: Introducing nonlinear relationships through activation functions.
4. The method for predicting air quality and health index based on PyTorch according to claim 3, characterized in that: The activation function is the ReLU activation function.
5. The method for predicting air quality and health index based on PyTorch according to claim 4, characterized in that: The optimization steps of the optimization model include: S100: calculate momentum and gradient estimation; S200: Deviation correction; S300: Parameter update.
6. The method for predicting air quality and health index based on PyTorch according to claim 1, characterized in that: The loss function is a cross entropy loss function.
7. The method for predicting air quality and health index based on PyTorch according to claim 6, characterized in that: The default risk value calculation rule is through the formula: Calculation number User's risk value ; in, is the judgment function, when hour, ;when hour, ; is the total number of pollutant monitoring indicators, ; For the The weight coefficient of each pollutant monitoring indicator; Number User No. The sensitivity of each pollutant monitoring indicator; For the The standard sensitivity of each pollutant monitoring indicator; is the first preset constant; It is a real-time health index.
8. The method for predicting air quality and health index based on PyTorch according to claim 7, characterized in that: The process of determining whether a warning is needed for the user is as follows: Number User's risk value With preset threshold Make a comparison; when There is no risk and no need for early warning; when When there is a low risk, a Level 1 warning is issued; when When there is a high risk, a level 2 warning is issued.