Skip to content

Commit 98031c9

Browse files
authored
Merge pull request #1573 from PrAyAg9/prayag_patch1
Issue #1572 Solved :- Added Asthma Prediction
2 parents 523a90d + 058d1d9 commit 98031c9

File tree

7 files changed

+1297
-0
lines changed

7 files changed

+1297
-0
lines changed

Prediction Models/Ashtma Attack Prediction/Ashtma_Attack_Pred.ipynb

Lines changed: 568 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Age,Height,Gender,Outdoor Temperature,Humidity,PM 2.5 ,PM 10,PEFR
2+
19,155,1,33,60,16,23.62,524
3+
26,183,1,32,71,12,18.29,640
4+
22,153,0,27,85,27,38.29,356
5+
25,160,0,26,88,18,26.2,402
6+
18,162,0,26,85,16,23.62,424
7+
18,150,1,32,64,38,52.8,465
8+
26,176,1,29,82,22,31.62,540
9+
33,146,0,24,86,34,47.5,326
10+
40,178,1,33,65,27,38.3,512
11+
25,164,0,36,55,28,39.8,399
12+
20,195,1,29,78,26,36,578
13+
27,153,0,27,86,18,27,401
14+
29,149,0,30,62,12,18,460
15+
26,157,0,31,66,16,23.66,453
16+
25,140,0,26,89,34,47.5,366
17+
20,168,1,24,90,20,29,571
18+
20,174,1,33,64,33,46.1,522
19+
23,154,0,28,86,21,30.5,432
20+
17,176,1,27,89,19,27.7,621
21+
18,155,1,34,63,14,21,531
22+
19,150,1,30,68,12,18,502
23+
20,149,0,25,78,18,27,456
24+
36,160,1,27,73,16,23.66,587
25+
49,153,1,20,92,20,29,516
26+
25,164,1,26,88,34,48,486
27+
29,152,0,24,88,20,35,460
28+
23,169,1,28,78,26,40,502
29+
24,154,1,29,67,38,50,412
30+
27,180,1,32,62,21,36,621
31+
15,160,0,21,92,36,48,322
32+
33,145,0,25,90,37,49,302
33+
65,190,1,24,88,25,40,600
34+
24,160,0,26,84,21,36,483
35+
26,169,1,36,59,26,39,513
36+
32,142,0,22,79,21,35,454
37+
16,195,1,33,68,25,29,586
38+
20,146,0,36,64,25,33,450
39+
25,187,1,34,63,12,24,651
40+
26,182,1,31,60,13,26,643
41+
29,162,1,22,83,18,29,586
42+
27,146,0,24,89,18,32,476
43+
23,186,1,27,81,14,24,608
44+
22,144,0,26,76,16,28,466
45+
33,176,1,32,70,22,35,578
46+
36,155,0,23,89,26,36,472
47+
36,169,1,36,52,29,39,565
48+
25,166,0,25,82,19,29,498
49+
39,185,1,34,60,18,30,600
50+
34,166,0,21,95,26,32,420
51+
29,178,1,25,82,24,35,598
52+
28,145,0,26,84,15,30,444
53+
25,177,1,35,56,16,36,599
54+
36,146,0,24,81,35,51,356
55+
22,149,0,33,56,24,40,416
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Asthma Risk Prediction System
2+
3+
## Table of Contents
4+
1. [Abstract](#abstract)
5+
2. [Algorithm](#algorithm)
6+
3. [Proposed Methodology](#proposed-methodology)
7+
4. [Dataset Details](#dataset-details)
8+
5. [Deep Learning Algorithm](#deep-learning-algorithm)
9+
6. [Model Validation](#model-validation)
10+
7. [Results](#results)
11+
8. [Conclusion and Future Plans](#conclusion-and-future-plans)
12+
13+
## Abstract
14+
Air pollution poses a significant threat to global health, particularly in relation to respiratory conditions, contributing to over 8 million deaths annually. The impact is widespread, with more than 4.2 million deaths attributed to outdoor exposure and an additional 3.8 million linked to indoor pollution. Respiratory symptoms induced by pollutant agents are evident, with a pronounced interference in asthma outcomes, including incidence, prevalence, hospital admissions, emergency department visits, mortality, and asthma attacks. Amidst the ongoing COVID-19 situation, the risk escalates for older adults and individuals with complications like hypertension and diabetes during hospital admissions. Addressing this concern, an essential in-house monitoring framework for predicting asthma risk is proposed.
15+
16+
The proposed Asthma Risk Prediction framework utilizes deep learning algorithms to estimate vulnerability based on particulate matter (PM) levels in the living environment and outdoor weather conditions. Employing Convolutional Neural Networks, the framework categorizes predicted peak expiratory flow rate (PEFR) levels into three groups: "Green" (Safe), "Yellow" (Moderate Risk), and "Red" (High Risk). When conditions indicate potential asthma risk, proactive measures such as activating air purifiers and notifying first responders are initiated. The hardware implementation involves PM sensors for detection, with a Raspberry Pi serving as the edge node to predict risk levels and trigger the response system.
17+
18+
**Keywords:** edge computing, machine learning, IoT, asthma prediction, particulate matter (PM), peak expiratory flow rates (PEFR), convolutional neural network, Raspberry Pi
19+
20+
## Algorithm
21+
The algorithm explaining the proposed system works in real-time:
22+
- **Input:** PM2.5, PM10, outdoor temperature, humidity.
23+
- **Output:** Safe, Moderate, or High asthma risk prediction.
24+
25+
**Data Processing Stage on the Raspberry Pi:**
26+
- Collect PM2.5, PM10 using SDS011.
27+
- Collect weather data using OpenWeatherMap.
28+
- Host input features to the server.
29+
30+
**Real-time Stage on the Smartphone:**
31+
```plaintext
32+
while MQTT publishing data:
33+
do
34+
Collect data from Sensor;
35+
CNN prediction;
36+
if PEFR > 80% then
37+
Safe;
38+
else if 50% < PEFR < 80% then
39+
Moderate risk;
40+
else
41+
High risk;
42+
end
43+
end
44+
```
45+
# PROPOSED METHODOLOGY
46+
47+
# Proposed Asthma Prediction Method
48+
• PM sensors to detect the particulate matters.
49+
• The collected data is sent to the edge node raspberry pi
50+
• The CNN algorithm will be running in the raspberry pi which has already been trained with the dataset given previously
51+
• the estimated PEFR levels are categorized into three groups: "Green" (Safe), "Yellow" (Moderate Risk), and "Red “
52+
• Raspberry pi predicts the level of risk
53+
• If the prevailing conditions are amenable to cause asthma risk then with the help of relay air purifier is switched on and informs the first responsible persons (FRP)
54+
55+
# DATASET DETAILS
56+
57+
![image](https://github.com/user-attachments/assets/5751b23b-09f3-405f-8c4f-5635cfc1f17f)
58+
59+
60+
The dataset utilized is real-time and includes both features and one label. It comprises the individual's age, height, and gender, along with the room's temperature, humidity, particulate matter information, and the predicted Peak Expiratory Flow Rate.
61+
62+
The humidity and temperature are recorded from the readings of DHT11 sensor and the pm2.5 and pm10 values from the sds011 air quality sensor
63+
64+
Out of the dataset 80% of the data is used for training and 20% is used for testing.
65+
66+
# DEEP LEARNING ALGORITHM
67+
68+
69+
The deep learning algorithm which we have used is 1DCNN.
70+
71+
One-dimensional convolution neural networks(1D CNN) are often used for time series data analysis, where the data is sequenced and ordered over time. Asthma is a chronic respiratory disease that can be characterized by symptoms that change over time, such as wheezing and shortness of breath.
72+
73+
1D CNN is effective for asthma prediction because they are designed to learn spatial temporal patterns in sequential data. They can capture both short-term and long-term dependencies in the time series data, which is important for asthma prediction as the symptoms can vary over different time scales.
74+
75+
In addition,1D CNN can be used to automatically extract relevant features from the raw input data, which can help to improve the accuracy of the prediction.
76+
77+
![image](https://github.com/user-attachments/assets/3fa7ed85-0af9-4a62-9cc2-e8fac7f6e3c7)
78+
79+
# MODEL VALIDATION :
80+
81+
82+
83+
In this work, we used two criteria RMSE and MAE ,These are used to evaluate the performance of the model
84+
85+
86+
• MEAN ABSOLUTE ERROR:
87+
88+
MAE is the absolute difference between the target and predicted variables.
89+
90+
![image](https://github.com/user-attachments/assets/9213f1cd-ffc2-4ea8-b437-9a774d58b3a2)
91+
92+
93+
MAE ranges from 0 to positive infinity, Apparently it is expected to achieve MAE value as small
94+
as possible (close to 0),meaning that the predicted value is equal to the target
95+
96+
97+
• ROOT MEAN SQUARE ERROR:
98+
99+
RMSE is the standard deviation,which indicated the difference between real and predicted variables
100+
101+
![image](https://github.com/user-attachments/assets/96967f56-a4c0-4e01-8dcc-dc149d154349)
102+
103+
# RESULTS
104+
105+
• Plot between RMSE and epoch
106+
![image](https://github.com/user-attachments/assets/2f9e172c-46f8-4e43-a1af-9b9a9bbc1ac1)
107+
108+
• Plot between MAE and epochs
109+
![image](https://github.com/user-attachments/assets/0ce8b834-bfbc-4daa-9180-9148c0651cdf)
110+
111+
• Mean Absolute Error
112+
![image](https://github.com/user-attachments/assets/a19d26ff-409e-4ccf-93aa-146a05aac0c7)
113+
114+
• Root Mean Squared Error
115+
![image](https://github.com/user-attachments/assets/4217b126-94d4-4c5a-b238-7d13b4a156de)
116+
117+
• Prediction of PEFR value
118+
![image](https://github.com/user-attachments/assets/5a809d3e-f5e2-43e8-b9cd-b38ef1059942)
119+
120+
# CONCLUSION AND FUTURE PLANS
121+
In this project, we introduce a convolutional neural network-based approach to predict asthma development risk. By leveraging basic PM and weather data, we forecast PEFR readings. Through unbiased evaluations, we observe significant performance improvements with our proposed method. This model employs sensors, an edge device, and an IoT platform. It offers an accurate means of forecasting asthma likelihood, providing individuals the ability to monitor their condition anytime, anywhere. Our future plans involve product development and the creation of a mobile application. This app will collect user data such as height, weight, age, and sex, while the product itself monitors environmental conditions. Its portability ensures easy accessibility for asthma risk assessment regardless of location or time. Hence, this tool presents a highly effective solution for asthma risk monitoring.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "be5b3365",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"data": {
11+
"text/plain": [
12+
"['PEFR_predictor.joblib']"
13+
]
14+
},
15+
"execution_count": 1,
16+
"metadata": {},
17+
"output_type": "execute_result"
18+
}
19+
],
20+
"source": [
21+
"import pandas as pd\n",
22+
"from sklearn.tree import DecisionTreeClassifier as dtc\n",
23+
"import joblib\n",
24+
"\n",
25+
"data=pd.read_csv(\"PEFR_Data_set.csv\")\n",
26+
"data.shape\n",
27+
"X=data.drop(columns=['Age','Height','PEFR'])\n",
28+
"y=data['PEFR']\n",
29+
"model=dtc()\n",
30+
"model.fit(X,y)\n",
31+
"joblib.dump(model, 'PEFR_predictor.joblib')\n"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 3,
37+
"id": "39c29fa3",
38+
"metadata": {},
39+
"outputs": [
40+
{
41+
"name": "stdout",
42+
"output_type": "stream",
43+
"text": [
44+
"Enter Gender 1-Male 0-Female1\n",
45+
"Enter Temperature C:22\n",
46+
"Enter Humidity %:33\n",
47+
"Enter PM 2.5 Value:44\n",
48+
"Enter PM 10 Value:22\n",
49+
"Enter Actual PEFR value334\n",
50+
"512\n",
51+
"65.234375\n",
52+
"MODERATE\n"
53+
]
54+
}
55+
],
56+
"source": [
57+
"\n",
58+
"model = joblib.load('PEFR_predictor.joblib')\n",
59+
"g=int(input(\"Enter Gender 1-Male 0-Female\"))\n",
60+
"p=float(input('Enter Temperature C:'))\n",
61+
"q=float(input('Enter Humidity %:'))\n",
62+
"r=float(input('Enter PM 2.5 Value:'))\n",
63+
"s=float(input('Enter PM 10 Value:'))\n",
64+
"prediction = model.predict([[g,p,q,r,s]])\n",
65+
"predicted_pefr = prediction[0]\n",
66+
"actual_pefr = float(input(\"Enter Actual PEFR value\"))\n",
67+
"print(predicted_pefr)\n",
68+
"perpefr = (actual_pefr/predicted_pefr)*100\n",
69+
"print(perpefr)\n",
70+
"if perpefr >= 80:\n",
71+
" print('SAFE')\n",
72+
"elif perpefr >= 50:\n",
73+
" print('MODERATE')\n",
74+
"else:\n",
75+
" print('RISK')\n"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "66e1edfe",
82+
"metadata": {},
83+
"outputs": [],
84+
"source": []
85+
}
86+
],
87+
"metadata": {
88+
"kernelspec": {
89+
"display_name": "Python 3 (ipykernel)",
90+
"language": "python",
91+
"name": "python3"
92+
},
93+
"language_info": {
94+
"codemirror_mode": {
95+
"name": "ipython",
96+
"version": 3
97+
},
98+
"file_extension": ".py",
99+
"mimetype": "text/x-python",
100+
"name": "python",
101+
"nbconvert_exporter": "python",
102+
"pygments_lexer": "ipython3",
103+
"version": "3.7.5"
104+
}
105+
},
106+
"nbformat": 4,
107+
"nbformat_minor": 5
108+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# In[1]:
5+
6+
7+
import pandas as pd
8+
from sklearn.tree import DecisionTreeClassifier as dtc
9+
import joblib
10+
import requests
11+
from bs4 import BeautifulSoup
12+
13+
14+
# In[2]:
15+
16+
17+
data=pd.read_csv("PEFR_Data_set.csv")
18+
data.shape
19+
X=data.drop(columns=['Age','Height','PEFR'])
20+
y=data['PEFR']
21+
model=dtc()
22+
model.fit(X,y)
23+
24+
#joblib.dump(model, 'PEFR_predictor.joblib')
25+
26+
27+
# In[3]:
28+
29+
30+
#model = joblib.load('PEFR_predictor.joblib')
31+
32+
33+
# In[5]:
34+
35+
city = input("Enter City:")
36+
url = f'https://www.iqair.com/in-en/india/tamil-nadu/{city}'
37+
r = requests.get(url)
38+
39+
soup = BeautifulSoup(r.content,'html.parser')
40+
aqi_dict = []
41+
s = soup.find_all(class_ = "mat-tooltip-trigger pollutant-concentration-value")
42+
43+
44+
for x in s:
45+
aqi_dict.append(x.text)
46+
47+
pm2 = aqi_dict[0]
48+
pm10 = aqi_dict[1]
49+
50+
t = soup.find('div', class_="weather__detail")
51+
y = t.text
52+
temp_index = y.find('Temperature')+11
53+
degree_index = y.find('°')
54+
temp = y[temp_index : degree_index]
55+
56+
hum_index = y.find('Humidity')+8
57+
perc_index = y.find('%')
58+
hum = y[hum_index:perc_index]
59+
'''
60+
print(pm2)
61+
print(pm10)
62+
print(temp)
63+
print(hum)
64+
'''
65+
66+
# In[6]:
67+
68+
g=int(input("Enter Gender (1-Male/0-Female): "))
69+
p=temp
70+
q=hum
71+
r=pm2
72+
s=pm10
73+
prediction = model.predict([[g,p,q,r,s]])
74+
predicted_pefr = prediction[0]
75+
76+
actual_pefr = float(input("Enter Actual PEFR value: "))
77+
78+
perpefr = (actual_pefr/predicted_pefr)*100
79+
if perpefr >= 80:
80+
print('SAFE')
81+
elif perpefr >= 50:
82+
print('MODERATE')
83+
else:
84+
print('RISK')
85+

0 commit comments

Comments
 (0)