diff --git a/UseCases/SmartWatch_Healthcare/Smartwatch_Report.ipynb b/UseCases/SmartWatch_Healthcare/Smartwatch_Report.ipynb new file mode 100644 index 00000000..49e33e0c --- /dev/null +++ b/UseCases/SmartWatch_Healthcare/Smartwatch_Report.ipynb @@ -0,0 +1,333 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "c3ac6379-96d4-4aa8-b45f-da0d92996f44", + "metadata": {}, + "source": [ + "
\n", + "

\n", + " Stress Detection Using Smartwatch Data
\n", + " \"Teradata\"\n", + "

\n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "d556bd95-c3d1-405c-8289-81c3d626e362", + "metadata": {}, + "source": [ + "

Introduction:

\n", + "

\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", + "

\n", + "\n", + "

\n", + "Proposed Solution:
\n", + "Smartwatch-Based Stress Detection Using AI/ML and Vantage Analytics
\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", + "

\n", + "\n", + "

\n", + "Benefits:\n", + "

\n", + "

\n" + ] + }, + { + "cell_type": "markdown", + "id": "58609d9c-43de-4301-af28-e02c401b05e5", + "metadata": {}, + "source": [ + "
\n", + "

1. Connect to Vantage, Import python packages and explore the dataset

" + ] + }, + { + "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": [ + "

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.

" + ] + }, + { + "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": [ + "

Getting Data for This Demo

\n", + "

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.

" + ] + }, + { + "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": [ + "

Optional step – We should execute the below step only if we want to see the status of databases/tables created and space used.

" + ] + }, + { + "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": [ + "
\n", + "

2. Data Exploration

" + ] + }, + { + "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": [ + "

The following datasets are used in this analysis to train, validate, and correlate stress detection:\n", + "

" + ] + }, + { + "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": [ + "
\n", + "

3. Dashboard and Insights

" + ] + }, + { + "cell_type": "markdown", + "id": "ef27510d-45f1-46a9-ae97-ba0f89d64cb0", + "metadata": { + "tags": [] + }, + "source": [ + "\n", + "

\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", + "

\n", + "\n", + "

\n", + "Key features of the dashboard:\n", + "

\n", + "

\n", + "\n", + "

Live Dashboard Link:\n", + "Smart Watch Dashboard\n", + "

\n", + "\n", + "

Dashboard Snapshot:

\n", + "\n", + "\n", + "

Insights:

\n", + "\n", + "

\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", + "

\n" + ] + }, + { + "cell_type": "markdown", + "id": "a4c645f2-d5c6-442a-8e45-6a97ab60c987", + "metadata": {}, + "source": [ + "
\n", + "4. Cleanup" + ] + }, + { + "cell_type": "markdown", + "id": "18c149c5-7f26-4926-be8a-829077e2f5bd", + "metadata": {}, + "source": [ + "

Databases and Tables

\n", + "

The following code will clean up tables and databases created above.

" + ] + }, + { + "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": [ + "" + ] + } + ], + "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 +} diff --git a/UseCases/SmartWatch_Healthcare/images/smartwatch.jpg b/UseCases/SmartWatch_Healthcare/images/smartwatch.jpg new file mode 100644 index 00000000..862025bf Binary files /dev/null and b/UseCases/SmartWatch_Healthcare/images/smartwatch.jpg differ