Abstract
Activity classification consists in detecting and classifying a sequence of activities, choosing from a limited set of known activities, by observing the outputs generated by (typically) inertial sensor devices placed over the body of a user. To this end, machine learning techniques can be effectively used to detect meaningful patterns from data without explicitly defining classification rules. In this paper, we present a novel Body Sensor Network (BSN)-based low complexity activity classification algorithm, which can effectively detect activities performed by the user just analyzing the accelerometric signals generated by the BSN. A preliminary (computationally intensive) training phase, performed once, is run to automatically optimize the key parameters of the algorithm used in the following (computationally light) online phase for activity classification. In particular, during the training phase, optimized subsets of nodes are selected in order to minimize the number of relevant features and keep a good compromise between performance and time complexity. Our results show that the proposed algorithm outperforms other known activity classification algorithms, especially when using a limited number of nodes, and lends itself to real-time implementation.
Keywords
Introduction
Wireless Sensor Networks (WSNs) are attracting a relevant interest in many applications, typically associated with monitoring of particular environments. Body Sensor Networks (BSNs) are a special class of WSNs, where wireless nodes are applied to a user body in order to monitor and detect some activities, e.g., activities of daily living (ADL), performed by the user. Relevant applications of these systems include long-term remote monitoring (e.g., at home) of the activities performed by a user (e.g., elderly people or post-rehabilitation patients), typically for medical purposes [15].
Past work on BSN activity classification algorithms has relied on accelerometers placed in multiple locations over the body [2,10]. A performance improvement can be observed using multiple types of sensors [1,11,16,21]. Since the involved data are characterized by a high dimensionality and large variability, there is an inherent difficulty in determining exact classification rules. For such reason, machine learning and data mining techniques have gained an increasing interest due to their strength in “learning” ad-hoc rules and detecting significant patterns, provided that some data are given to the algorithm for “training” purposes. Regardless of the considered type of sensor, an activity classification algorithm is indeed generally composed of two phases: a training phase, typically used for calibration and parameters estimation purposes; and an online (classification) phase, possibly executed in real time. The training phase aims at identifying activity-specific features from the signals generated at each sensor, after manual [11] or automatic [9,20,22] signal segmentation. Regarding classification, most of the works in the literature tend to adopt thresholding or to use k-Nearest Neighbors (k-NN) algorithms, because of their simplicity and applicability on low-cost mobile devices [10,16]. However, more sophisticated machine learning techniques have also been considered, such as those based on the use of decision trees [2], support vector machines [6], or hidden Markov models [13,21]. Furthermore, machine learning techniques for activity classification typically require also the development of robust methods to address issues such as feature selection and classification [17], decision fusion and fault-tolerance [3,19,23].
In this work, we design a novel low-complexity automatic BSN-based activity classification algorithm, which aims at detecting and classifying a sequence of activities, choosing from a list of known activities, by observing accelerometric data. A preliminary training phase is used to automatically optimize key parameters of the algorithm. The goal of the training phase is that of selecting a proper subset of nodes in order to minimize the number of relevant features, yet guaranteeing an accurate activity classification degree. The classification performance of the proposed algorithm is analyzed using publicly available experimental data [14] (in part generated in the context of the Opportunity Challenge [4,18]), thus providing a valid and unbiased benchmark for comparisons with other algorithms. In particular, the classification algorithm is tested on four activities, which correspond to different locomotion modes: stand, walk, sit, and lie. The proposed algorithm outperforms, especially when using a limited number of nodes, other known low-complexity algorithms, such as the k-NN, the Nearest Centroid Classifier (NCC), the Linear Discriminant Analysis (LDA), and the Quadratic Discriminant Analysis (QDA) [4,5,12]. The obtained results are very promising, making the proposed algorithm suitable for real-time activity monitoring applications.
The rest of this paper is structured as follows. In Section 2, the experimental setup and the performance metric are preliminary introduced, followed by the derivation of the proposed algorithm. Section 3 is dedicated to performance analysis. Finally, in Section 4 concluding remarks are given.
Method
Experimental setup and performance metrics
As anticipated in Section 1, the experimental data used to test our algorithm are shared data collected in the context of the European project Opportunity and provided for the so-called Opportunity Challenge [4,14,18]. Figure 1 shows the experimental configuration of the sensor nodes in the considered BSN. The output of the BSN consists of mainly accelerometric data, integrated, for some nodes, with gyroscopic and magnetometric data – in this work, in order to guarantee a low hardware complexity (and, consequently, a low cost and large battery life of the whole activity classification system), only accelerometric data will be used.1
To this end, note that the cost of a gyroscope (or of a magnetometer) chip is typically at least twice that of an accelerometer chip. Similar considerations hold for power consumption requirements, as accelerometers require indeed much less power than gyroscopes and magnetometers do. This has obviously a strong impact on the battery lifetime.

Given a discrete set of predefined activities
Note that, while evaluating the algorithm performance, the samples containing “undefined” activities (e.g., transitions between classifiable activities), because of the temporal continuity of the collected data, are not taken into account for the evaluation of
Generally, an activity classification problem leads to the design of an algorithm that can estimate the sequence of occurrences of specific activities choosing from a discrete set of predefined activities
In the following, a detailed description of the operational steps of the proposed algorithm are presented. After preliminaries on data preprocessing, the online and training phases are presented. In order to run properly, the online activity classification algorithm needs some parameters that have to be estimated and optimized during the training phase. Even though, practically, the training phase precedes the online phase, in the remainder of this subsection, after preliminaries on data processing and feature extraction, we first describe in detail, for ease of presentation, the online phase. In the training phase, the same steps of the online phase are considered, with the only difference that known (labeled) data are used to tune the key parameters of the algorithm, which are then kept constant in the (following) online phase.
Preliminaries on data preprocessing and feature extraction
At each node, an accelerometer outputs a stream of three-dimensional data, which corresponds to the accelerations measured by the sensor in its three reference axes. More formally, let us define the three-dimensional acceleration vector, measured at the i-th epoch, as
Starting from the filtered signal, at the i-th epoch, two types of simple features are of interest and can be extracted. The first one, denoted as p-feature (where “p” stands for “parallel”) and indicated with
Note that, by normalizing the acceleration vector (for the p-feature), we are implicitly assuming that no linear acceleration is present (i.e., the device is still) and only the gravity acceleration contribution (i.e., 1 g) is measured by the accelerometer. Note that, although this assumption is not always true, in the majority of human movements it is true that the magnitude of the linear acceleration is rather lower than that of the gravity component.
The second considered feature, denoted as dev-feature and indicated with
More details about the definition of the window, especially at the borders of the acceleration signal, are given in [8].
Considering a single activity
For each considered activity, the proposed activity classification algorithm aims at automatically selecting the best nodes in the BSN and the corresponding most significant feature types, that can best discriminate the occurrence of the considered activity (e.g., the thigh node is intuitively one of the best nodes to estimate a “sit” activity, whereas the feet nodes give relevant information about the “walk” activity). More formally, let us define as
Note that, throughout this paper, the term “optimal” and the superscript “*” are equivalently used with reference to the tunable parameters considered in the proposed algorithm. Furthermore, if not stated otherwise, the optimality is always intended in terms of classification performance through the f1 score (when activities are independently considered) and the weighted f1 score (when activities are combined together).
The proposed algorithm identifies activities by properly thresholding the selected features. In particular, referring to a given feature f, an activity a is considered as detected at the samples in correspondence to which the feature (type) is between the (lower and upper) thresholds
In order for the activity classification algorithm to output a single sequence
The online phase of the proposed algorithm is based on three main steps: (i) a first coarse classification step; (ii) a refinement step; (iii) and a final priority-based activity combination step.
Concerning the first coarse classification step, which is executed independently for each activity to be classified, a specific activity a is detected at epoch i (i.e.,
In the first coarse classification step, a single occurrence of an activity can be missed (because of little pauses or random movements). This can be avoided, or at least mitigated, by applying to the detected activity windows a refinement step which takes into account the length of the estimated activity windows. More specifically, given a specific activity a, in our implementation the refinement step is based on the following sequential operations: (1) every “null window” (a group of consecutive “0”s), with a length (in terms of number of samples) shorter than
Finally, the priority-based activity combination step consists in combining the sequences
Algorithm training
In order to work effectively, the proposed algorithm needs to be properly trained by exploiting the part of collected data for which the occurrences of the activity of interest are correctly (manually) labeled. The training phase aims at estimating the optimal values of the key parameters that will be used in the online phase. In particular, for each activity a the following parameters need to be estimated: (i) the optimal subset of features
A detailed flow diagram of the implementation steps of the training phase of the proposed algorithm is shown in Figs 2, 3, and 4 and will be now described, distinguishing between its three component blocks (the same of the online phase): (i) the first coarse classification step; (ii) the refinement step; and (iii) the final priority-based activity combination step.

Detailed flow diagram of the implementation steps of the proposed algorithm’s training phase: the first coarse classification step.

Detailed flow diagram of the implementation steps of the proposed algorithm’s training phase: the refinement step.

Detailed flow diagram of the implementation steps of the proposed algorithm’s training phase: the final priority-based activity combination step.
Coarse classification At the beginning of the coarse classification step, shown in Fig. 2 and executed for each activity a, the set
The goal of the first part of the coarse classification step is to estimate and store the activity windows

Description of the thresholds estimation step, which appears in Fig. 2, for an illustrative acceleration signal produced at the thigh node: (a) acceleration signal (the x, y, and z components are highlighted); (b) p-feature (straight line) and dev-feature (dashed line) extracted from the previous acceleration signal; PMFs of (c) p-feature and (d) dev-feature evaluated in the “sit” intervals.
In order to clarify the process which leads to the identification of the thresholds for activity classification, we consider an example relative to the acceleration signals produced at the thigh node (i.e., node 1 in Fig. 1) and used to detect the “sit” activity. An illustrative description of the thresholds estimation step is shown in Fig. 5: the p-feature (i.e.,
The second part of the coarse classification step, still performed independently for each
Given a combination
Refinement The next refinement step, shown in Fig. 3 and executed for each activity a, retraces the operations of the previous step in order to estimate the optimal thresholds
These values should be properly chosen in the order of at most a few seconds in order to filter out just the windows of samples which correspond to little pauses or random movements.
Priority-based activity combination During the final step, shown in Fig. 4, the optimal list of activities’ priorities
At this point, for given
At the end of the training phase, for each activity a, the optimal
The performance of the proposed algorithm has been evaluated for the classification of activities related to modes of user locomotion. In particular,
Configurations of nodes and features
Overall, we consider 38 different configurations of nodes (and feature types): configurations 1–31 (with at most 7 nodes) apply to the proposed algorithms and the four considered existing classification algorithms (k-NN, NCC, LDA, and QDA) and rely on the use of accelerometric data; configurations 32–38 (with more than 7 nodes) apply only to the four considered existing classification algorithms and rely on the use of other (besides accelerometers) inertial sensors (e.g., magnetometers). Each configuration involves a specific nodes’ configuration, explicitly shown in the x axis of Fig. 6 (which will be described in the next subsection) with reference to the node number in Fig. 1.
Note that, given a set of activities that need to be classified, the number and placement of the devices could be preliminary devised and used by determining which devices may provide the most different signal patterns in correspondence to different activities. However, in this work we take advantage of the fact that an exhaustive dataset was provided in the Opportunity Challenge [4,14,18], since the BSN used to acquire the given dataset was composed by a large number of sensor devices placed all over the users’ body. The automatic selection of the best devices and features is then left to the “artificial intelligence” of the algorithm (specifically, during the training phase). In this way, some sensor devices, which could have appeared to be intuitively useless at classifying some activities, may be instead selected as good candidates. Furthermore, once the best set of devices is determined, the proposed approach also allows to automatically determine the best subset of devices and features for each activity that has to be classified and such subset may likely change from activity to activity.

Average (over 4 subjects) classification performance (i.e., weighted f1 score) as a function of the considered configurations of nodes. The performance of the proposed algorithm is compared with that of some existing algorithms, averaging the performance of the four considered subjects. For every configuration, the considered subsets of BSN nodes (numbered as in Fig. 1) are highlighted. The features per configuration and per algorithm are properly selected as summarized in Section 3.1.

Average (over 4 subjects) classification performance (i.e., weighted f1 score) as a function of the considered (a) number of nodes and (b) number of features. For each considered algorithm, the configurations which use the same number of (a) nodes or (b) features have been averaged together.
The choice of the nodes’ feature types for each classification algorithm can be summarized as follows.
for configuration 34: every node equipped with gyroscope and magnetometer (i.e., nodes from 13 to 21) produces 6 additional features (3 from gyroscope and 3 from magnetometer);
for configuration 35: 6 additional features (3 from gyroscope and 3 from magnetometer) are extracted at node 13;
for configuration 36: 3 additional gyroscopic features are extracted at node 13;
for configurations 37 and 38: 3 additional magnetometric features are extracted at node 13.
The performance of the proposed algorithm has been evaluated for 31 different configurations of nodes in order to determine the optimal subset of BSN nodes (and, thus, of features) useful for the activity classification. In particular, in Fig. 6, the performance of our algorithm (in terms of
In order to better investigate the impact of the number of nodes on the performance of the considered algorithms, in Fig. 7(a) the performance of the considered algorithms is properly averaged over all configurations with the same number of nodes. It can be observed that, for a given number of nodes in the BSN, our algorithm, making use of configurations with at most 7 nodes, outperforms the others. Moreover, with only 7 nodes, our algorithm outperforms all existing algorithms, including the k-NN and QDA, run with a much larger number of nodes (e.g., 21).
Another aspect to take into account is the number of features used in the algorithms. Unlike the existing algorithms, where each node generates at least three features,7
The typical features computed at each node are the mean of every acceleration component within a sliding window. In addition, other six features are considered for nodes provided with gyroscopes and magnetometers. A standard deviation-related feature has been also used giving however poor performance.
For the sake of completeness, we want to highlight that, if the previously cited configurations 15, 16, 17, 18, 21 in Fig. 6 (which do not use node 1 in Fig. 1) are not taken into account for the evaluation of the curves in Fig. 7, the performance of our algorithm improves significantly more (in relative terms) than those of the other algorithms.
Finally, on the basis of the previous results, configuration 22 (as denoted in Fig. 6) can be identified as the best configuration of nodes for our algorithm. In particular, it needs 5 nodes (namely, nodes {1, 2, 13, 19, 21} in Fig. 1) and generates
The time complexity of the proposed algorithm has been evaluated and compared with those of the classification algorithms previously considered for performance comparison.8
Recall that, we here consider the time complexity of the online phase due to its impact on real-time applicability of the algorithm and due to the fact that the training phase should be performed just once (offline), provided that the BSN configuration does not change over time.
the number of activities is typically quite larger than the size of the training dataset (i.e.,
the classification performance of the proposed algorithm, when considering a few features (i.e., for small values of F), is far better than those of the NCC, the LDA, and the QDA algorithms (and also slightly better than that of the k-NN algorithm).
Time complexity of the online phase for the considered algorithms

Average (over 4 subjects) classification performance (i.e., weighted f1 score) of the proposed algorithm in the presence of simulated rotational noise: (a) the weighted f1 score as a function of the intensity of the simulated rotational noise; (b) the admissible range of rotations as a function of the weighted f1 score. The previously estimated optimal configuration of nodes (i.e., configuration 22, as denoted in Fig. 6) is considered. Indicative thresholds (dashed lines), corresponding to an admissible minimum performance of
A typical problem of a real BSN scenario consists of unwanted rotations in the displacement of the BSN nodes, that can differ between the training and the online phases. It is then of interest to investigate the robustness of BSN-based activity classification algorithm to rotational noise. To this end, artificial rotational noise has been added to the accelerometric data, simulating possible rotations of a device around its three reference axes. We remark that modeling rotations around the accelerometer axes, rather than around the body axes, is just an assumption, which is made to avoid taking devices position shifts also into account. It is, however, a reasonable assumption, since the position shifts would be rather limited.
Two considerations can be preliminary made: the dev-feature is actually insensitive to rotational noise, due to its definition; the p-feature is invariant to rotational noise around the axis about which the feature is measured (i.e., the one parallel to the related body segment, which we assume to be the y axis for every device). For such reasons, the rotational noise is then being only added to p-features and the device rotations have been simulated only around its other two axes, namely (due to the previous assumption) the x and z axes. More specifically, from now on, we assume that the x axis is directed from the front to the back of the user, whereas the z axis is directed from his/her right side to his/her left side. For ease of simplicity, we only simulate rotations around one axis at a time.
In Fig. 8(a), the average performance of our algorithm (averaged over the 4 considered subjects) is shown as a function of the intensity of the simulated rotational noise (in terms of degrees of rotation with respect to the initial orientation), for the previously estimated (at the end of Section 3.2) optimal configuration of nodes (i.e., configuration 22, as denoted in Fig. 6). In Fig. 8(b), for the same configuration 22 (as denoted in Fig. 6) and averaging over the same 4 subjects, the curves show the range of rotations that can be applied to the nodes in order to keep a user-defined admissible minimum performance (in terms of weighted f1 score). The results in Fig. 8 show that our algorithm, possibly due to the nature of the activities that we want to classify, suffers less from rotations around the z axis than those around the x axis. As an example, if one accepts as a minimum acceptable performance a
We also remark that, due to the realistic data collection (often operated in different times with respect to the training acquisition), the testing data (used in the online phase) implicitly presents real rotational noise. Therefore, the results previously presented implicitly assume that the proposed algorithm has to combat some rotational noise.
Conclusion
In this work, a simple, yet effective, activity classification algorithm has been presented. Its performance has been evaluated and compared with that of existing algorithms. The data used to test the algorithms are publicly available and, thus, represent a valid and unbiased benchmark for the evaluation of the performance of different algorithms. The proposed algorithm is based on simple comparisons of properly selected features with thresholds that are automatically optimized during a preliminary training phase performed once (offline). In order to simplify the operations of the online phase of the algorithm, the training phase is also used to automatically select the optimal subset of nodes and features to be used.
The time complexity of the proposed algorithm has also been evaluated. Our results show that its complexity is on the order of that of existing algorithms, but its performance is better. On the other hand, some of the existing algorithms show a performance similar to that of ours at the cost of higher complexity. In particular, our algorithm significantly outperforms the others when using a small numbers of nodes and features. Taking also into account its robustness against rotational noise, it can be concluded that the proposed algorithm can be used effectively for real-time activity classification, especially when some constraints on the number of BSN nodes are introduced.
