Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 0c7e43b

Browse files
committed
Sleep Disorder Predictor - Added
1 parent 7df48ac commit 0c7e43b

File tree

10 files changed

+587
-0
lines changed

10 files changed

+587
-0
lines changed

App.py

+12
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@
130130
- **spread1**, **spread2**, **PPE**: Nonlinear measures of fundamental frequency variation.
131131
"""
132132
},
133+
{
134+
"name": "Sleep Disorder Prediction",
135+
"description": "Assess your risk of developing a sleep disorder using advanced ML algorithms.",
136+
"details": """
137+
### Introduction
138+
Sleep disorders can have a significant impact on an individual's overall health and well-being. These disorders often result from a combination of poor sleep habits, lifestyle factors, stress, and underlying medical conditions.
139+
140+
### Sleep Health and Lifestyle Dataset
141+
The dataset consists of sleep, lifestyle, and health metrics collected from 400 individuals. The main goal is to predict the likelihood of an individual having a sleep disorder using the "Sleep Disorder" column, which contains categorical values indicating the presence or absence of a sleep disorder.
142+
143+
"""
144+
},
133145
{
134146
"name": "PDF Malware Detector",
135147
"description": "Identify and alert users about potential malware in PDF files.",

form_configs/sleep_prediction.json

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"Sleep Prediction Form": {
3+
"Age": {
4+
"field_name": "Age",
5+
"type": "number",
6+
"min_value": 0,
7+
"max_value": 120,
8+
"default_value": 25,
9+
"step": 1
10+
},
11+
"Sleep_Duration": {
12+
"field_name": "Sleep_Duration",
13+
"type": "float",
14+
"min_value": 0.0,
15+
"max_value": 24.0,
16+
"default_value": 8.0,
17+
"step": 0.1
18+
},
19+
"Heart_Rate": {
20+
"field_name": "Heart_Rate",
21+
"type": "number",
22+
"min_value": 10,
23+
"max_value": 200,
24+
"default_value": 72,
25+
"step": 1
26+
},
27+
"Daily_Steps": {
28+
"field_name": "Daily_Steps",
29+
"type": "number",
30+
"min_value": 0,
31+
"max_value": 1000000,
32+
"default_value": 0,
33+
"step": 10
34+
},
35+
"Systolic": {
36+
"field_name": "Systolic",
37+
"type": "float",
38+
"min_value": 0.0,
39+
"max_value": 250.0,
40+
"default_value": 120.0,
41+
"step": 0.1
42+
},
43+
"Diastolic": {
44+
"field_name": "Diastolic",
45+
"type": "float",
46+
"min_value": 0.0,
47+
"max_value": 250.0,
48+
"default_value": 80.0,
49+
"step": 0.1
50+
},
51+
"Occupation": {
52+
"field_name": "Occupation",
53+
"type": "dropdown",
54+
"options": [
55+
"Software Engineer" ,"Doctor" ,"Sales Representative","Teacher" ,"Nurse",
56+
"Engineer" ,"Accountant" ,"Scientist", "Lawyer" ,"Salesperson" ,"Manager"
57+
],
58+
"default_value": "Software Engineer"
59+
},
60+
"Quality_of_Sleep": {
61+
"field_name": "Quality_of_Sleep",
62+
"type": "number",
63+
"min_value": 0,
64+
"max_value": 10,
65+
"default_value": 0,
66+
"step": 1
67+
},
68+
"Gender": {
69+
"field_name": "Gender",
70+
"type": "dropdown",
71+
"options": [
72+
"Male",
73+
"Female"
74+
],
75+
"default_value": "Male"
76+
77+
},
78+
"Physical_Activity_Level": {
79+
"field_name": "Physical_Activity_Level",
80+
"type": "number",
81+
"min_value": 0,
82+
"max_value": 200,
83+
"default_value": 0,
84+
"step": 1
85+
},
86+
"Stress_Level": {
87+
"field_name": "Stress_Level",
88+
"type": "number",
89+
"min_value": 0,
90+
"max_value": 10,
91+
"default_value": 0,
92+
"step": 1
93+
},
94+
"BMI_Category": {
95+
"field_name": "BMI_Category",
96+
"type": "dropdown",
97+
"options": [
98+
"Normal Weight",
99+
"Obese",
100+
"Overweight"
101+
],
102+
"default_value": "Normal Weight"
103+
}
104+
}
105+
}

models/sleep_disorder_predictor/data/dataset.csv

+375
Large diffs are not rendered by default.
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import streamlit as st
2+
import pickle
3+
import pandas as pd # Import pandas to handle DataFrames
4+
import numpy as np
5+
import warnings
6+
warnings.filterwarnings("ignore")
7+
8+
# Load the model and the scaler
9+
model_path = 'models/sleep_disorder_predictor/saved_models/Model_Prediction.sav'
10+
preprocessor_path = 'models/sleep_disorder_predictor/saved_models/preprocessor.sav'
11+
12+
# Load the pre-trained model and scaler using pickle
13+
loaded_model = pickle.load(open(model_path, 'rb'))
14+
preprocessor = pickle.load(open(preprocessor_path, 'rb'))
15+
16+
# Define the prediction function
17+
def disease_get_prediction(Age, Sleep_Duration,
18+
Heart_Rate, Daily_Steps,
19+
Systolic, Diastolic, Occupation, Quality_of_Sleep, Gender,
20+
Physical_Activity_Level, Stress_Level, BMI_Category):
21+
# Create a DataFrame with the features using correct column names
22+
features = pd.DataFrame({
23+
'Age': [int(Age)],
24+
'Sleep Duration': [float(Sleep_Duration)], # Changed to match expected name
25+
'Heart Rate': [int(Heart_Rate)], # Changed to match expected name
26+
'Daily Steps': [int(Daily_Steps)], # Changed to match expected name
27+
'Systolic': [float(Systolic)],
28+
'Diastolic': [float(Diastolic)],
29+
'Occupation': [Occupation],
30+
'Quality of Sleep': [int(Quality_of_Sleep)], # Changed to match expected name
31+
'Gender': [Gender],
32+
'Physical Activity Level': [int(Physical_Activity_Level)], # Changed to match expected name
33+
'Stress Level': [int(Stress_Level)], # Changed to match expected name
34+
'BMI Category': [BMI_Category] # Changed to match expected name
35+
})
36+
37+
# Apply the preprocessor (make sure it expects a DataFrame)
38+
preprocessed_data = preprocessor.transform(features)
39+
40+
# Make prediction
41+
prediction = loaded_model.predict(preprocessed_data)
42+
43+
return prediction

models/sleep_disorder_predictor/notebooks/sleep-disorder.ipynb

+1
Large diffs are not rendered by default.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from models.sleep_disorder_predictor.model import disease_get_prediction
2+
3+
def get_prediction(Age, Sleep_Duration,
4+
Heart_Rate, Daily_Steps,
5+
Systolic, Diastolic,Occupation,Quality_of_Sleep,Gender,
6+
Physical_Activity_Level, Stress_Level, BMI_Category):
7+
8+
prediction = disease_get_prediction(Age, Sleep_Duration,
9+
Heart_Rate, Daily_Steps,
10+
Systolic, Diastolic,Occupation,Quality_of_Sleep,Gender,
11+
Physical_Activity_Level, Stress_Level, BMI_Category)
12+
13+
message = ""
14+
15+
# Provide message based on the prediction value
16+
if prediction==0:
17+
message= "Insomnia"
18+
elif prediction==1:
19+
message = "No disorder"
20+
elif prediction==2:
21+
message = "Sleep Apnea"
22+
else:
23+
message="Invalid details."
24+
25+
return message+"\n\nRecommendation - To prevent sleep disorders, maintain a balanced lifestyle with regular exercise, a healthy diet, and stress management. Stick to a consistent sleep schedule, limit caffeine and alcohol, and create a relaxing bedtime routine."
Binary file not shown.
Binary file not shown.

pages/Sleep_Disorder_Predictor.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from page_handler import PageHandler
2+
3+
page_handler = PageHandler("pages/pages.json")
4+
page_handler.render_page("Sleep Disorder Predictor")

pages/pages.json

+22
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,28 @@
152152
}
153153
]
154154
},
155+
"Sleep Disorder Predictor": {
156+
"title": "Sleep Disorder Predictor",
157+
"page_title": "Sleep Disorder Predictor",
158+
"model_predict_file_path": "models/sleep_disorder_predictor/predict.py",
159+
"model_function": "get_prediction",
160+
"model_detail_function": "model_details",
161+
"form_config_path": "form_configs/sleep_prediction.json",
162+
"tabs": [
163+
{
164+
"name": "Sleep Disorder Predictor",
165+
"type": "form",
166+
"form_name": "Sleep Prediction Form"
167+
},
168+
{
169+
"name": "Model Details",
170+
"type": "model_details",
171+
172+
"problem_statement": "The model aims to predict the likelihood of an individual having a sleep disorder based on lifestyle, sleep quality, and health metrics.",
173+
"description": "Using a XGBoost classifier, the model predicts whether an individual is likely to have a sleep disorder based on features such as sleep duration, stress level, physical activity level, cardiovascular health metrics, and demographic information."
174+
}
175+
]
176+
},
155177

156178
"Malware_Detection": {
157179
"title": "PDF Malware Detection",

0 commit comments

Comments
 (0)