Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from Utility.data_loader import (
|
| 4 |
+
load_train_series, load_train_events,
|
| 5 |
+
load_sample_submission, load_test_series
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Sleep Detection", layout="wide")
|
| 9 |
+
st.title("Sleep Detection")
|
| 10 |
+
|
| 11 |
+
st.markdown("""
|
| 12 |
+
### π About the App
|
| 13 |
+
|
| 14 |
+
This **Sleep Detection App** uses sensor data collected over time to predict sleep-related events such as *onset* or *wake-up*. The application allows users to analyze sleep patterns based on movement data and provides predictions using a machine learning model trained on labeled sensor events.
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
### π§Ύ Data Description
|
| 19 |
+
|
| 20 |
+
Each row in the dataset represents a time-stamped sensor reading with the following key columns:
|
| 21 |
+
|
| 22 |
+
- **series_id**: Unique identifier for a sleep session or user.
|
| 23 |
+
- **step**: Sequence number of the reading.
|
| 24 |
+
- **sensor_timestamp**: The time when the sensor reading was recorded.
|
| 25 |
+
- **anglez**: Z-axis body orientation angle (used as a feature).
|
| 26 |
+
- **enmo**: Euclidean Norm Minus One β a movement magnitude metric (used as a feature).
|
| 27 |
+
- **night**: Night identifier (used to separate sessions).
|
| 28 |
+
- **event**: The sleep-related label (e.g., `onset`, `wake`) indicating the event type.
|
| 29 |
+
- **event_timestamp**: Timestamp of the actual sleep event (used to calculate sleep duration).
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
### π€ App Capabilities
|
| 34 |
+
|
| 35 |
+
- Displays raw sensor data and sleep event counts.
|
| 36 |
+
- Trains an ML model (XGBoost) using movement features (`anglez`, `enmo`) to predict sleep events.
|
| 37 |
+
- Allows real-time prediction of sleep events based on user input.
|
| 38 |
+
- Displays evaluation metrics: **Accuracy**, **F1 Score**, **ROC AUC Score**.
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
""")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# --- Sidebar Radio Button ---
|
| 46 |
+
st.header("Select Dataset to View")
|
| 47 |
+
option = st.radio(
|
| 48 |
+
"Choose a dataset:",
|
| 49 |
+
("Train Events","Train Series", "Test Series", "Summary")
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# --- Load and Show Data Based on Selection ---
|
| 53 |
+
df = None
|
| 54 |
+
|
| 55 |
+
if option == "Train Events":
|
| 56 |
+
df = load_train_events()
|
| 57 |
+
st.subheader("Train Events")
|
| 58 |
+
st.dataframe(df.head())
|
| 59 |
+
|
| 60 |
+
elif option == "Sample Submission":
|
| 61 |
+
df = load_sample_submission()
|
| 62 |
+
st.subheader("Sample Submission")
|
| 63 |
+
st.dataframe(df.head())
|
| 64 |
+
|
| 65 |
+
elif option == "Train Series":
|
| 66 |
+
df = load_train_series()
|
| 67 |
+
st.subheader("Train Series (1M rows sample)")
|
| 68 |
+
st.dataframe(df.head())
|
| 69 |
+
|
| 70 |
+
elif option == "Test Series":
|
| 71 |
+
df = load_test_series()
|
| 72 |
+
st.subheader("Test Series")
|
| 73 |
+
st.dataframe(df.head())
|
| 74 |
+
|
| 75 |
+
elif option == "Summary":
|
| 76 |
+
st.subheader("Summary of All Key Datasets")
|
| 77 |
+
|
| 78 |
+
with st.expander("π Train Events"):
|
| 79 |
+
df_events = load_train_events()
|
| 80 |
+
st.dataframe(df_events.head())
|
| 81 |
+
st.write("Summary:")
|
| 82 |
+
st.dataframe(df_events.describe(include="all"))
|
| 83 |
+
|
| 84 |
+
with st.expander("π Sample Submission"):
|
| 85 |
+
df_sample = load_sample_submission()
|
| 86 |
+
st.dataframe(df_sample.head())
|
| 87 |
+
st.write("Summary:")
|
| 88 |
+
st.dataframe(df_sample.describe(include="all"))
|
| 89 |
+
|
| 90 |
+
with st.expander("π Train Series"):
|
| 91 |
+
df_series = load_train_series()
|
| 92 |
+
st.dataframe(df_series.head())
|
| 93 |
+
st.write("Summary:")
|
| 94 |
+
st.dataframe(df_series.describe())
|
| 95 |
+
|
| 96 |
+
with st.expander("π Test Series"):
|
| 97 |
+
df_test = load_test_series()
|
| 98 |
+
st.dataframe(df_test.head())
|
| 99 |
+
st.write("Summary:")
|
| 100 |
+
st.dataframe(df_test.describe())
|
| 101 |
+
|