Skip to content

Commit

Permalink
Add Sleep Disorder Predictor Model
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvini121 authored Oct 30, 2024
2 parents 413c02a + 0c7e43b commit 89c5053
Show file tree
Hide file tree
Showing 10 changed files with 587 additions and 0 deletions.
12 changes: 12 additions & 0 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@
- **spread1**, **spread2**, **PPE**: Nonlinear measures of fundamental frequency variation.
"""
},
{
"name": "Sleep Disorder Prediction",
"description": "Assess your risk of developing a sleep disorder using advanced ML algorithms.",
"details": """
### Introduction
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.
### Sleep Health and Lifestyle Dataset
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.
"""
},
{
"name": "PDF Malware Detector",
"description": "Identify and alert users about potential malware in PDF files.",
Expand Down
105 changes: 105 additions & 0 deletions form_configs/sleep_prediction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"Sleep Prediction Form": {
"Age": {
"field_name": "Age",
"type": "number",
"min_value": 0,
"max_value": 120,
"default_value": 25,
"step": 1
},
"Sleep_Duration": {
"field_name": "Sleep_Duration",
"type": "float",
"min_value": 0.0,
"max_value": 24.0,
"default_value": 8.0,
"step": 0.1
},
"Heart_Rate": {
"field_name": "Heart_Rate",
"type": "number",
"min_value": 10,
"max_value": 200,
"default_value": 72,
"step": 1
},
"Daily_Steps": {
"field_name": "Daily_Steps",
"type": "number",
"min_value": 0,
"max_value": 1000000,
"default_value": 0,
"step": 10
},
"Systolic": {
"field_name": "Systolic",
"type": "float",
"min_value": 0.0,
"max_value": 250.0,
"default_value": 120.0,
"step": 0.1
},
"Diastolic": {
"field_name": "Diastolic",
"type": "float",
"min_value": 0.0,
"max_value": 250.0,
"default_value": 80.0,
"step": 0.1
},
"Occupation": {
"field_name": "Occupation",
"type": "dropdown",
"options": [
"Software Engineer" ,"Doctor" ,"Sales Representative","Teacher" ,"Nurse",
"Engineer" ,"Accountant" ,"Scientist", "Lawyer" ,"Salesperson" ,"Manager"
],
"default_value": "Software Engineer"
},
"Quality_of_Sleep": {
"field_name": "Quality_of_Sleep",
"type": "number",
"min_value": 0,
"max_value": 10,
"default_value": 0,
"step": 1
},
"Gender": {
"field_name": "Gender",
"type": "dropdown",
"options": [
"Male",
"Female"
],
"default_value": "Male"

},
"Physical_Activity_Level": {
"field_name": "Physical_Activity_Level",
"type": "number",
"min_value": 0,
"max_value": 200,
"default_value": 0,
"step": 1
},
"Stress_Level": {
"field_name": "Stress_Level",
"type": "number",
"min_value": 0,
"max_value": 10,
"default_value": 0,
"step": 1
},
"BMI_Category": {
"field_name": "BMI_Category",
"type": "dropdown",
"options": [
"Normal Weight",
"Obese",
"Overweight"
],
"default_value": "Normal Weight"
}
}
}
375 changes: 375 additions & 0 deletions models/sleep_disorder_predictor/data/dataset.csv

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions models/sleep_disorder_predictor/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import streamlit as st
import pickle
import pandas as pd # Import pandas to handle DataFrames
import numpy as np
import warnings
warnings.filterwarnings("ignore")

# Load the model and the scaler
model_path = 'models/sleep_disorder_predictor/saved_models/Model_Prediction.sav'
preprocessor_path = 'models/sleep_disorder_predictor/saved_models/preprocessor.sav'

# Load the pre-trained model and scaler using pickle
loaded_model = pickle.load(open(model_path, 'rb'))
preprocessor = pickle.load(open(preprocessor_path, 'rb'))

# Define the prediction function
def disease_get_prediction(Age, Sleep_Duration,
Heart_Rate, Daily_Steps,
Systolic, Diastolic, Occupation, Quality_of_Sleep, Gender,
Physical_Activity_Level, Stress_Level, BMI_Category):
# Create a DataFrame with the features using correct column names
features = pd.DataFrame({
'Age': [int(Age)],
'Sleep Duration': [float(Sleep_Duration)], # Changed to match expected name
'Heart Rate': [int(Heart_Rate)], # Changed to match expected name
'Daily Steps': [int(Daily_Steps)], # Changed to match expected name
'Systolic': [float(Systolic)],
'Diastolic': [float(Diastolic)],
'Occupation': [Occupation],
'Quality of Sleep': [int(Quality_of_Sleep)], # Changed to match expected name
'Gender': [Gender],
'Physical Activity Level': [int(Physical_Activity_Level)], # Changed to match expected name
'Stress Level': [int(Stress_Level)], # Changed to match expected name
'BMI Category': [BMI_Category] # Changed to match expected name
})

# Apply the preprocessor (make sure it expects a DataFrame)
preprocessed_data = preprocessor.transform(features)

# Make prediction
prediction = loaded_model.predict(preprocessed_data)

return prediction

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions models/sleep_disorder_predictor/predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from models.sleep_disorder_predictor.model import disease_get_prediction

def get_prediction(Age, Sleep_Duration,
Heart_Rate, Daily_Steps,
Systolic, Diastolic,Occupation,Quality_of_Sleep,Gender,
Physical_Activity_Level, Stress_Level, BMI_Category):

prediction = disease_get_prediction(Age, Sleep_Duration,
Heart_Rate, Daily_Steps,
Systolic, Diastolic,Occupation,Quality_of_Sleep,Gender,
Physical_Activity_Level, Stress_Level, BMI_Category)

message = ""

# Provide message based on the prediction value
if prediction==0:
message= "Insomnia"
elif prediction==1:
message = "No disorder"
elif prediction==2:
message = "Sleep Apnea"
else:
message="Invalid details."

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.
4 changes: 4 additions & 0 deletions pages/Sleep_Disorder_Predictor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from page_handler import PageHandler

page_handler = PageHandler("pages/pages.json")
page_handler.render_page("Sleep Disorder Predictor")
22 changes: 22 additions & 0 deletions pages/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@
}
]
},
"Sleep Disorder Predictor": {
"title": "Sleep Disorder Predictor",
"page_title": "Sleep Disorder Predictor",
"model_predict_file_path": "models/sleep_disorder_predictor/predict.py",
"model_function": "get_prediction",
"model_detail_function": "model_details",
"form_config_path": "form_configs/sleep_prediction.json",
"tabs": [
{
"name": "Sleep Disorder Predictor",
"type": "form",
"form_name": "Sleep Prediction Form"
},
{
"name": "Model Details",
"type": "model_details",

"problem_statement": "The model aims to predict the likelihood of an individual having a sleep disorder based on lifestyle, sleep quality, and health metrics.",
"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."
}
]
},

"Malware_Detection": {
"title": "PDF Malware Detection",
Expand Down

0 comments on commit 89c5053

Please sign in to comment.