Professional Documents
Culture Documents
DIPLOMA THESIS
CONTINUOUS HEALTH
MONITORING FOR DETECTING
SITUATIONS OF DISTRESS
Supervisor
Lect. Ph.D. Radu D. Găceanu
Author
Daniela Crăciun
2017
UNIVERSITATEA BABEŞ-BOLYAI CLUJ-NAPOCA
FACULTATEA DE MATEMATICĂ ŞI INFORMATICĂ
SPECIALIZAREA INFORMATICA ENGLEZĂ
LUCRARE DE LICENŢĂ
SISTEM DE MONITORIZARE
PENTRU INTERVENŢII ÎN
SITUAŢII DE URGENŢĂ
Conducător ştiinţific
Lect. Ph.D. Radu D. Găceanu
Absolvent
Crăciun Daniela
2017
Abstract
The purpose of this thesis is to introduce a system structure for monitoring activity level and
detecting dangerous situations for the elderly or people that have mobility issues. This system
uses an ensemble classification method to distinguish between various levels of activity intensity
and threshold-based mechanisms to sense whether a person has an abnormal heart rate or is
at risk of falling. The system proposed should not be considered as an actual emergency tool,
but rather as a first step in this direction. If a person has serious health issues, it is advised
they be monitored permanently.
The proposed system has three parts. The sensor unit employs two devices that mine envi-
ronment information from sensors and measure heart rate continuously. The main application
unit is in charge of ensuring proper routing between the other elements of the system and main-
taining synchronization between components of the sensor unit. The coordination of the devices
in the sensor unit is done by using a timestamp-based method to accurately represent the state
of the person wearing the two devices. The main unit converts received data into structured
input, which is forwarded to the third component of the system: the prediction unit. A trained
model which predicts activity level and the rules on which heart rate is analyzed reside in the
prediction module.
At the beginning of the thesis, the intention is to build a knowledge base on ensemble
methods, what are they and how do they perform, while extensively detailing the key algorithm
used by us: random forests. The next chapter describes how the sensors present on different
wearable devices work and fetch information from the environment, while also mentioning the
importance of vital signs tracking. The next chapter introduces the rule behavior for the
heart status monitoring, the fall detection procedure and the dataset chosen for processing.
Another interesting point is the analysis side which describes what results has the application
yielded under different configurations. In the last chapter, the application is presented, both
from a structural and abstract point of view, while also addressing the central components
of the system and the communication between units. The last chapter also contains a user
manual, which aims to provide useful advice to a person interested in setting up and using the
application. Finally, the conclusions and the future work are presented.
This work is the result of my own activity. I have neither given nor received unauthorized
assistance on this work.
Daniela Crăciun
Contents
List of Figures 3
List of Tables 4
Introduction 5
1 Ensemble methods 7
1.1 What are ensemble methods? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Methods of constructing ensembles . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.1 Bagging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.2 Boosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Combination of base learners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.1 Averaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.2 Voting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Random forests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4.1 Decision tree mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.4.2 Out-of-bag estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.3 Split selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1
CONTENTS 2
Bibliography 39
List of Figures
3
List of Tables
4
Introduction
As physical data tracking devices become smaller, cheaper and more accessible, they will be
considered for further usage in various contexts. Wearables available to the public have shown
a promising result in helping recovering patients and helping with the management of various
diseases. Unfortunately, the data is seldom integrated into programmatic systems that offer
options beyond monitoring and filtering data.
Heart rate (HR) is measured as beats per minute (bpm) and has a long history of being
tracked that way because it is readily and easily measurable by simple palpation of an artery.
Also, it provides an estimate that is normalized to time.
Analysis performed on HR is becoming a common, noninvasive tool (due to the latest
technologies which allow the wearer of the tracking device free movement) for studies. A
limitation when using HR monitoring techniques is that it is challenging to identify if the
fluctuation is caused by physical or mental activity, especially when the difference between
two heart-rate states is minimal [15]. A possible solution is also taking movement signals into
account when examining the activity level of an individual. This way, the study becomes more
difficult but can also gather more data and detect with a higher accuracy the activity levels.
The first and primary purpose of this thesis is to build a classification model based on
HR and movement sensor (gyroscope, accelerometer, and magnetometer) data. The second
objective of this thesis is to develop a threshold-based system for detecting irregularities in the
health of the wearer depending on sensor measurements. The third purpose is to develop an
interface for different sensor devices, through which they can be able to communicate with a
trained model. As a general idea, this system must have end-to-end capabilities to provide
useful information to individuals that need to care for others. This system will allow the care
receivers to get back some of their independence, without the people who take care of them
losing grasp on their state.
Movement signals data can be retrieved from any device that has and IMU (Inertial Mea-
surement Unit composed of accelerometer, gyroscope, and magnetometer). The data is in 3D
format, meaning that each reading of a sensor has 3 data points, each corresponding to an
axis. HR data can arrive from a device capable of obtaining heart rate measurements in a
beats-per-minute format and is capable of forwarding it.
The first chapter, Ensemble methods, provides an exploration of the world of ensembles,
defining them and presenting the various ways in which they can be built. Finally, it provides
an in-depth explanation of the different types of ensembles and expands on the random forest
5
INTRODUCTION 6
method. Finally, this chapter also provides details on various ways in which the algorithm can
be tuned to yield better results.
The second chapter, Sensor data processing, presents some technical details on how the
IMU (inertial measurement unit) works and how the extraction of the environment data from
sensors (accelerometer, gyroscope, and magnetometer) is done. Another topic breached in this
chapter is that of personal physical data monitoring, providing details about the various devices
that measure heart rate and other vital signs. Also introduced are ways to filter the sensor
data to make it more reliable when processing it. This chapter also describes suggestions and
solutions from healthcare experts on how to monitor an individual efficiently.
The third chapter, Our approach: Continuous health monitoring, contains a presen-
tation of the application, providing an in-depth view of the motivation behind it. Also stated
are the algorithms employed for fall detection, the rule-based system used for heart rate ir-
regularities and a presentation of the dataset chosen, providing experiments that illustrate the
decisions we make in our system.
The last chapter, Pulse Review (PULSER) Application, introduces an architectural
point of view, detailing all the components of the system and the interaction between them.
Also stated are implementation details and a thorough user manual, which can aid the user in
setting up and using the application.
Finally, there are the conclusions and future work section, where ideas to improve further
the current system and findings reached while implementing it are provided.
List of publications:
• Crăciun Daniela. Continuous physical health monitoring and classification for distress
detection. Sesiunea de Comunicări Ştiinţifice ale Studentilor, Cluj-Napoca (Romania),
June 26, 2017. –accepted
Chapter 1
Ensemble methods
In this chapter, a short theoretical primer on ensemble methods is presented. Section 1.1
describes what ensemble methods are, while section 1.2 provides an overview on how these
methods are constructed. Section 1.3 mentions the way in which ensembles choose a result,
while section 1.4 focuses on the random forests algorithm, more specifically on its structure,
performance, and variables.
• Averaging methods, in which the driving principle is to build several estimators inde-
pendently and then to average their predictions. For example, bagging methods, forests
of randomized trees
• Boosting methods, in which base estimators are built sequentially, and one tries to
reduce the bias of the combined estimator. The motivation is to combine several weak
models to produce a powerful ensemble. For example, AdaBoost, gradient tree boosting
There are many reasons for choosing an ensemble method over other typical classifiers.
From a statistical point of view, a combination of multiple classifier outputs reduces the risk
of selecting a poorly performing classifier. They also perform well on a large amount of data,
since a single classifier may not be able to handle it, providing the ability to train on different
data partitions [21].
7
CHAPTER 1. ENSEMBLE METHODS 8
1.2.1 Bagging
The naming for bagging is a portmanteau word, a combination between bootstrap and aggre-
gating. As the name obviously suggests, the two most important concepts that reside behind
this method are bootstrap and aggregation [6]. Bagging adopts the bootstrap distribution for
generating different base learners.
Bootstrap sampling [16] is used to obtain subsets from the original data for usage in
training. Bootstrapping aims to resample (with replacement) from the sample data at hand
and create a large number of samples. Since replacement (meaning we can select the same
value multiple times) is allowed, some samples may appear more than once, and some may be
ignored entirely and new bootstrap samples most likely will not identical to our initial sample.
For example, if we have the sample of integers S = {2, 4, 5, 6, 6} possibilities of bootstrap
samples are S1 = {2, 5, 5, 6, 6}, S2 = {4, 5, 6, 6, 6}, S3 = {4, 6, 6, 6, 6}, S4 = {4, 4, 2, 6, 6} and so
on.
Bagging has two different strategies in aggregating the results it obtains: voting for classifi-
cation and averaging for regression. In classification, the input is forwarded to base classifiers,
which then individually reach a conclusion. Afterward, their outputs are collected, and each
one of them votes for the predicted class. The winning label (depending on what kind of voting
procedure is employed) is used as the final prediction. Bagging can deal both with binary
classification as well as multi-class classification [42].
A general procedure for a classifying bagging ensemble method when dealing with a multi-
class problem:
CHAPTER 1. ENSEMBLE METHODS 9
for i = 1 to k do
Create training set Di from D
Build a base classifier Ci from Di
end for
for each test record x in T do
C*(x) = Voting(C1 (x), C2 (x), ..., Ck (x))
end for
where D denotes the original training data, k denotes the number of base classifiers, and t is
the test sample.
1.2.2 Boosting
Boosting represents a suite of algorithms which convert an individual weak learner into a
powerful learner. Briefly, boosting works by training a set of learners sequentially and combining
them for prediction, where the later learners focus more on the mistakes of the earlier learners
[42]. The general boosting procedure is quite simple and is succinctly described below:
Initialize distribution D as Dt
for t = 1 to T do
Apply L on Dt to obtain Bt
Obtain error et of Bt
Adjust Dt to obtain Bt+1
end for
for each learning round x in T do
B*(x) = Combine(B1 (x), B2 (x), ..., Bk (x))
end for
where the input is a sample set of data denoted as D, the base learning algorithm is L and the
number of learning rounds T .
Bias indicates the error that is introduced by a simple model that tries to approximate a
complex real-life problem. So, if a connection is complicated and a parametric algorithm is
employed, then it will surely result in some bias in the calculation of f (x). A low bias suggests
that the algorithm makes fewer assumptions about the structure of the target function and a
high bias means it makes more assumptions.
Variance refers to the amount by which the estimate f (x) shaped by the algorithm would
change if estimation is done with another training set. Ideally, f (x) should not fluctuate too
much among sets used for training. However, if a method has significant variance, then small
alterations in the training data can produce substantial changes in f (x).
1.3.1 Averaging
Averaging is a fundamental method of combining numeric outputs. It is usually performs on
regression-type problems, and combines the output of individual learners to obtain the final
prediction of a real-valued variable.
Simple averaging obtains the combined output by averaging the outputs of individual
learners directly. Its simplicity and effectiveness make the simple averaging one of the most
popular methods and represents the first choice in many real applications. It gives the combined
H(x) as specified in definition 1.3.1.
1
PT
Definition 1.3.1 H(x) = T i=1 hi (x) where the T is the number of independent classifiers.
Weighted averaging obtains the merged output by averaging the outputs of individual
learners with different weights implying different importance. It is easy to see that simple
averaging, which can be regarded as taking equal weights for all individual learners, is a special
case of weighted averaging [42].
Definition 1.3.2 H(x) = T1 Ti=1 wi hi (x) where the T is the number of independent classifiers
P
1.3.2 Voting
Voting is one of the most used combination methods for categorical outputs and is usually used
in classification problems.
Majority voting is the most popular voting method. Each classifier votes for one class
label, and the definitive output class label is the one that gets more than half of the votes; if
none of the class labels receives more than half of the votes, a rejection option will be given, and
the merged classifier makes no prediction. The output class label of the ensemble is mentioned
in 1.3.3.
if Ti=1 hji (x) > 21 lk=1 Ti=1 hji (x)
c P P P
j
Definition 1.3.3 H(x) =
rejection otherwise
where the T is the number of independent classifiers and l is the number of labels.
CHAPTER 1. ENSEMBLE METHODS 11
Plurality voting is in contrast to majority voting which requires the final winner to take
at least half of votes. This method takes the class label which receives the largest number of
votes as the final winner and ties are broken swiftly, with no priority given to a classifier over
others. The output class label of the ensemble is shown in definition 1.3.4.
Definition 1.3.4 H(x) = cmax(PT hji (x)) where the T is the number of independent classifiers.
i=1
Weighted voting gives more power to the stronger classifiers in voting if the individual
classifiers have different weights assigned [42]. By assigning more weight to a classifier, its input
will have more significance in the final prediction. The output class label of the ensemble is
presented in 1.3.5.
Definition 1.3.5 H(x) = cmax(PT wi hj (x)) where the T is the number of independent classi-
i=1 i
fiers.
Because in a random tree the final result is obtained by quorum election, it best fits into
the averaging family of ensemble methods. The basis of the system is the construction of a set
of classifiers, and then classification on new data points is performed by taking a weighted vote
of their predictions.
The random forest algorithm follows these steps when performing, assuming N cases are in
the training set and M input variables are present:
• A m < M is chosen so that at every node, m variables are selected at random out of the
M. The value of m is constant as the forest grows continuously
• A split is performed and the result that yields the best split is selected for further pro-
cessing
• Each tree grows as much as possible as denoted by the initial parameters of the algorithm
(the growing stops at a certain number of levels in the tree, as decided beforehand, or
keeps growing until all its leaves are pure, meaning that no further split can be performed)
• Prediction is performed by aggregating the results of all the classifiers (by voting or
averaging)
CHAPTER 1. ENSEMBLE METHODS 12
The central concepts that shape a decision tree are (its structure is also seen in figure 1.1):
• The root node represents the entire sample, which gets divided further into two or more
subsets
• Terminal nodes (also called leaves) are nodes that do not split any further (also known
as pure)
• Splitting is the action of dividing a node into (usually) two or more sub-nodes
• Pruning is the opposite of splitting and is the removal of the sub-nodes of a decision node
An important aspect of the decision tree in practice is the configuration of the parameters.
Some important criteria that can be adjusted are:
• Minimum samples split number, which denotes the minimum numbers of sample required
to split a node. This value helps in reducing overfitting.
CHAPTER 1. ENSEMBLE METHODS 13
• Maximum depth of a tree limits the vertical depth up to which pruning is needed.
• Split choice strategy, which refers to the usage of a criterion for splitting or random choice
There are two principal types of decision trees, based on the target variable: categorical
(for example, binary outcomes such as yes or no) or continuous (for example, trying to find a
value for the income of an individual). Some of the main advantages of using decision trees as
base learners in the context of an ensemble are:
Of course, they also have some disadvantages such as a tendency to overfit and reduced per-
formance on continuous variables [12].
Since random forests is a bagging method, an ensemble of trees is generated by drawing
subsamples from the initial training data and fitting a single tree to each sample. Randomness
is introduced not only by the bootstrapping but also by the arbitrary restriction of the set of
predictor variables to select from at every split, producing even more distinct trees.
Even though these variables may not be the best performing on the current split, their
selection may reveal intercommunication effects with other variables that otherwise would have
been missed. This actual node is defined by a combination of predictor values, that is specified
by all past splits in the same branch of the tree. This search strategy leads to a variable
selection pattern where a predictor variable that is weakly or not at all correlated with the
response but is associated with another important predictor variable may appear equally well
suited for splitting. [7].
The random forest (as seen in figure 1.2) takes the notion of a decision tree to the next level
by fusing them with the concept of an ensemble and aggregating each independent prediction.
it is marked as uncounted. For a test situation, its posterior probability can be estimated by
averaging the following probabilities of non-uncounted nodes into which it falls.
The examination of error estimates for bagged classifiers in [6], gives proof to show that
the out-of-bag estimate is as reliable as using a test set of the same size as the training set.
Hence, using the out-of-bag error estimate eliminates the need for a set-aside test set. Since
the error rate decreases as the number of combinations increases, the out-of-bag estimates will
tend to overestimate the current error rate. A clear distinction between out-of-bag estimates
and cross-validation, where bias is present, but its range is unknown, is that the former are
unbiased.
When discussing the information gain criterion, it is important to mention the purity of a
node and what does it mean. An impure node requires more information to describe it, and
as the purity increases, it requires less information to detail. Entropy estimates the level of
impurity in a collection of examples [3]. If a sample is homogeneous, the entropy is zero. If the
sample is equally divided (the split is of 50% each, in the case of a binary choice) the entropy
is one.
CHAPTER 1. ENSEMBLE METHODS 15
The Gini index involves the selection of two random items from a population and imposes the
condition that they must be of the same class. The probability of this is one if the population
is pure [3].
Some limitations of this type of split are that it only works on categorical values and it only
performs binary splits. The Gini index is computed using the following formula:
Definition 1.4.2 GI = p2 + q 2 where the p is the success probability, and q is the failure
probability
1.4.3.3 Chi-squared
This algorithm is used to find the statistical significance amongst differences between parent
and children nodes. It is measured by the sum of squares of standardized differences between
observed and expected frequencies of a target variable [3]. Same as the Gini index, it only
works on categorical values but can perform more than two splits. It is computed using the
formula:
2
Definition 1.4.3 χ2 = (A−E) 1 where the A is the actual frequency of a variable, and E is the
E2
expected frequency of a variable
Chapter 2
For measuring heart rate or other vital signs such as temperature, energy expenditure, blood
pressure or blood oxygen levels, there are consumer-level devices such as smartwatches or fitness
bands available. Movement sensors are often embedded in smartphones and easy to mine for
use in other contexts.
Smartwatches are devices worn on the wrist that use sensors to gather data about the user’s
movement and various other information. First examples of wristband sensors were based on the
use of accelerometers to measure steps. However, the latest models already include other kinds
of metrics. Regarding smartphones, most of the ones available on the market have incorporated
an IMU (inertial measurement unit).
In the following chapter, a general overview is provided on sensors that can be worn by
humans and how they can track interaction with the environment or physical data. Section
2.1 explains the inner structure and functionality of an IMU and how data provided by it can
be further used in various circumstances. Section 2.2 aims to discuss retrieval of physical data
measurement sensors and how they work, while section 2.3 advances on a subset of such sensors
incorporated in a device that can be worn on the body and is called wearable technology.
16
CHAPTER 2. SENSOR DATA PROCESSING 17
Most modern smartphones embody this type of sensor, which is capable of providing user
position, among other measurements. Recent performance evaluation done on innovative sensor
technologies provide good results regarding their reliability [38]. Smartphones have been used
as tools for research, especially in the healthcare and physical activity monitoring fields. For
example, a smartphone could be used to assess the range of motion and posture. Current
smartphone applications mainly use algorithms provided by the manufacturer [27].
Smartphones usually have two basic types of sensors: software and hardware. Hardware
sensors represent the physical components of the inertial measurement unit, and they are built
into the device. They extract data by directly measuring environment properties (such as accel-
eration, geomagnetic field or angular rate) and provide raw measurements. Software sensors are
not physical devices, but they mimic hardware-based sensors and usually apply some processing
to the data, making it more accessible for an application [9].
This chapter describes an completely original approach to the theme of health-related moni-
toring, based on the scientific paper [11]. Section 3.1 presents the motivation for this work and
section 3.2 introduces the fall detection algorithm. In section 3.3 the rules used for determining
the heart condition are introduced. Section 3.4, presents the dataset used as input and the
processing done on it and finally, section 3.5 details the various experiments performed to tune
and measure the performance of our approach.
3.1 Motivation
The reason for this implementation is to provide caregivers an easy way to monitor and intervene
in the case of emergency. Since the application is web-based, it has no complicated install guide
and set-up, requiring minimal guidance. Once the connection of the main account with the
necessary devices is made, following the care receiver’s status is easy. All the information
needed presents itself on a panel, and the caregiver is alerted whenever there might be a fall
event, or the heart rate is abnormal for the detected activity. Both the unexpected heart rate
and the fall warning function based on threshold systems.
When reporting the heart rate abnormality, what is taken into account are general ranges
for a patient of the specified sex, age, and activity level. When reporting a fall, the device
acceleration is calculated based on sensors data and may be wrong at times, wrongfully guessing
a fall (in the case of a person jumping around or throwing the phone).
A fair point to make is that application usage for a single purpose only is feasible and that
can be configurable. Since heart rate is not an accurate enough metric to detect activity, if only
a heart rate sensor is connected then the warnings received by the caregiver will only notify
about irregular heart rate. If only an IMU sensor is connected (from a phone or otherwise),
monitoring activities and fall events are possible, but no heart-rate related notifications arise.
Another possibility is to deactivate a certain sensor, relying on the information from the other
one. At least one device needs to be connected to use the application.
19
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 20
What this application is not meant to be is an actual emergency tool. While it may prove
useful to people trying to track a person of unstable health, the notifications and warnings it
gives are mostly informational and can be misleading. If the care-receiver is in bad shape, the
constant presence of a caregiver is needed. Also, even if the application is used, caregivers must
be in a position where they may quickly intervene if something happens and should not be used
as a monitor from far away. It would be most effective in a hospital, or a home for the elderly,
where there are multiple patients to keep track of in different rooms and intervention from the
staff is possible. Also, with some extensions, it could be used for self-monitoring and aid for
individuals in need of tracking their heart health.
The total acceleration magnitude and the aggregate rotational rate is obtained by using the
following equations:
q
|acc| = a2x + a2y + a2z (3.1)
q
|ω| = ωx2 + ωy2 + ωz2 (3.2)
where ax , ay and az correspond to the sensor frame of a 3-axis accelerometer and ωx , ωy and
ωz are extracted from a gyroscope. Both represent measurements along the three axes (x, y, z),
from inertial measurement units equipped on phones or other devices. The three-phase fall
detection algorithm that combines two methods presented in [25] and [5] is employed in the
application (on the movement sensor device) is shown below:
"""
LFT represents the lower fall threshold and UFT the upper fall threshold
The deltas repesent the absolute value of the difference between two measurements:
the current one and the previous one
"""
LFT = 0.41
UFT = 3.52
MAX_ACC_DELTA = 0.4
MIN_ARR_DELTA = 35
MAX_ARR_DELTA = 60
def check_if_fall(acc_current, acc_prev, arr_current, arr_prev):
delta_acc = abs(acc_current - acc_prev)
delta_arr = abs(arr_current - arr_prev)
if LFT < acc_current < UFT:
if delta_acc < MAX_ACC_DELTA and MIN_ARR_DELTA < delta_arr < MAX_ARR_DELTA:
return True
return False
The thresholds used are configurable, with the purpose of extension and experimenting. By
using this simple and fast equation, many systems have integrated it for step detection using
various algorithms like peak detection or zero-crossing.
in preventive care.
Heart-rate can easily be categorized as normal or not by different methods: concluding
where the measurement falls relative to lower and upper bounds by some range tables by age
[18] (seen in table 3.1) or using an equation to identify expected heart rate by age and compare
measurements with that [38].
A downfall for the chart methods is that the base of all measurements is the RPR (Resting
Pulse Rate), while the second one only measures the maximum heart rate. Our application
receives measurements during the day while resting and while being active. Consequently, we
need to combine these two methods and compare with our activity level discovery. If the care
receiver is performing some higher or moderate intensity activities, we use the maximum heart
rate formula to conclude if the current heart rate is appropriate. Otherwise, if the care-receiver
is performing low-intensity activities or resting, the heart rate gets checked by the RPR chart.
where hrmax represents the maximum heart rate and age represents the current age of the care
receiver in years.
When a heart rate that is denoted as part of a low or medium activity state is checked,
our system tries to fit the value in this chart. If the heart rate value reaches the upper or
lower ranges by a configurable threshold, a warning is issued. Otherwise, if the value can be
comfortably fit within the range corresponding to the care receiver’s age and gender, the system
will just announce that the heart rate is good. The formula for maximum heart rate is used
when the activity level is high.
The heart rate abnormality does not have a designated channel for communication and is
processed as it comes, with a lower priority than falling.
Correlation with the activity level is an important part of the heart rate status notification.
If the positioning sensor is not connected to the application, then the detection of the activity
level is deactivated. In this case, the threshold-based system only uses the ranges mentioned in
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 23
the table above to reach a conclusion. It will certainly not be as accurate, but it is still helpful.
Label Activity
0 Transition activities
1 Lying
2 Sitting
3 Standing
4 Walking
5 Running
6 Cycling
7 Alert walking
9 Watching TV
10 Computer work
11 Driving a car
12 Ascending stairs
13 Descending stairs
16 Vacuum cleaning
17 Ironing
18 Folding laundry
19 General house cleaning
20 Playing soccer
24 Rope jumping
measurements for further training of the predictive model. Another problem is the diversity of
activity classification provided by the dataset. To solve this, the wide range of activities has
been mapped to three classes: light, medium and high. The activity level mapping seen in 3.3
is based on energy expenditure by action, as seen in [4].
When selecting features based on their importance, the computation usually starts from
a single tree and is then applied to all the trees in the ensemble. To compute the feature
importance, each feature importance is computed as the sum of the number of splits (across
all trees) that include the feature, proportionally to the number of samples it splits (so the
feature importance should be in range [0, 1], with 1 as a maximum value). A short version of
the procedure used is as follows:
The map F will contain entries of type f eature : importance. By sorting the map in descending
order based on importance, the actual order can be observed.
Using the above-mentioned procedure, we obtain a feature importance graph as seen in
figure 3.1. Since the personal details do not seem to influence the end result considerably, they
are discarded as well.
• accelx, accely and accelz represent the X-axis, Y-axis and Z-axis measurements for the
accelerometer
• gyrox, gyroy and gyroz represent the X-axis, Y-axis and Z-axis measurements for the
gyroscope
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 26
• magnetox, magnetoy, magnetoz are the X-axis, Y-axis and Z-axis measurements for the
magnetometer
3.5 Experiments
To evaluate the performance of our trained model, we used a subset of the PAMAP2 dataset
(from a part of the subjects), which was not included in the training subset. This subset has
232776 rows and 11 columns; preprocessing is performed as specified in section 3.4 above. The
activities included are diverse, from lying, sitting, standing, walking to running, ascending and
descending stairs. Transition activities and activities irrelevant to our scope (as described in
the following section) were discarded.
The experiments for this paper consist of hyperparameter optimization, performance mea-
surements, choosing a strategy for sparse data handling and comparison with related work in
the field.
A well-known strategy for performing tuning is the grid search. It facilitates an exhaustive
search over a set of specified parameters for a certain estimator.
K-fold cross-validation implies division of the original data set into k subsets, and for k
times, one subset is going to be used for validation and the rest k − 1 for training. All these k
outputs are then joined together when computing the accuracy.
By combining the above-mentioned methods, we obtain cross-validated grid search [23],
which can be parallelized relatively easy. Each specified parameter from the grid will be paired
up with all the other parameters, and for a complete set of parameters used within a model,
cross-validation is used in the end.
The random forest algorithm has the following important parameters which support adjust-
ments:
• Maximum features to consider when looking for the best split (max f eatures)
• The minimum number of samples to split an internal node (min samples split)
As mentioned in [7], each tree should grow to the largest extent possible, so the only
parameter random forests is truly senstive to is the maximum features that are chosen at each
split. The error rate in the forest depends on the correlation and individual strength of each
tree.
Since our methodology is to avoid pruning and limiting the growth of each particular tree,
we will neglect the max depth, min samples split and min samples leaf parameters.
n estimators 15 20 50
√
max f eatures n total f eatures log2 (n total f eatures) n total f eatures
criterion gini entropy chi-squared
bootstrap yes no randomly chosen
We perform an exhaustive search over the parameter values mentioned in table 3.4, expecting
to find the pairing that provides the best results. This will result in 81 candidate models being
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 28
built and trained, then cross-validation with 3 folds is used to measure their performance,
resulting in 243 fits.
According to our fitting, the best pairing of parameters is as follows: n estimators = 50,
max f eatures = log2 , criterion = entropy and bootstrap = yes. We use a forest of 50 trees
and the number of features considered when looking for a split is logarithm in base 2 of the
total number of features. By using entropy as the function which measures the quality of the
split and employing bootstrap samples, we arrive at a final accuracy of 91%.
When deciding the performance of a learning model, many metrics can be used. The meth-
ods chosen are very important, since they can ultimately influence the choices made regarding
algorithm usage and parameters. The classification metrics we have chosen to interpret our
trained learner are:
• Classification accuracy
Classification accuracy is the number of valid predictions made as a ratio of all predictions
that have been done. It is the most widely used but also relatively easy to apply wrongly. It
is appropriate to use when the number of observations in each class is roughly the same. It is
usually in the [0, 1] range but it can be converted into a percentage by multiplying the value
by 100.
tp
Definition 3.5.2 precision = tp+f p
where tp is the number of true positives and f p is the
number of false positives.
tp
Definition 3.5.3 recall = tp+f n
where tp is the number of true positives and f n is the number
of false positives.
By using the above definitions, we obtain precision and recall as seen in table 3.5.
Precision Recall
Low 1.00 0.79
Medium 0.99 0.98
High 0.90 0.98
Average 0.96 0.91
One of the simplest strategies is to simply remove the rows containing missing data from the
dataset, but this is not an ideal scenario for us. Since the heart rate is a very sparse column,
the first intuition is that this would lead to us losing a lot of information [14]. But since it is
an applicable method, it will be used for experimentation.
Another option, which involves some data processing, is to impute the value. When replac-
ing, multiple strategies can be adopted:
• Replacing with a constant value that makes sense in the problem domain and that does
not induce confusion (for example, in our problem statement, it would make sense to use
0 as a replacement for heart rate, since it is not a valid measurement)
• Choosing a value from another randomly selected row, from within the same column
• The mean of the all the known values that were previously found in the column
Since the implementation of decision trees (the base learner in random forests) we use is
not robust to missing values, leaving the dataset in its original state is not an option.
After analyzing the possibilities, we have reached three possible strategies in handling the
sparse heart rate column: imputing with 0 or the mean and removing all the instances that do
not contain a heart rate measurement. The accuracy obtained with each method can be seen
in table 3.6.
Method Accuracy
Imputing with 0 91%
Imputing with mean 88%
Removing columns with missing data 81%
It observed that the best accuracy is obtained by replacing the missing values with 0,
strategy which will be used further in the processing of the data.
Diaz et al. [13] constructed a similar system to the one described above, with a slight
difference in sensor placement and type. The device consisted of an adhesive sensor patch off
small dimensions that could be attached to the body, and its fall detection accuracy was 100%,
and only 7.5% of daily activities were wrongly detected as falls.
Hwang et al. [20] used a tri-axial accelerometer and also a gyroscope, both placed on the
chest, to successfully distinguish between falls and other activities that a subject may perform
in a day. This system had lower accuracy than the ones mentioned above but still obtained
good results. On the other hand, this system has only been used to experiment on very few
subjects of young age, so its findings might not prove relevant when working with elders.
In comparison to other papers when relating to activity prediction (using the PAMAP2
dataset), we obtain comparable results. In [1], three algorithms are used for classification:
KNN (k-nearest neighbors), rotation forest and NN (neural networks) and the results obtained
are 70%, 94% and 89%, respectively. In [41], BP (back-propagation) neural networks and
additional data processing are used to obtain an accuracy of 93%. A comparison between the
algorithms mentioned before and ours in terms of accuracy is presented in table 3.7.
This section illustrates how the application is implemented and how it processes data. In
section 4.1 implementation details are exposed. Section 4.2 presents the system organization
and component interaction. In the end, section 4.3 provides the user manual needed for a user
to properly set up and use the application.
4.1 Implementation
The main web application server is implemented in Python [39]. This language was chosen for
its brevity and ability to provide tools and frameworks that make it easy to move from an idea to
an actual implementation. The base of this application used is Flask [36], which is a micro web
framework that provides a full stack tools for developing both server-side and client-side. The
main philosophy it follows is to start with a small core and offer enough flexibility for following
extensions. While Flask provides through extensions user management, easy form handling,
mail sending, caching and database interactions capabilities, other Python libraries were also
used. SQLAlchemy [2] is a powerful SQL toolkit and Object Relational Mapper (ORM), which
allows the application to interact with the database at a higher level of abstraction. It also
comes with a lightweight database migration tool, which allows for the easier altering of the
database structure. Currently, it can be set up to run locally (the main web application on
port :5000 and the prediction unit on port :9000) but a deployment on a public domain will be
done in the future. The communication between all the units is done by using JSON messages.
JSON (JavaScript Object Notation) is a lightweight data-interchange format which easy to
generate and can only be text.
The client-side is developed using a web template system and is minimal, providing only
essentials for monitoring while trying to be as explicit as possible. The templating language
used is Jinja2, which features template inheritance and just in time compilation down to Python
code. It also uses the OAuth library for Python for generating a token for the FitBit application.
It is also fast and lightweight because most of the styling is done in Bootstrap, which is an
HTML, CSS and JS framework, which allows for the development of responsive pages. Real-
time fall detection is displayed on the front end, by using a long polling technique with AJAX
32
CHAPTER 4. PULSE REVIEW (PULSER) APPLICATION 33
calls.
The prediction unit is also relying on Flask for route exposure but does not have a visual
interface. It contains the trained model for heart rate and movement classification and performs
some basic data processing for a better prediction.
The scikit-learn project [31] supplies an open source machine learning library for the Python
programming language. It provides support for the algorithmic part of the prediction unit,
through the RandomF orestClassif ier classifier, which offers a highly configurable learner. It
also provides various other utilities (such as feature importance, grid searching) which help
in tuning and experiments. The prediction service exposes a single route, which accepts only
POST requests and returns a prediction based on heart rate and movement sensor data.
The mobile application which fetches sensor data is implemented in Java for Android. It
uses a sensor service to continuously retrieve sensor data and the OkHttp library to issue POST
requests to the main application server.
The whole system revolves around a real life, key relationship: caregiver and care receiver.
The caregiver is an individual with interest in keeping track of the health of another. The care
receiver is assumed to be a person with limited mobility or other illnesses, who needs constant
monitoring.
CHAPTER 4. PULSE REVIEW (PULSER) APPLICATION 34
t = |th − tm | (4.1)
where th is the heart rate measurement timestamp in seconds, and tm is the movement state
measurement in seconds. The threshold value for t used in the application currently is 60 (since
the bpm measurement of the heart rate is assumed to be valid for 60 seconds), but it can be
adjusted.
through an application that must be installed on the phone. After installation, a secret key
is provided by the web application and it needs to be entered in the phone application. The
caregiver must click on the Movement connection option and retrieve the secret key from there,
ensuring that the data received from the phone is saved for the corresponding user.
In the end, the heart-rate sensor needs to be set up in the application. In the Connections
tab, the caregiver must input the Fitbit data for Heart Rate Intraday Time Series as provided
by the instructional guide on the Fitbit website [46]. The Connections tab can also be accessed
from the main page; same with the monitoring panel.
After all of this has been done and the devices are correctly placed on the care receiver,
the caregiver can monitor the activity level and all the other features mentioned above on the
Health Monitoring Panel. Synchronizing devices is done by pressing the refresh button to fetch
the latest data. To further edit or adjust any of the devices which communicate with the web
application, the caregiver can always go back to Connections tab where connection information
can be modified. Also, a connected device can always be ejected by clicking the button Discon-
nect on the data editing page, under the corresponding menu. The disconnected device means
will not send any more data to the web application, but it can always be reconnected. Also,
the registered care receiver can also be replaced, and all data relating to them will be deleted
too.
Chapter 5
Since this application was designed as a proof of concept rather than a finite product, there are
many ways in which the features provided can be extended and enhanced, or even additional
features can be easily integrated.
A beneficial element of the application is the fact that it is API-based, making it very easy to
offer as a service to the public. A multitude of different heart-rate monitors and IMU (Inertial
Measurement Unit) sensors can be easily integrated, and data sent by them can be used by
the application. All that is needed is JSON-based communication between the application
endpoints and the sender, which must send requests on the proper endpoint with accordingly
formatted data. For our purpose, the heart-rate was provided through a fitness band, and
the positioning data was retrieved from mobile phone sensors, but since it has a very clearly
defined API, it can use anything as a data source, as long as the sender conforms to the standard
imposed by the application. Also in this context, it would be useful if the sensor would use
a proprietary SDK rather than an API since it would communicate a larger volume of data,
faster, without the additional overhead of ensuring a stable client-server communication.
An ideal improvement would be porting the monitoring web panel to a mobile device. That
way, it would be easier for the caregiver to monitor on the go, rather than having to log on to
a computer or laptop. For the application to have real-world applicability, it must be extended
to support multiple care-receivers. Right now, one person can only monitor an individual. This
use case, while useful in proving the need for such an application, is not as common in the real
world. The application’s structure could easily support such an extension.
Also, it could allow for a more precise fall-detection specialized device to be connected by
Bluetooth technology to the application. Since this application is aimed at the elderly, trying
to make the monitoring device as small as non-invasive as possible should be a priority. Right
now, the system proposes a mobile phone that needs to be strapped to the waist and a fitness
bracelet and both need to be continuously worn, which might not be an option for some persons.
An experimental feature would be extending the learning model to use other data about
the care-receiver as well. The latest technology advancements made it possible to develop non-
invasive sensors that also monitor body temperature, blood pressure, neurological activity and
many other vital signs. Also, the application could request more details about the lifestyle of a
37
CHAPTER 5. FUTURE WORK AND CONCLUSIONS 38
user, to detect and provide alerts for a wider range of ailments, like heart attacks or epileptic
seizures. By providing more varied input to the prediction algorithm, it may also become less
time-efficient. Comprehensive experiments need to be performed, to outline suitable input that
also proves efficient.
Another idea would be to offer the possibility of self-monitoring. While this is technically
possible in the application, by adding yourself as a care-receiver and wearing the tracking and
monitoring devices, it is not an ideal use case. The interface is not engaging enough and
does not provide enough interactivity convince a user to keep using the application. In the
future, the application could provide an alternative user interface, where rather than tracking
the movement on the user, it should keep the focus on heart rate and other vital signs. Then,
by using the same (or a more sophisticated) threshold mechanism, it could provide the user
different facilities based on abnormalities detected, like breathing exercises or reminders to slow
down during the day.
Bibliography
[1] M. Arif and A. Kattan. Physical activities monitoring using wearable acceleration sensors
attached to the body. PloS one, 10(7):e0130851, 2015.
[2] Michael Bayer. SQLalchemy, SQL toolkit and ORM for Python. https://www.
sqlalchemy.org.
[3] M.J.A. Berry and G.S. Linoff. Data Mining Techniques: For Marketing, Sales, and Cus-
tomer Relationship Management. Wiley technology publication. Wiley, 2004.
[4] S.N. Blair, A.L. Dunn, B.H. Marcus, R.A. Carpenter, and P. Jaret. Active Living Every
Day. Human Kinetics, 2010.
[5] A.K. Bourke, J.V. Obrien, and G.M. Lyons. Evaluation of a threshold-based tri-axial
accelerometer fall detection algorithm. Gait & posture, 26(2):194–199, 2007.
[8] S. Chaudhuri, H. Thompson, and G. Demiris. Fall detection devices and their use with
older adults: a systematic review. Journal of geriatric physical therapy (2001), 37(4):178,
2014.
[9] R. Chen. Ubiquitous Positioning and Mobile Location-Based Services in Smart Phones.
Premier reference source. Information Science Reference, 2012.
[11] Daniela Crăciun. Continuous physical health monitoring and classification for distress
detection. Sesiunea de Comunicari Stiintifice ale Studentilor, Cluj-Napoca, 2017.
[13] A. Diaz, M. Prado, L.M. Roa, J. Reina-Tosina, and G. Sanchez. Preliminary evaluation of
a full-time falling monitor for the elderly. In Engineering in Medicine and Biology Society,
39
BIBLIOGRAPHY 40
2004. IEMBS’04. 26th Annual International Conference of the IEEE, volume 1, pages
2180–2183. IEEE, 2004.
[14] Y. Dong and C.Y.J. Peng. Principled missing data methods for researchers. SpringerPlus,
2(1):222, 2013.
[15] A. E. Draghici and J. A. Taylor. The physiological basis and measurement of heart rate
variability in humans. Journal of Physiological Anthropology, 35, 2016.
[16] B. Efron and R.J. Tibshirani. An Introduction to the Bootstrap. Chapman & Hall/CRC
Monographs on Statistics & Applied Probability. Taylor & Francis, 1994.
[17] T. Ferguson, A.V. Rowlands, T. Olds, and C. Maher. The validity of consumer-level,
activity monitors in healthy adults worn in free-living conditions: a cross-sectional study.
International Journal of Behavioral Nutrition and Physical Activity, 12(1):42, 2015.
[18] John Hart. Normal resting pulse rate ranges. Journal of Nursing Education and Practice,
5(8):95, 2015.
[19] J.M. Hausdorff, D.A. Rios, and H.K. Edelberg. Gait variability and fall risk in community-
living older adults: a 1-year prospective study. Archives of physical medicine and rehabil-
itation, 82(8):1050–1056, 2001.
[20] Jong-Young Hwang, JM Kang, Yong Won Jang, and Hee-Chan Kim. Development of novel
algorithm and real-time monitoring ambulatory system using bluetooth module for fall
detection in the elderly. In Engineering in Medicine and Biology Society, 2004. IEMBS’04.
26th Annual International Conference of the IEEE, volume 1, pages 2204–2207. IEEE,
2004.
[22] D.S. Krantz, A. Baum, and M. Wideman. Assessment of preferences for self-treatment
and information in health care. J Pers Soc Psychol, 39(5):977–990, 1980.
[23] D. Krstajic, L.J. Buturovic, D.E. Leahy, and S. Thomas. Cross-validation pitfalls when
selecting and assessing regression and classification models. Journal of Cheminformatics,
6(1):10, 2014.
[24] A. Lee, K. Lee, and P. Khang. Preventing falls in the geriatric population. The Permanente
Journal, 17(4):37, 2013.
[25] Q. Li, J.A. Stankovic, M.A. Hanson, A.T. Barth, and G. Lach, J.and Zhou. Accurate, fast
fall detection using gyroscopes and accelerometer-derived posture information. In Wearable
and Implantable Body Sensor Networks, 2009. BSN 2009. Sixth International Workshop
on, pages 138–143. IEEE, 2009.
[28] D. Opitz and R. Maclin. Popular ensemble methods: An empirical study. Journal of
Artificial Intelligence Research, 11:169–198, 1999.
[29] Palatini P., Casiglia E., Julius S., and Pessina A.C. High heart rate: A risk factor for
cardiovascular death in elderly men. Archives of Internal Medicine, 159(6):585–592, 1999.
[30] R.R. Pate and M. Pratt. Physical activity and public health: a recommendation from
the centers for disease control and prevention and the american college of sports medicine.
Jama, 273(5):402–407, 1995.
[32] L. Piwek, D.A. Ellis, S. Andrews, and A. Joinson. The rise of consumer health wearables:
promises and barriers. PLoS Med, 13(2):e1001953, 2016.
[33] L.E. Raileanu and K. Stoffel. Theoretical comparison between the gini index and informa-
tion gain criteria. Annals of Mathematics and Artificial Intelligence, 41(1):77–93, 2004.
[34] Attila Reiss. PAMAP2 physical activity monitoring data set. https://archive.ics.uci.
edu/ml/datasets/{PAMAP2}+Physical+Activity+Monitoring.
[35] Lior Rokach. Ensemble-based classifiers. Artificial Intelligence Review, 33(1):1–39, 2010.
[37] Bhide Samir. Applying Low Pass Filter to Android Sensor Readings. https://www.built.
io/blog/applying-low-pass-filter-to-android-sensor-s-readings.
[38] H. Tanaka, K.D. Monahan, and D.R. Seals. Age-predicted maximal heart rate revisited.
Journal of the American College of Cardiology, 37(1):153–156, 2001.
[39] Guido van Rossum. Python, the programming language. http://python.org/, 1991–.
[40] A.C. Verceles and E.R. Hager. Use of accelerometry to monitor physical activity in critically
ill subjects: a systematic review. Respiratory care, 60(9):1330–1336, 2015.
[41] H. Xu, J. Liu, H. Hu, and Y. Zhang. Wearable Sensor-Based Human Activity Recog-
nition Method with Multi-Features Extracted from Hilbert-Huang Transform. Sensors,
16(12):2048, 2016.
BIBLIOGRAPHY 42
[42] Zhi-Hua Zhou. Ensemble Methods: Foundations and Algorithms. Chapman and Hall, 1
edition, 2012.