You are on page 1of 45

BABEŞ-BOLYAI UNIVERSITY CLUJ-NAPOCA

FACULTY OF MATHEMATICS AND COMPUTER SCIENCE


SPECIALIZATION COMPUTER SCIENCE IN ENGLISH

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

2 Sensor data processing 16


2.1 Inertial measurement units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2 Sensor data filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3 Physical data and wearable technology . . . . . . . . . . . . . . . . . . . . . . . 18

3 Our approach: Continuous health monitoring 19


3.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Fall detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.3 Rules for processing heart status . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.4 Dataset choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.1 Feature selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.2 Data transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.5 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.5.1 Hyperparameter tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1
CONTENTS 2

3.5.2 Performance test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28


3.5.3 Sparse data handling methods . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.4 Comparison with related work . . . . . . . . . . . . . . . . . . . . . . . . 30

4 Pulse Review (PULSER) Application 32


4.1 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2 System structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.2.1 Routing unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.2.2 Prediction service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.2.3 Sensor retrieval units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.3 User manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

5 Future work and conclusions 37

Bibliography 39
List of Figures

1.1 Decision tree structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12


1.2 Random forest classifier structure . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.1 Inertial measurement unit axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.1 Feature importance on PAMAP2 dataset . . . . . . . . . . . . . . . . . . . . . . 25


3.2 Confusion matrix of random forest classifier . . . . . . . . . . . . . . . . . . . . 28

4.1 Monitoring system structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3
List of Tables

3.1 Resting pulse rate values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22


3.2 Activity detailing in PAMAP2 dataset . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Activity mapping by energy expenditure . . . . . . . . . . . . . . . . . . . . . . 25
3.4 Random forest parameter grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5 Precision and recall for random forest classifier . . . . . . . . . . . . . . . . . . . 29
3.6 Sparse data handling strategies accuracy . . . . . . . . . . . . . . . . . . . . . . 30
3.7 Comparisons with related work . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

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.

1.1 What are ensemble methods?


An ensemble method is a type of technique that combines some bases hypothesis to learn its
own, to improve robustness and decrease error. Some reasons to avoid them in some cases
would be increased complexity of training and prediction time, and it is harder to explain and
follow the prediction [35]. Two families of ensemble methods are usually distinguished:

• 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 Methods of constructing ensembles


According to how the generation of base learners is done, two paradigms of ensemble methods
emerge: sequential ensemble methods, that build learners incrementally (AdaBoost being a
typical method in this case) and methods that are capable of generating learners in parallel
(with bagging as a representative).
The motivation of sequential methods is that they can exploit the interconnection between
the learners, aiming to improve overall performance. Parallel methods attempt to use the
independence between the learners since their separate error can be drastically reduced when
they are combined. Thought the concept of truly independent learners is not feasible, base
learners with minimal dependence can be obtained by introducing some level of randomness in
the process of learning. Another aspect that is attractive when employing parallel methods for
providing solutions is their propriety to be accelerated by using multi-core computing processors
(which are widely available currently) or parallel computers [42].
This part aims to provide a basic introduction to the various types of ensemble methods
available currently, by what means they can be distinguished from one another, and moreover
how they can be built.

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 .

1.3 Combination of base learners


After generating a set of base learners, there are multiple strategies from which one can choose
to combine their output to ensure a strong ability to generalize. Issues that frequently occur
when trying to build learners are of three natures: statistical, computational and representa-
tional. These three concerns are the main cause of traditional approaches failing. A learning
algorithm that suffers from statistical issues is said to have high variance; computational issues
cause high computational variance and difficulties of representational type induce a strong bias.
Consequently, by combining learners, the variance and the bias are reduced [28].
CHAPTER 1. ENSEMBLE METHODS 10

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

and each wi represents the weight assigned to a certain classifier.

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.

1.4 Random forests


This section aims to introduce the random forest algorithm, an ensemble approach which was
first introduced in [7], where it is described as an aggregation of decision trees, conforming to
the definition below:

Definition 1.4.1 A random forest consists of a collection of tree-structured classifiers h(x, θk )


where the θk are independent identically distributed random vectors and each tree casts a unit
vote for the most popular class at input x.

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 sample of the initial cases in the training is taken at random

• 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

1.4.1 Decision tree mechanism


The random forest begins with a standard machine learning technique called a decision tree
which, in ensemble terms, corresponds to our weak learner.
The decision tree algorithm is useful in the context of supervised learning. This technique
implies the splitting of the sample into two or more sets based on a particular splitting criterion,
identifying the most significant variable and its value that gives best homogeneous sets. In a
decision tree, an input enters at the top, and as it traverses down the tree, the data gets divided
into smaller and smaller sets. Each node in the tree is, in fact, a test for the attribute of the
instance which needs to be classified [7].

Figure 1.1: Decision tree structure

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

• Decision nodes are sub-nodes that split into further sub-nodes

• 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

• Sub-trees (also called branches) represent a sub-section of the entire tree

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:

• Intuitive and easy to understand

• No constraints regarding data types they can work with

• No assumptions regarding distribution or structure of the data

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.

1.4.2 Out-of-bag estimates


For each base learner in bagging, there are about 36.8% training examples which have not
been used in its training process [42], also called out-of-bag estimates. The performance
of a base learner can be determined by using these out-of-bag examples, and after that, the
generalization error of the bagged ensemble can be estimated.
To get the out-of-bag estimate, we need to record the training samples used for each base
learner. Each new training set is extracted, with replacement, from the original training set.
Then a tree is grown on the new training set using random feature selection [42].
The out-of-bag estimates can also be used for many other purposes. For example, when
decision trees are used as base classifiers, the following probability of each node of each tree can
be determined using the out-of-bag examples. If a node does not include out-of-bag examples,
CHAPTER 1. ENSEMBLE METHODS 14

Figure 1.2: Random forest classifier structure

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.

1.4.3 Split selection


When splitting nodes, the algorithm used is of limited importance, since they rarely seem
to provide different results [33]. An important aspect is that not all algorithms for splitting
are compatible with different types of problems. In this section, some splitting methods are
introduced.

1.4.3.1 Information gain

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

1.4.3.2 Gini index

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

Sensor data processing

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.

2.1 Inertial measurement units


The IMU (inertial measurement unit) was made known to the general public in 1987 when
a patent regarding it was introduced in [26]. It is the main component of inertial guidance
systems used in most devices and vehicles.
An IMU works by sensing motion including the type, rate, and direction of it, usually
employing accelerometers, gyroscopes and sometimes also magnetometers. In flight dynamics,
three principal axes are defined: pitch, roll, and yaw. The vertical axis (yaw), is drawn from
top to bottom, perpendicular on the other two. The lateral axis (pitch), runs from left to right,
while the longitudinal axis (roll) is traced from front to back. In accelerometers placement,
measuring axes are orthogonal to each other. An IMU works by detecting the current rate
of acceleration, as well as changes in rotational attributes. An overview on how the axis are
represented in an inertial measurement unit (in a smartphone) is displayed in figure 2.1.

16
CHAPTER 2. SENSOR DATA PROCESSING 17

Figure 2.1: Inertial measurement unit axis. Image source: [44]

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].

2.2 Sensor data filtering


A problem that might occur when reading sensor data from a device is the added noise that
accumulates. High-frequency signals (noise) cause the readings to hop between high and low
values. The solution to this is applying some filters to the data to smooth it out and make it
more reliable. A simple filter is a low pass, which passes low-frequency values from previous
measurements and tries to reduce the amplitude of measurements higher than a designed cutoff
frequency. Conversely, a high pass filter passes high-frequency signals and reduces the amplitude
of signals with frequencies lower than the threshold frequency [37].
Filtering can also aid in isolating or eliminating the contribution of the force of gravity in an
accelerometer measurement. The isolation can be obtained by applying a low-pass filter while
applying a high pass filter can eliminate it. The angular speed is measured in the same coordi-
nate system as is used for the acceleration sensor. Rotation is positive in the counterclockwise
direction. In practice, the gyroscope noise will introduce some inaccuracies which need to be
compensated for. The compensation mentioned before is usually done using the information
from other sensors [43].
CHAPTER 2. SENSOR DATA PROCESSING 18

2.3 Physical data and wearable technology


A formal definition states: ”Physical activity is defined as any bodily movement produced
by skeletal muscles that result in energy expenditure” and exercise is defined as ”a subset of
physical activity that is planned, structured, and repetitive and has as a final or an intermediate
objective the improvement or maintenance of physical fitness. Physical fitness is a set of
attributes that are either health- or skill-related.” [30], describing general body movement as
physical activity and also how it does not necessarily have anything to do with exercise (which
is a subset of physical activities) or with physical fitness (which can be acquired in diverse
ways). A wide range of medical articles mention how helpful it is even for critically ill persons
to incorporate some physical activity [40]. Most hospitals treat severe conditions with total
bed-rest, even though numerous clinical studies have proven that integrating a small amount of
exercise in the early course of the illness results in improved outcomes related to patient health.
Submitting patients to prolonged bed-rest puts them at risk of profound weakness, delirium and
muscle atrophy. These exercises should include but not be limited to basic mobility movements,
like sitting-to-standing, rolling and pivoting. If adequately monitored, either by using a device
or by a supervisor, the patient could confidently perform these exercises. Their physician should
also monitor their well-being so as to recommend safe activities for the illness level.
Recent studies have compared consumer-level activity monitors with research-grade devices
regarding accuracy and validity of data. The correlation between the data from consumer-
level gadget and research-grade was high enough to deem valid, with the Fitbit devices being
some of the top performers [17]. Monitoring is also recommended for self-assessment when
dealing with chronic health conditions and allows patients greater control over their health. As
more activity data is gathered, valuable information about disease onset and severity can have
a tremendous impact on understanding and delivering care, either self-administered or from
another individual [10].
The first wireless heart rate monitor which was composed of an emitter placed on a chest
strap with a receiver worn on the wrist was introduced in 1982 for athletes. In the past five
years, heart rate monitoring has been combined with pedometers, accelerometers, and GPS
(global positioning systems) to provide individuals more accurate estimates of their activities.
Recently, wearable activity trackers have utilized optical blood flow sensing to measure HR.
This method is a non-invasive method for the detection of heart rate and is connected with
the optical properties of vascular tissue using LEDs, which are shined directly into the skin
and interact with changes in the blood volume passing through arteries to emit a value. Many
wristband manufacturers use this type of technology, the most notable ones being Fitbit Charge
HR [45].
A dilemma that often arises in the medical world (and a reason why doctor are reserved in
recommending wearables) is their impact on the behavior of the wearer. When worn by healthy
people, they are shown to improve overall condition [22], but use within a clinical population is
still limited. A potential harming effect is that the user might rely too heavily on the automated
system, which may provide a deceptive sense of security or promote self-misdiagnosis [32].
Chapter 3

Our approach: Continuous health


monitoring

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

During the building of this application, the primary aims were:

• Easy to set-up and understand the process

• Ways of tracking and monitoring care-receiver are expected not to be uncomfortable or


invasive for easy daily use

• High accuracy and low latency

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.

3.2 Fall detection


Falling is not dangerous to younger people, who can easily recover from such incidents, but to
elders, they can be the cause of serious injuries or even life-threatening. Consequently, seniors
are more susceptible to falling due to their impaired mobility and decreased muscle strength.
One in every three persons older than 65 years old is estimated to fall once or more times in
a year [19], and it is the leading cause of death and injury for people in that age bracket [24].
Even if the fall does not entail immediate harm, it can contribute to a decrease in mobility,
independence and desire to participate in activities.
Another event that can happen after falling is the ”long-lie” which describes a period of
lying down involuntarily after a fall. Remaining on the ground for such extended periods
causes dehydration and pressure sores, but also has some unexpected effects on the body, such
as internal bleeding or even death. Scientific experiments have shown that even basic algorithms
have registered good accuracy in practice and may be viable to integrate into applications [8].
An important aspect is that detection of the fall should be done as fast as possible, without
further processing of the data. When additional agents for data sending and retrieving are
added, latency is increased, and that is undesirable when a situation of emergency occurs. For
this reason, the currently presented application relies on the fall event being directly recorded by
the device which mines the data and ensures the availability of a one-way channel to announce
the falling, ensuring that this situation is quickly signaled to the end user.
Also, the system uses a very straightforward method: calculating the total acceleration and
the rotational rate for multiple movement states and trying to fit them between two threshold
measurements.
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 21

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.

3.3 Rules for processing heart status


With age, tracking heart rate becomes necessary, especially if there is a genetic predisposition
to heart disease or other related ailments, like blood pressure. Statistics show that an elevated
heart rate can be a predictor of cardiovascular-related deaths. Also, results are profoundly
impacted by the lifestyle choices a person makes. Smoking and a sedentary way of life have been
shown to affect negatively cardiovascular health [29]. Monitoring heart rate can be beneficial
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 22

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.

Age Female Male


18 to 25 54 to 85 49 to 82
26 to 35 54 to 83 49 to 82
36 to 45 54 to 85 50 to 83
46 to 55 54 to 85 50 to 84
56 to 65 54 to 85 51 to 82
Over 65 54 to 85 50 to 80

Table 3.1: Resting pulse rate values

The formula proposed by [38] is as follows:

hrmax = 208 − 0.7 × age (3.3)

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.

3.4 Dataset choice


The PAMAP2 Physical Activity Monitoring dataset [34] consists of data retrieved from nine
human subjects (one female and eight males), each subject wearing three inertial measurement
units and a heart rate monitor. This dataset was chosen because the attributes it contains are
easy to retrieve in real life situations and do not require special equipment.
Each IMU measures temperature and 3D data from accelerometer, gyroscope, and magne-
tometer. Subjects wore one IMU on the dominant wrist, one on the dominant ankle and one
on the trunk.
The protocol that each one of the subjects had to follow involved 12 activities. Some
additional optional activities were performed only by some of the subjects. The raw sensor
data is stored for each separately, in space separated text files (with the .dat extension). The
dataset contains 54 columns: each line has a timestamp, an activity tag and 52 attributes of
sensor telemetry. The complete dataset contains 2872532 rows.
In table 3.2, we can see what each activity tag is correspondent to.

3.4.1 Feature selection


When classifying, it is sometimes necessary to choose a subset of the data provided to keep
only the information that is relevant to our problem. The process mentioned above is called of
feature selection. Additionally, we may need to perform some transformation on our data and
obtain the related information, and this is feature extraction.
The dataset used in our case is extensive, but it is not feasible for usage in real life situations.
Consequently, some analysis has been performed to select the features which impact the final
results the most. The dataset also presented a significant amount of undefined data, which
needed a method of handling.
The first step in selecting attributes to use further is deciding how suitable it is to our
needs and how easily it can be retrieved. The PAMAP2 dataset retrieves data from 3 sensors
placed on the hand, trunk, and leg. While wearing many sensors is appropriate in a research
environment, it is not convenient in daily monitoring. For that reason, we need to determine
which one of the three sensors mentioned before provides the most accurate result and has a
considerable influence on the prediction.
Another idea is to add the subject information (which is needed in other parts of the applica-
tion) to the attributes. Consequently, the dataset was extended with four additional attributes:
height, weight, age, and sex. These details were extracted from the dataset documentation,
which contains a table with additional subject information.
A conclusion reached by studies that implement fall detection with thresholding techniques
is that the trunk is the most suitable section of the body to place a sensor because it yields
the most accurate results, this being explicitly mentioned in [13]. We also keep only the trunk
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 24

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

Table 3.2: Activity detailing in PAMAP2 dataset

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:

Get all trees after training as T.


Initialize empty feature importance map as F.
for tree in T do
for node in tree do
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 25

Intensity level Activities


Light Alert walking, Descending stairs, Vacuum cleaning, General house cleaning
Moderate Lying, Sitting, Standing, Walking, Watching TV, Computer work, Driving a car, Ironing, Folding laundry
High Running, Cycling, Ascending stairs

Table 3.3: Activity mapping by energy expenditure

Get node split attribute as f.


Increment the number for f in F.
end for
end for

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.

Figure 3.1: Feature importance on PAMAP2 dataset

The labels in figure 3.1 can be described as follows:

• 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

• hr represents the heart rate measurements in BPM (beats per minute)

• weight represents the weight in kilograms

• height represents the height in centimeters

• age represents age in years

• sex is 0 for male and 1 for female

3.4.2 Data transformation


The major data transformation that has been performed on the dataset is managing problematic
input. Handling missing data can be a challenge. First, the data needs to be identified. A
problematic attribute was the heart rate, which was missing in 856775 columns. We need to
determine whether dropping the rows which do not contain the heart rate measurement or
imputing their value will provide us with a better accuracy.
When imputing a value, many methods can be used: using a constant value (such as 0),
compute a mean or use a value from another randomly selected row, from within the same
column. After applying these methods on the PAMAP2 dataset and verifying the accuracy of
each method, the optimal approach is to replace every missing value with zeros. Experiments
done in this regard can be observed in the 3.5 section of this chapter.

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.

3.5.1 Hyperparameter tuning


One of the parts of configuring a learning model is setting the parameters it will use when
running the algorithm. To ensure that the used model reaches peak predictive performance,
the goal is to set the parameters in such a way that it enables completion of the learning task
in the best possible way.
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 27

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:

• Number of estimators (trees) in the forest (n estimators)

• Maximum features to consider when looking for the best split (max f eatures)

• The maximum depth a tree can reach (max depth)

• Criterion on which to measure the quality of a split (criterion)

• The minimum number of samples to split an internal node (min samples split)

• Minimum number of samples to be at a leaf node (min samples leaf )

• Whether to use bootstrap samples or not (bootstrap)

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

Table 3.4: Random forest parameter grid

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%.

3.5.2 Performance test

Figure 3.2: Confusion matrix of random forest classifier

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

• Confusion matrix and derived measurements


CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 29

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.

Definition 3.5.1 accuracy(y, y) = n1 ( n−1


P
i=0 ind(yi = yi )) where n is the number of samples and
ind(x) is the indicator function, meaning that if the predicate is true, its value is 1, otherwise
it is 0.

By applying this formula on our learning model, we obtain accuracy = 0.9172


In figure 3.2, we can observe the confusion matrix (without normalizing the values) gen-
erated by our model. It is observed that the most problematic label to classify was the high
activity level, wrongly classifying 168 other activities as high.
Using the confusion matrix, we can also derive the precision and the recall of our learner.

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

Table 3.5: Precision and recall for random forest classifier

3.5.3 Sparse data handling methods


When replacing sparse data, the missing values must first be identified. They may be marked
as not a number, or have a value (usually 0) that does not make sense (in the measurement of
heart rates, for example, using negative numbers). The only problematic column in our data
set is the heart rate.
Missing values can sometimes cause problems, since there are algorithms that do not work
with missing values.
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 30

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%

Table 3.6: Sparse data handling strategies accuracy

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.

3.5.4 Comparison with related work


There are already some existing systems that try to detect falling using different sensor data
with thresholding techniques. Most of them detect the shock received by the body on impact
using accelerometers. For example, A.K. Bourke et al. [5] used accelerometer measure from
different regions of the body (anterior aspect of the trunk, at the sternum and, at the anterior
of the thigh at the midpoint of the femur) and held two different experiments: one with young
people performing controlled falls and one with seniors while performing their daily activities,
managing to obtain a 100% accuracy using the trunk sensor.
CHAPTER 3. OUR APPROACH: CONTINUOUS HEALTH MONITORING 31

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.

Activity classifier Accuracy


K-Nearest Neighbors [1] 70%
Rotation Forest [1] 94%
Neural Networks [1] 89%
Neural Networks [41] 93%
Random Forests (this paper) 91%

Table 3.7: Comparisons with related work


Chapter 4

Pulse Review (PULSER) Application

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.

4.2 System structure


The system proposed has multiple components, referred from now on as units. While each one
of them can independently perform, abstracting freely from the other elements, the units work
best when all of them are available. Each unit provides an interface through which it can be
accessed, without making any assumptions about the input it receives. An overview of the
structure can be seen in figure 4.1.

Figure 4.1: Monitoring system structure

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

4.2.1 Routing unit


The main application server performs varied tasks: functions as a back-end for the monitoring
panel (client), dispatches requests and gathers data from all the other units and stores them
in a database. Synchronization of the movement and heart rate sensors is done via a simple
computation, that aims to synchronize them as accurately as possible without an overhead.
In this particular case, the movement sensor sends data almost constantly, having a mea-
surement for each second. The heart monitor does not send data that often, mainly because
it relays on syncing with a remote server which happens roughly every 15 minutes. That is
why the application independently fetches both measurements, and when the user requests a
prediction, it automatically groups the latest two measurements based on a maximum accepted
difference between them which may be configured. If there are no pairs yet, the application just
predicts based on the movement sensor data and uses the latest known heart rate.The formula
used to determine if the heart rate accurately represents the state of the care receiver is:

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.

4.2.2 Prediction service


The prediction unit is where a trained model that makes predictions resides. This unit also
exposes some endpoints, through which it accepts data rows of a certain structure. It also sends
back to the main server the results of the prediction. A training script is bundled within the
unit, which can be triggered manually by command line, by providing a path to the dataset
to use. Afterward, the trained model will reside in the application for further usage. When a
prediction request arrives, the latest generated model is loaded and used. Minimal processing
is done on the data received to ensure the prediction is accurately done.
When input data arrives into the prediction unit, all the necessary elements for prediction
(such as sensor data and heart rate) are organized into a row that is fit for the trained model
to process. After the prediction action, the heart rate is checked according to the rules describe
in section 3.3.
The algorithm used here is a random forest classifier and its parameters have been tuned
as described in section 3.5.

4.2.3 Sensor retrieval units


The movement unit can be any device with a sensor that records magnetometer, accelerometer
and gyroscope, the current date and time and is capable of forwarding that data. For the
CHAPTER 4. PULSE REVIEW (PULSER) APPLICATION 35

present case, the movement sensors of a mobile phone are used.


The heart monitoring unit can be any fitness band, smartwatch or sensor that can track
the heart rate of the wearer and a timestamp of the record. Currently, HR data arrives into
the system from an innovative device called Fitbit Charge 2 [45], which measures the beats
per minute by using LED lights which reflect onto the surface of the skin. When the heart is
beating, the capillaries expand and contract based on blood volume changes. Consequently,
this fluctuation is processed by calibrated algorithms which are applied to measure heart rate
automatically, and most importantly, in a continuous fashion.
Some of the latest smart watches are Wi-Fi enabled, and other devices might only be able
to initiate a Bluetooth connection with another device, in which case most of them have a
proprietary SDK available. In the latter case, a program can be implemented as a computer
or a mobile phone application to fetch data from the sensor and pass it on to our endpoints.
In our situation, a FitBit bracelet is capable of syncing data with a mobile phone application,
which consequently makes the data available via an external endpoint.

4.3 User manual


To run locally, the script start.sh provided with the application needs to be run. The interface
is then available by typing localhost:5000 in the browser of choice. Firstly, the caregiver must
register an account in the application. On the first screen, one must click on the Create account
button in the upper navigation bar if they have not already signed up for the service. Otherwise,
they can use the username and password chosen at sign-up and proceed. When registering, the
new user must fill a form with their details: username, first and last name (which are optional),
email and a password. Also, there is an option to reset your password if it is forgotten. After
creating an account and logging in, a new tab appears on the navigation bar: Health Monitoring
Panel and the user has the option to connect a care receiver and change the password. In the
panel, the caregiver can check the current heart rate of the care receiver (and if it is abnormal)
and the intensity level of their current activity. Also, a notification is issued whenever the
system detects a falling happening. This synchronizing happens automatically, but for other
data retrieval, the sync needs to be done manually by clicking the Refresh button in the right
upper corner.
For the application to give optimal results, it is advised for the caregiver to make sure that
the movement sensor (in our case, the phone) is securely strapped at waist-level, where the
arms end. Also, the heart rate sensor needs to be properly fixed on the surface of the skin so
that it can accurately detect needed data. The application will function with any of the two
sensors missing, but the results may not be as relevant.
Next, the sensor data sources need to be set up. The caregiver must click on the button
in the right-upper corner titled Connections, under the Account menu. At first, the caregiver
needs to insert some essential details about the person they are taking care of: full name (which
is later used in the panel), age, sex, weight, and height. A movement sensor can be connected
CHAPTER 4. PULSE REVIEW (PULSER) APPLICATION 36

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

Future work and conclusions

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.

[6] Leo Breiman. Bagging predictors. Machine learning, 24(2):123–140, 1996.

[7] Leo Breiman. Random forests. Machine learning, 45(1):5–32, 2001.

[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.

[10] E. Chiauzzi, C. Rodarte, and P. DasMahapatra. Patient-centered activity monitoring in


the self-management of chronic health conditions. BMC medicine, 13(1):77, 2015.

[11] Daniela Crăciun. Continuous physical health monitoring and classification for distress
detection. Sesiunea de Comunicari Stiintifice ale Studentilor, Cluj-Napoca, 2017.

[12] A. Dasgupta, Y. V. Sun, I. R Knig, J. E. Bailey-Wilson, and J. D. Malley. Brief review


of regression-based and machine learning methods in genetic epidemiology: The genetic
analysis workshop 17 experience. Genetic Epidemiology, 35:5–11, 2011.

[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.

[21] Reid Johnson. Ensemble methods. 2014.

[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.

[26] M.M. Morrison. Inertial measurement unit, 1987. US Patent 4,711,125.


BIBLIOGRAPHY 41

[27] Q. Mourcou, A. Fleury, C. Franco, F. Klopcic, and N. Vuillerme. Performance evaluation of


smartphone inertial sensors measurement for range of motion. Sensors, 15(9):23168–23187,
2015.

[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.

[31] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blon-


del, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau,
M. Brucher, M. Perrot, and E. Duchesnay. Scikit-learn: Machine learning in Python.
Journal of Machine Learning Research, 12:2825–2830, 2011.

[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.

[36] Armin Ronacher. Flask, a Python Web Microframework. http://flask.pocoo.org.

[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.

[43] Android Sensor Documentation. https://developer.android.com/reference/


android/hardware/SensorEvent.html.

[44] Mobile Phone Sensors Microsoft Guide. https://docs.microsoft.com/en-us/windows/


uwp/devices-sensors/sensors.

[45] Fitbit Charge 2 Band. https://www.fitbit.com/charge2.

[46] Intraday HR Retrieval Fitbit Guide. https://dev.fitbit.com/docs/heart-rate.

You might also like