File size: 3,381 Bytes
1911e3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import streamlit as st
import pandas as pd
from Utility.data_loader import (
    load_train_series, load_train_events, 
    load_sample_submission, load_test_series
)

st.set_page_config(page_title="Sleep Detection", layout="wide")
st.title("Sleep Detection")
  
st.markdown("""

### πŸ“Š About the App



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.



---



### 🧾 Data Description



Each row in the dataset represents a time-stamped sensor reading with the following key columns:



- **series_id**: Unique identifier for a sleep session or user.

- **step**: Sequence number of the reading.

- **sensor_timestamp**: The time when the sensor reading was recorded.

- **anglez**: Z-axis body orientation angle (used as a feature).

- **enmo**: Euclidean Norm Minus One – a movement magnitude metric (used as a feature).

- **night**: Night identifier (used to separate sessions).

- **event**: The sleep-related label (e.g., `onset`, `wake`) indicating the event type.

- **event_timestamp**: Timestamp of the actual sleep event (used to calculate sleep duration).



---



### πŸ€– App Capabilities



- Displays raw sensor data and sleep event counts.

- Trains an ML model (XGBoost) using movement features (`anglez`, `enmo`) to predict sleep events.

- Allows real-time prediction of sleep events based on user input.

- Displays evaluation metrics: **Accuracy**, **F1 Score**, **ROC AUC Score**.



---

""")



# --- Sidebar Radio Button ---
st.header("Select Dataset to View")
option = st.radio(
    "Choose a dataset:",
    ("Train Events","Train Series", "Test Series", "Summary")
)

# --- Load and Show Data Based on Selection ---
df = None

if option == "Train Events":
    df = load_train_events()
    st.subheader("Train Events")
    st.dataframe(df.head())

elif option == "Sample Submission":
    df = load_sample_submission()
    st.subheader("Sample Submission")
    st.dataframe(df.head())

elif option == "Train Series":
    df = load_train_series()
    st.subheader("Train Series (1M rows sample)")
    st.dataframe(df.head())

elif option == "Test Series":
    df = load_test_series()
    st.subheader("Test Series")
    st.dataframe(df.head())

elif option == "Summary":
    st.subheader("Summary of All Key Datasets")

    with st.expander("πŸ“„ Train Events"):
        df_events = load_train_events()
        st.dataframe(df_events.head())
        st.write("Summary:")
        st.dataframe(df_events.describe(include="all"))

    with st.expander("πŸ“„ Sample Submission"):
        df_sample = load_sample_submission()
        st.dataframe(df_sample.head())
        st.write("Summary:")
        st.dataframe(df_sample.describe(include="all"))

    with st.expander("πŸ“„ Train Series"):
        df_series = load_train_series()
        st.dataframe(df_series.head())
        st.write("Summary:")
        st.dataframe(df_series.describe())

    with st.expander("πŸ“„ Test Series"):
        df_test = load_test_series()
        st.dataframe(df_test.head())
        st.write("Summary:")
        st.dataframe(df_test.describe())