Spaces:
Sleeping
Sleeping
Commit ·
63a679d
1
Parent(s): 26de386
Upload 2 files
Browse files
eda.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
#membuat function untuk nantinya dipanggil di app.py
|
| 9 |
+
def run():
|
| 10 |
+
st.title('Welcome to Explaration Data Analysis')
|
| 11 |
+
|
| 12 |
+
#menampilkan eda
|
| 13 |
+
st.title('Sleep Disorder Distribution')
|
| 14 |
+
image = Image.open('1.png')
|
| 15 |
+
st.image(image, caption='figure 1')
|
| 16 |
+
#menampilkan penjelasan
|
| 17 |
+
with st.expander('Explanation'):
|
| 18 |
+
st.caption('''Berdasarkan bar plot di atas, dapat diketahui bahwa lebih banyak orang yang tidak mengalami gangguan tidur(normal),
|
| 19 |
+
perbandingan orang yang mengalami sleep apnea maupun insomnia tidak sangat tipis.
|
| 20 |
+
''')
|
| 21 |
+
|
| 22 |
+
#menampilkan eda
|
| 23 |
+
st.title('BMI Category Distribution')
|
| 24 |
+
image = Image.open('2.png')
|
| 25 |
+
st.image(image, caption='figure 2')
|
| 26 |
+
image = Image.open('3.png')
|
| 27 |
+
st.image(image, caption='figure 3')
|
| 28 |
+
#menampilkan penjelasan
|
| 29 |
+
with st.expander('Explanation'):
|
| 30 |
+
st.caption('''
|
| 31 |
+
Berdasarkan plot di atas:
|
| 32 |
+
- lebih banyak pasien yang memiliki berat badan normal
|
| 33 |
+
- namun tidak sedikit pula pasien yang memiliki masalah berat badan overweight
|
| 34 |
+
- kebanyakan pasien yang memiliki berat badan overweight yaitu wanita
|
| 35 |
+
- sedangkan pasien yang memiliki berat badan normal di dominasi oleh pria
|
| 36 |
+
''')
|
| 37 |
+
|
| 38 |
+
#menampilkan eda
|
| 39 |
+
st.title('Daily Step by Occupation')
|
| 40 |
+
image = Image.open('4.png')
|
| 41 |
+
st.image(image, caption='figure 4')
|
| 42 |
+
#menampilkan penjelasan
|
| 43 |
+
with st.expander('Explanation'):
|
| 44 |
+
st.caption('''Berdasarkan bar diatas dapat kita lihat bahwa pekerja yang miliki jumlah langkah harian paling banyak ialah seorang perawat,
|
| 45 |
+
namun yang memiliki jumlah langkah harian paling sedikit ialah sales representative''')
|
model.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import pickle
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def run():
|
| 7 |
+
# Load All Files
|
| 8 |
+
|
| 9 |
+
with open('final_model.pkl', 'rb') as file:
|
| 10 |
+
final_model = pickle.load(file)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Gender= st.selectbox("Gender", ["Male", "Female"])
|
| 14 |
+
Occupation = st.selectbox("Occupation", ["Software Engineer", "Doctor", "Sales Representative", "Teacher", "Nurse",
|
| 15 |
+
"Engineer", "Accountant", "Scientist", "Lawyer", "Salesperson", "Manager"])
|
| 16 |
+
Sleep_Duration = st.selectbox("Sleep_Duration", [6.1, 6.2, 5.9, 6.3, 7.8, 6. , 6.5, 7.6, 7.7, 7.9, 6.4, 7.5, 7.2, 5.8,
|
| 17 |
+
6.7, 7.3, 7.4, 7.1, 6.6, 6.9, 8. , 6.8, 8.1, 8.3, 8.5, 8.4, 8.2])
|
| 18 |
+
Physical_Activity_Level = st.selectbox("Physical_Activity_Level", [42, 60, 30, 40, 75, 35, 45, 50, 32, 70,
|
| 19 |
+
80, 55, 90, 47, 65, 85])
|
| 20 |
+
Stress_Level = st.selectbox("Stress_Level", [6, 8, 7, 4, 3, 5])
|
| 21 |
+
BMI_Category = st.selectbox("BMI_Category", ["Overweight", "Normal", "Obese", "Normal Weight"])
|
| 22 |
+
Heart_Rate = st.selectbox("Heart_Rate", [77, 75, 85, 82, 70, 80, 78, 69, 72, 68, 76, 81, 65, 84, 74, 67, 73, 83, 86])
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
st.write('In the following is the result of the data you have input : ')
|
| 26 |
+
|
| 27 |
+
data_inf = pd.DataFrame({
|
| 28 |
+
"Gender" : Gender,
|
| 29 |
+
"Occupation" : Occupation,
|
| 30 |
+
"Sleep Duration" : Sleep_Duration,
|
| 31 |
+
"Physical Activity Level" : Physical_Activity_Level,
|
| 32 |
+
"Stress Level" : Stress_Level,
|
| 33 |
+
"BMI Category" : BMI_Category,
|
| 34 |
+
"Heart Rate" : Heart_Rate,
|
| 35 |
+
}, index=[0])
|
| 36 |
+
|
| 37 |
+
st.table(data_inf)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if st.button(label='predict'):
|
| 41 |
+
|
| 42 |
+
# Melakukan prediksi data dummy
|
| 43 |
+
scaler = scaler.transform(input)
|
| 44 |
+
y_pred_inf = final_model.predict(data_inf)
|
| 45 |
+
|
| 46 |
+
st.write("Here is a prediction of the People Who Have Sleep Disorder: ")
|
| 47 |
+
if y_pred_inf[0] == 1:
|
| 48 |
+
st.subheader("The Diagnosis is:")
|
| 49 |
+
prediction = 'Sleep Apnea'
|
| 50 |
+
|
| 51 |
+
if y_pred_inf[0] == 2:
|
| 52 |
+
st.subheader("This People Diagnosed Insomnia")
|
| 53 |
+
prediction = 'Insomnia'
|
| 54 |
+
|
| 55 |
+
else:
|
| 56 |
+
st.subheader("This People Normal")
|
| 57 |
+
prediction = 'Normal'
|
| 58 |
+
|
| 59 |
+
st.subheader('Based on user input, the model predicted: ')
|
| 60 |
+
st.header(y_pred_inf)
|