Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1572 Solved :- Added Asthma Prediction #1573

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
568 changes: 568 additions & 0 deletions Prediction Models/Ashtma Attack Prediction/Ashtma_Attack_Pred.ipynb

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions Prediction Models/Ashtma Attack Prediction/Asthamapred_dataset.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Age,Height,Gender,Outdoor Temperature,Humidity,PM 2.5 ,PM 10,PEFR
19,155,1,33,60,16,23.62,524
26,183,1,32,71,12,18.29,640
22,153,0,27,85,27,38.29,356
25,160,0,26,88,18,26.2,402
18,162,0,26,85,16,23.62,424
18,150,1,32,64,38,52.8,465
26,176,1,29,82,22,31.62,540
33,146,0,24,86,34,47.5,326
40,178,1,33,65,27,38.3,512
25,164,0,36,55,28,39.8,399
20,195,1,29,78,26,36,578
27,153,0,27,86,18,27,401
29,149,0,30,62,12,18,460
26,157,0,31,66,16,23.66,453
25,140,0,26,89,34,47.5,366
20,168,1,24,90,20,29,571
20,174,1,33,64,33,46.1,522
23,154,0,28,86,21,30.5,432
17,176,1,27,89,19,27.7,621
18,155,1,34,63,14,21,531
19,150,1,30,68,12,18,502
20,149,0,25,78,18,27,456
36,160,1,27,73,16,23.66,587
49,153,1,20,92,20,29,516
25,164,1,26,88,34,48,486
29,152,0,24,88,20,35,460
23,169,1,28,78,26,40,502
24,154,1,29,67,38,50,412
27,180,1,32,62,21,36,621
15,160,0,21,92,36,48,322
33,145,0,25,90,37,49,302
65,190,1,24,88,25,40,600
24,160,0,26,84,21,36,483
26,169,1,36,59,26,39,513
32,142,0,22,79,21,35,454
16,195,1,33,68,25,29,586
20,146,0,36,64,25,33,450
25,187,1,34,63,12,24,651
26,182,1,31,60,13,26,643
29,162,1,22,83,18,29,586
27,146,0,24,89,18,32,476
23,186,1,27,81,14,24,608
22,144,0,26,76,16,28,466
33,176,1,32,70,22,35,578
36,155,0,23,89,26,36,472
36,169,1,36,52,29,39,565
25,166,0,25,82,19,29,498
39,185,1,34,60,18,30,600
34,166,0,21,95,26,32,420
29,178,1,25,82,24,35,598
28,145,0,26,84,15,30,444
25,177,1,35,56,16,36,599
36,146,0,24,81,35,51,356
22,149,0,33,56,24,40,416
121 changes: 121 additions & 0 deletions Prediction Models/Ashtma Attack Prediction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Asthma Risk Prediction System

## Table of Contents
1. [Abstract](#abstract)
2. [Algorithm](#algorithm)
3. [Proposed Methodology](#proposed-methodology)
4. [Dataset Details](#dataset-details)
5. [Deep Learning Algorithm](#deep-learning-algorithm)
6. [Model Validation](#model-validation)
7. [Results](#results)
8. [Conclusion and Future Plans](#conclusion-and-future-plans)

## Abstract
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.

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.

**Keywords:** edge computing, machine learning, IoT, asthma prediction, particulate matter (PM), peak expiratory flow rates (PEFR), convolutional neural network, Raspberry Pi

## Algorithm
The algorithm explaining the proposed system works in real-time:
- **Input:** PM2.5, PM10, outdoor temperature, humidity.
- **Output:** Safe, Moderate, or High asthma risk prediction.

**Data Processing Stage on the Raspberry Pi:**
- Collect PM2.5, PM10 using SDS011.
- Collect weather data using OpenWeatherMap.
- Host input features to the server.

**Real-time Stage on the Smartphone:**
```plaintext
while MQTT publishing data:
do
Collect data from Sensor;
CNN prediction;
if PEFR > 80% then
Safe;
else if 50% < PEFR < 80% then
Moderate risk;
else
High risk;
end
end
```
# PROPOSED METHODOLOGY

# Proposed Asthma Prediction Method
• PM sensors to detect the particulate matters.
• The collected data is sent to the edge node raspberry pi
• The CNN algorithm will be running in the raspberry pi which has already been trained with the dataset given previously
• the estimated PEFR levels are categorized into three groups: "Green" (Safe), "Yellow" (Moderate Risk), and "Red “
• Raspberry pi predicts the level of risk
• 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)

# DATASET DETAILS

![image](https://github.com/user-attachments/assets/5751b23b-09f3-405f-8c4f-5635cfc1f17f)


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.

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

Out of the dataset 80% of the data is used for training and 20% is used for testing.

# DEEP LEARNING ALGORITHM


The deep learning algorithm which we have used is 1DCNN.

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.

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.

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.

![image](https://github.com/user-attachments/assets/3fa7ed85-0af9-4a62-9cc2-e8fac7f6e3c7)

# MODEL VALIDATION :



In this work, we used two criteria RMSE and MAE ,These are used to evaluate the performance of the model


• MEAN ABSOLUTE ERROR:

MAE is the absolute difference between the target and predicted variables.

![image](https://github.com/user-attachments/assets/9213f1cd-ffc2-4ea8-b437-9a774d58b3a2)


MAE ranges from 0 to positive infinity, Apparently it is expected to achieve MAE value as small
as possible (close to 0),meaning that the predicted value is equal to the target


• ROOT MEAN SQUARE ERROR:

RMSE is the standard deviation,which indicated the difference between real and predicted variables

![image](https://github.com/user-attachments/assets/96967f56-a4c0-4e01-8dcc-dc149d154349)

# RESULTS

• Plot between RMSE and epoch
![image](https://github.com/user-attachments/assets/2f9e172c-46f8-4e43-a1af-9b9a9bbc1ac1)

• Plot between MAE and epochs
![image](https://github.com/user-attachments/assets/0ce8b834-bfbc-4daa-9180-9148c0651cdf)

• Mean Absolute Error
![image](https://github.com/user-attachments/assets/a19d26ff-409e-4ccf-93aa-146a05aac0c7)

• Root Mean Squared Error
![image](https://github.com/user-attachments/assets/4217b126-94d4-4c5a-b238-7d13b4a156de)

• Prediction of PEFR value
![image](https://github.com/user-attachments/assets/5a809d3e-f5e2-43e8-b9cd-b38ef1059942)

# CONCLUSION AND FUTURE PLANS
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "be5b3365",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['PEFR_predictor.joblib']"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"from sklearn.tree import DecisionTreeClassifier as dtc\n",
"import joblib\n",
"\n",
"data=pd.read_csv(\"PEFR_Data_set.csv\")\n",
"data.shape\n",
"X=data.drop(columns=['Age','Height','PEFR'])\n",
"y=data['PEFR']\n",
"model=dtc()\n",
"model.fit(X,y)\n",
"joblib.dump(model, 'PEFR_predictor.joblib')\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "39c29fa3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter Gender 1-Male 0-Female1\n",
"Enter Temperature C:22\n",
"Enter Humidity %:33\n",
"Enter PM 2.5 Value:44\n",
"Enter PM 10 Value:22\n",
"Enter Actual PEFR value334\n",
"512\n",
"65.234375\n",
"MODERATE\n"
]
}
],
"source": [
"\n",
"model = joblib.load('PEFR_predictor.joblib')\n",
"g=int(input(\"Enter Gender 1-Male 0-Female\"))\n",
"p=float(input('Enter Temperature C:'))\n",
"q=float(input('Enter Humidity %:'))\n",
"r=float(input('Enter PM 2.5 Value:'))\n",
"s=float(input('Enter PM 10 Value:'))\n",
"prediction = model.predict([[g,p,q,r,s]])\n",
"predicted_pefr = prediction[0]\n",
"actual_pefr = float(input(\"Enter Actual PEFR value\"))\n",
"print(predicted_pefr)\n",
"perpefr = (actual_pefr/predicted_pefr)*100\n",
"print(perpefr)\n",
"if perpefr >= 80:\n",
" print('SAFE')\n",
"elif perpefr >= 50:\n",
" print('MODERATE')\n",
"else:\n",
" print('RISK')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66e1edfe",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import pandas as pd
from sklearn.tree import DecisionTreeClassifier as dtc
import joblib
import requests
from bs4 import BeautifulSoup


# In[2]:


data=pd.read_csv("PEFR_Data_set.csv")
data.shape
X=data.drop(columns=['Age','Height','PEFR'])
y=data['PEFR']
model=dtc()
model.fit(X,y)

#joblib.dump(model, 'PEFR_predictor.joblib')


# In[3]:


#model = joblib.load('PEFR_predictor.joblib')


# In[5]:

city = input("Enter City:")
url = f'https://www.iqair.com/in-en/india/tamil-nadu/{city}'
r = requests.get(url)

soup = BeautifulSoup(r.content,'html.parser')
aqi_dict = []
s = soup.find_all(class_ = "mat-tooltip-trigger pollutant-concentration-value")


for x in s:
aqi_dict.append(x.text)

pm2 = aqi_dict[0]
pm10 = aqi_dict[1]

t = soup.find('div', class_="weather__detail")
y = t.text
temp_index = y.find('Temperature')+11
degree_index = y.find('°')
temp = y[temp_index : degree_index]

hum_index = y.find('Humidity')+8
perc_index = y.find('%')
hum = y[hum_index:perc_index]
'''
print(pm2)
print(pm10)
print(temp)
print(hum)
'''

# In[6]:

g=int(input("Enter Gender (1-Male/0-Female): "))
p=temp
q=hum
r=pm2
s=pm10
prediction = model.predict([[g,p,q,r,s]])
predicted_pefr = prediction[0]

actual_pefr = float(input("Enter Actual PEFR value: "))

perpefr = (actual_pefr/predicted_pefr)*100
if perpefr >= 80:
print('SAFE')
elif perpefr >= 50:
print('MODERATE')
else:
print('RISK')

Loading
Loading