Human Stress Detection Based On Sleeping Habits Through Machine Learning Algorithms
Human Stress Detection Based On Sleeping Habits Through Machine Learning Algorithms
---------------------------------------------------------------------***---------------------------------------------------------------------
Abstract - Stress is a mental or emotional state data, learn from it, and make informed predictions. In the realm
brought on by demanding or unavoidable circumstances, also of healthcare and well-being, machine learning's ability to parse
referred to as stressors. In order to prevent any unfavorable through large datasets and find patterns can be particularly life-
occurrences in life, it is crucial to understand human stress enhancing. This document will explore how machine learning,
levels. Sleep disturbances are related to a number of physical, through various learning models such as Supervised,
mental, and social problems. Unsupervised, and Ensemble Learning, can be applied to predict
This study's main objective is to investigate how human stress levels during sleep using psychological and physiological
stress might be detected using machine learning algorithms data.
based on sleep-related behaviors. Detecting and understanding
stress patterns during sleep can provide valuable insights into 2. LITERATURE REVIEW
individuals' overall stress levels and aid in the development of
targeted interventions for stress management. This project L. Rachakonda, A. K. Bapatla, S. P. Mohanty, and E.
focuses on the detection of human stress in and through sleep Kougianos, “SaYoPillow: Blockchain-Integrated Privacy-
using various sensing modalities and machine learning Assured IoMT Framework for Stress Management
techniques. The project employs a multimodal approach, Considering Sleeping Habits”, IEEE Transactions on
combining physiological signals, sleep-related data, and Consumer Electronics (TCE), Vol. 67, No. 1, Feb 2021, pp.
contextual information to capture comprehensive stress patterns 20-29.
during sleep. Considering today’s lifestyle, people just sleep forgetting the
Physiological signals such as heart rate, electro dermal benefits sleep provides to the human body. Smart-Yoga
activity, and respiratory patterns are collected using wearable Pillow (SaYoPillow) is proposed to help in understanding the
sensors, while sleep-related data, including sleep stages and relationship between stress and sleep and to fully materialize
sleep quality metrics, are obtained through polysomnography the idea of “Smart-Sleeping” by proposing an edge device.
and actigraphy. This data when given to the web application An edge processor with a model analyzing the physiological
performs the prediction through the ML model and gives the changes that occur during sleep along with the sleeping
predicted output. This project is made on a Decision Tree habits is proposed. Based on these changes during sleep,
Classifier with best hyper parameters. stress prediction for the following day is proposed. A user
interface is provided allowing the user to control the data
accessibility and visibility. SaYoPillow is novel, with
security features as well as consideration of sleeping habits
Key Words: Stress, Sleep disturbances, Human stress,
for stress reduction, with an accuracy of up to 96%.
Physiological signals, Polysomnography, Actigraphy
Eye Movement) stages of sleep. Non-physiological Python source code is now available under the GNU General
parameters such as the numberof sleeping hours, the range of Public License (GPL). Python is now maintained by a core
snoring, the sleeping position, and environmental conditions development team at the institute, although Guido van Rossum
can also affect the quality of sleep. These factors are still holds a vital role in directing its progress.
considered here in order to analyze sleeping habits. A
system is defined which can predict stress levels up to four Pandas
states: Low, High, Medium, very high stress.
3. METHODILOGY Pandas is an open-source library that is made mainly for
working with relational or labeled data both easily and
3.1 EXISTING SYSTEM intuitively. It provides various data structures and
operations for manipulating numerical data and time series.
Psychological stress is injurious to health. In existing system, This library is built on top of the NumPy library. It is fast and
stress is identified in face-to-face interview, communication or it has high performance & productivity for users. Pandas were
any other activities, where two or more people are analyzed by initially developed by Wes McKinney in 2008 while he was
another. Most of the existing system works either on person working at AQR Capital Management. He convinced the
interaction or on social networking stress data and not on body- AQR to allow him to open source the Pandas.
based sensor data. Some existing systems detect stress but not in Another AQR employee, Chang She, joined as the second
sleep. major contributor to the library in 2012. Over time many
versions of pandas have been released. The latest version of
the pandas is 1.4.1.
3.2 PROPOSED SYSTEM
NumPy
The proposed system aims to detect and analyze stress levels in
NumPy is a general-purpose array-processing package. It
individuals using machine learning techniques applied to
provides a highperformance multidimensional array object,
various data sources, such as physiological signals, sleep
and tools for working with thesearrays. It is the fundamental
patterns, activity levels, and self-reported data. The system
package for scientific computing with Python.
utilizes machine learning algorithms to analyze the collected
data and identify patterns indicative of stress. The system can
Besides its obvious scientific uses, NumPy can also be used
potentially detect signs of stress at an early stage, enabling
as an efficient multi- dimensional container of generic data.
timely interventions and support. Early detection can help
Array in NumPy is a table of elements (usually numbers), all
individuals proactively manage stress and prevent its escalation
of the same type, indexed by a tuple of positive integers. In
into more severe issues.
NumPy, number of dimensions of the array is called rank of
the array.
4.SYSTEM DESIGN
Streamlit
use, and rightfully so. an appropriate value for "k" based on experimentation.
• Internally, the KNN algorithm calculates the
distance (e.g., Euclidean distance) between the input
Matplotlib data point and all other data points in the training set.
• It then selects the "k" data points (nearest neighbors)
Matplotlib is an amazing visualization library in Python for 2D with the smallest distances.
plots of arrays. Matplotlib is a multi-platform data visualization • The algorithm counts the occurrences of each stress
library built on NumPy arrays and designed to work with the level category among these "k"neighbors and assigns the
broader SciPy stack. It was introduced by John Hunter in category with the highest count as the predicted stress
theyear 2002. level.
• KNN is a lazy learner, which means it does not build an
One of the greatest benefits of visualization is that it allows us explicit model during training. Instead, it memorizes the
visual access tohuge amounts of data in easily digestible training data and makes predictions based on it.
visuals. Matplotlib consists of several plots like line, bar, scatter,
histogram etc. Windows, Linux and macOS distributions have 5. Training the KNN Model
matplotlib and most of its dependencies as wheel packages.
• Train the KNN model using the training dataset. The
OS model will learn to classify thestress levels based on the
provided features.
Python OS module provides the facility to establish the
interaction between the user and the operating system. It offers
many useful OS functions that are used to perform OS-based 6. Making Predictions
tasks and get related information about operating system.
The OS comes under Python's standard utility modules. This • Use the trained KNN model to make stress level
module offers a portable way of using operating system predictions for the data points in thetesting set.
dependent functionality. • The model will assign a stress level category (e.g.,
Low/Normal, Medium Low,Medium, Medium High,
The Python OS module lets us work with the files and High) to each data point.
directories. To work with the OS module, we need to import the
OS module. IMPORT OS 7. Evaluation
5.IMPLEMENTATION • Evaluate the performance of the KNN model using
metrics such as accuracy,precision, recall, and F1-score.
1. Data Collection and Preprocessing
8. User Interface
• Collect a dataset containing various sleep-related
features, such as Snoring Rate, Respiration Rate, Body • Develop a user-friendly interface where users can input
Temperature, Limb Movement, Blood Oxygen, Eye their sleep-related data, such as Snoring Rate,
Movement, Sleeping Hours, and Heart Rate. Respiration Rate, etc
• The dataset should include labeled stress levels for • When a user submits the data, the KNN model will
each set of features (e.g., Low/Normal, Medium Low, predict the stress level, and the result will be displayed
Medium, Medium High, High). to the user.
• Preprocess the dataset by handling missing values and
outliers, if any. 9. Deployment
3. Data Splitting
• Split the dataset into a training set and a testing set.
Typically, you can use a 70-30 or 80-20 split for this
purpose.
4. Building the KNN Model
• Implement the KNN algorithm, which is a
supervised machine learning algorithm used for
classification tasks.
• In KNN, the "k" represents the number of nearest
neighbors to consider for making predictions. Choose
6.TESTING
7.RESULTS
6.1 Introduction
Testing objectives:
The main objective of testing is to uncover a host of errors, It shows the problem of the stress level detector hoe it works
systematically and with minimum effort and time. Stating and what is the problem statement.
formally, we can say, testing is a process of executing a program
with intent of finding an error.
6.2 Levels of Testing It shows the home page of the dataset of the stress level to
Code testing predict.
Specification Testing
8.CONCLUSION
1. The implementation of the KNN algorithm has demonstrated
its effectiveness in detecting stress during sleep. By analyzing • A. Khademi, Y. El-Manzalawy, L. Master, O. M.
various physiological and behavioral parameters such as heart Buxton and V. G. Honavar, "Personalized sleep
rate, respiratory rate, body movement, and sleep patterns, we parameters estimation from actigraphy: A machine
were able to classify instances of stress with a reasonable learning approach", Nat. Sci. Sleep, vol. 11, pp. 387-
degree of accuracy. 399, 2019.