Spaces:
Build error
Build error
| 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()) | |