Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
333 changes: 333 additions & 0 deletions UseCases/SmartWatch_Healthcare/Smartwatch_Report.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c3ac6379-96d4-4aa8-b45f-da0d92996f44",
"metadata": {},
"source": [
"<header>\n",
" <p style='font-size:36px;font-family:Arial; color:#F0F0F0; background-color: #00233c; padding-left: 20pt; padding-top: 20pt;padding-bottom: 10pt; padding-right: 20pt;'>\n",
" Stress Detection Using Smartwatch Data <br>\n",
" <img id=\"teradata-logo\" src=\"https://storage.googleapis.com/clearscape_analytics_demo_data/DEMO_Logo/teradata.svg\" alt=\"Teradata\" style=\"width: 125px; height: auto; margin-top: 20pt;\">\n",
" </p>\n",
"</header>"
]
},
{
"cell_type": "markdown",
"id": "d556bd95-c3d1-405c-8289-81c3d626e362",
"metadata": {},
"source": [
"<p style = 'font-size:20px;font-family:Arial'><b>Introduction:</b></p>\n",
"<p style='font-size:16px;font-family:Arial'>\n",
"With rising stress levels globally, there's a growing need for scalable, continuous, and non-invasive stress monitoring solutions. Traditional methods like self-reported surveys and periodic clinical assessments are subjective, episodic, and not feasible for real-time monitoring. Smartwatches and other wearable devices are increasingly equipped with sensors capable of capturing physiological data, offering a powerful alternative. However, key challenges still remain:\n",
"<ul style='font-size:16px;font-family:Arial'>\n",
" <li>Limited access to advanced biosensors like EDA or EMG in most consumer-grade smartwatches.</li>\n",
" <li>High-frequency raw signal data requires extensive preprocessing and transformation for analysis.</li>\n",
" <li>Lack of labeled data for stress events, especially in naturalistic (non-lab) settings.</li>\n",
" <li>Difficulties in correlating physiological signals with contextual behaviors like sleep or activity levels.</li>\n",
"</ul>\n",
"\n",
"<p style='font-size:16px;font-family:Arial'>\n",
"<b>Proposed Solution:</b><br>\n",
"Smartwatch-Based Stress Detection Using AI/ML and Vantage Analytics<br>\n",
"Leverage data from widely available smartwatch sensors (e.g., ECG, BVP, Accelerometer) to detect stress using machine learning models. Extract block-wise statistical features using Vantage’s in-database processing capabilities to ensure scalable and parallelized analysis. Augment stress detection by integrating sleep stage classification, enabling holistic health insights. The end-to-end solution allows for identifying high-stress intervals, correlating them with sleep and activity behavior, and ultimately enabling personalized wellness interventions.\n",
"</p>\n",
"\n",
"<p style='font-size:16px;font-family:Arial'>\n",
"<b>Benefits:</b>\n",
"<ul style='font-size:16px;font-family:Arial'>\n",
" <li>Early and continuous detection of stress using physiological signals from smartwatches.</li>\n",
" <li>Improved individual well-being through timely recommendations and interventions.</li>\n",
" <li>Integration of stress detection with sleep analytics to provide contextual insights.</li>\n",
" <li>Scalable and parallel in-database feature extraction using Teradata Vantage.</li>\n",
" <li>Support for future expansion to lifestyle-based recommendations or health apps.</li>\n",
"</ul>\n",
"</p>\n"
]
},
{
"cell_type": "markdown",
"id": "58609d9c-43de-4301-af28-e02c401b05e5",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;\">\n",
"<p style = 'font-size:20px;font-family:Arial'><b>1. Connect to Vantage, Import python packages and explore the dataset</b></p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bab4f571-321f-4ac2-b295-0a4de3c3dccc",
"metadata": {},
"outputs": [],
"source": [
"#import libraries\n",
"import getpass\n",
"from teradataml import *\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"warnings.simplefilter(action='ignore', category=DeprecationWarning)\n",
"warnings.simplefilter(action='ignore', category=RuntimeWarning)\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
"\n",
"display.max_rows=5"
]
},
{
"cell_type": "markdown",
"id": "13fffe9b-2c06-462b-8722-af913b073adb",
"metadata": {},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>We will be prompted to provide the password. We will enter the password, press the Enter key, and then use the down arrow to go to the next cell.</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c45bc8b-1440-46b7-8837-dc112791156f",
"metadata": {},
"outputs": [],
"source": [
"%run -i ../startup.ipynb\n",
"eng = create_context(host = 'host.docker.internal', username='demo_user', password = password)\n",
"print(eng)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "31d30f3f-3989-42c2-a5a3-b32482de1aa3",
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"execute_sql('''SET query_band='DEMO=Smartwatch_Report.ipynb;' UPDATE FOR SESSION; ''')"
]
},
{
"cell_type": "markdown",
"id": "441b7eb9-57f2-4dbb-88d6-88345e66df55",
"metadata": {},
"source": [
"<p style = 'font-size:18px;font-family:Arial'> <b>Getting Data for This Demo</b></p>\n",
"<p style = 'font-size:16px;font-family:Arial'>We have provided data for this demo on cloud storage. We have the option of either running the demo using foreign tables to access the data without using any storage on our environment or downloading the data to local storage, which may yield somewhat faster execution. However, we need to consider available storage. There are two statements in the following cell, and one is commented out. We may switch which mode we choose by changing the comment string.</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cdb99534-8c49-4ffd-99e0-64145cf706c8",
"metadata": {},
"outputs": [],
"source": [
"# takes about 10 minutes\n",
"%run -i ../run_procedure.py \"call get_data('DEMO_HealthcareSW_local');\""
]
},
{
"cell_type": "markdown",
"id": "27215d11-6b1f-49a0-b181-d6fd41e394a8",
"metadata": {},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>Optional step – We should execute the below step only if we want to see the status of databases/tables created and space used.</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3205e46-ec11-47ea-b9dc-6db9fc177d83",
"metadata": {},
"outputs": [],
"source": [
"%run -i ../run_procedure.py \"call space_report();\""
]
},
{
"cell_type": "markdown",
"id": "19887947-1b78-44dd-9f42-7d888a278cca",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;\">\n",
"<p style = 'font-size:20px;font-family:Arial'><b>2. Data Exploration </b></p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c381685d-eea2-4a13-b1a4-e0cbb304af98",
"metadata": {},
"outputs": [],
"source": [
"db_list_tables('DEMO_HealthcareSW')"
]
},
{
"cell_type": "markdown",
"id": "38c44a83-5d30-40c9-b4ff-6abffb1f7feb",
"metadata": {},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>The following datasets are used in this analysis to train, validate, and correlate stress detection:\n",
"<ul style='font-size:16px;font-family:Arial'>\n",
" <li><b>StressFeatures_train:</b> Processed physiological features derived from smartwatch signals.</li>\n",
" <li><b>Predictions_on_Sleep_Data:</b> Predicted stress levels correlated with sleep metrics.</li>\n",
" <li><b>Wesad:</b> Multimodal raw dataset used for initial feature extraction and labeling.</li>\n",
"</ul></p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c682ca44-473a-4a65-b2c3-fd9bcb70bfbd",
"metadata": {},
"outputs": [],
"source": [
"df_stress = DataFrame(in_schema(\"DEMO_HealthcareSW\", \"StressFeatures_train \"))\n",
"df_stress"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b092bdda-eb13-4645-9040-c6a9e31c038b",
"metadata": {},
"outputs": [],
"source": [
"df_sleep = DataFrame(in_schema(\"DEMO_HealthcareSW\", \"Predictions_on_Sleep_Data\"))\n",
"df_sleep"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60002679-19cf-4dea-8092-620ea8761b3c",
"metadata": {},
"outputs": [],
"source": [
"df_wesad = DataFrame(in_schema(\"DEMO_HealthcareSW\", \"Wesad \"))\n",
"df_wesad"
]
},
{
"cell_type": "markdown",
"id": "475d03e4-d72f-4f2c-a1f4-7f7692a67409",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;\">\n",
"<p style = 'font-size:20px;font-family:Arial'><b>3. Dashboard and Insights </b></p>"
]
},
{
"cell_type": "markdown",
"id": "ef27510d-45f1-46a9-ae97-ba0f89d64cb0",
"metadata": {
"tags": []
},
"source": [
"\n",
"<p style='font-size:16px;font-family:Arial'>\n",
"This section showcases a visual summary of our Smartwatch Stress Detection analysis. The interactive dashboard provides insights into how stress (detected via physiological signals like heart rate and BVP) correlates with sleep behaviors such as deep sleep (SWS), insomnia, and restlessness.\n",
"</p>\n",
"\n",
"<p style='font-size:16px;font-family:Arial'>\n",
"Key features of the dashboard:\n",
"<ul style='font-size:16px;font-family:Arial'>\n",
" <li>Scatter plot showing relationship between hours spent in stress and percentage of deep sleep (Stage 3 and 4).</li>\n",
" <li>Pie charts representing distribution of work shifts, and conditions such as sleep apnea, insomnia, and restlessness.</li>\n",
" <li>Breakdown of subject sleep characteristics and working patterns to identify potential lifestyle factors contributing to stress.</li>\n",
"</ul>\n",
"</p>\n",
"\n",
"<p style='font-size:16px;font-family:Arial'><b>Live Dashboard Link:</b>\n",
"<a href=\"https://superset.env.ci.clearscape.teradata.com/superset/dashboard/e7046cdf-79da-4fc3-92ce-53794185fa8d/?permalink_key=P62LM9lLmRw&standalone=true#TAB-BRrqQIMwv5yxxeF-VL19c\" target=\"_blank\">Smart Watch Dashboard</a>\n",
"</p>\n",
"\n",
"<p style='font-size:16px;font-family:Arial'><b>Dashboard Snapshot:</b></p>\n",
"<img src=\"images/smartwatch.jpg\" style=\"border: 4px solid #404040; border-radius: 10px;\"/>\n",
"\n",
"<p style='font-size:16px;font-family:Arial'><b>Insights:</b></p>\n",
"<ul style='font-size:16px;font-family:Arial'>\n",
" <li>There is a general trend indicating that individuals with higher stress levels often experience reduced deep sleep.</li>\n",
" <li>Majority of the subjects do not report conditions like insomnia or sleep apnea, indicating the dataset is relatively healthy but still stress-affected.</li>\n",
" <li>Work shift variability (e.g., irregular shifts) might be contributing to disrupted sleep and elevated stress.</li>\n",
"</ul>\n",
"<p style='font-size:16px;font-family:Arial'>\n",
"Together, these visuals provide compelling evidence that smartwatch data can reliably reflect real-world stress and sleep interactions, opening pathways for personalized health monitoring.\n",
"</p>\n"
]
},
{
"cell_type": "markdown",
"id": "a4c645f2-d5c6-442a-8e45-6a97ab60c987",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;\">\n",
"<b style = 'font-size:20px;font-family:Arial;'>4. Cleanup</b>"
]
},
{
"cell_type": "markdown",
"id": "18c149c5-7f26-4926-be8a-829077e2f5bd",
"metadata": {},
"source": [
"<p style = 'font-size:18px;font-family:Arial;'> <b>Databases and Tables </b></p>\n",
"<p style = 'font-size:16px;font-family:Arial;'>The following code will clean up tables and databases created above.</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9d409aaa-8828-4687-837c-6d4cafa469b9",
"metadata": {},
"outputs": [],
"source": [
"%run -i ../run_procedure.py \"call remove_data('DEMO_HealthcareSW');\" # Takes 10 seconds"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00bc0bce-21ec-420c-bbf6-0df84c1005b5",
"metadata": {},
"outputs": [],
"source": [
"remove_context()"
]
},
{
"cell_type": "markdown",
"id": "c5c30f77-0da7-48c0-a8a9-e69b0c4b3b51",
"metadata": {},
"source": [
"<footer style=\"padding-bottom: 35px; background: #f9f9f9; border-bottom: 3px solid #00233C\">\n",
" <div style=\"float: left; margin-top: 14px;\">ClearScape Analytics™</div>\n",
" <div style=\"float: right;\">\n",
" <div style=\"float: left; margin-top: 14px;\">Copyright © Teradata Corporation - 2025. All Rights Reserved.</div>\n",
" </div>\n",
"</footer>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.