IoT - Internet of Things

With the rise of the Internet of things, IoT, always-connected electronic sensors can be combined with machine learning techniques to control, manage and study numerous phenomena. In this post, we present a use case consisting of the application of Data Analytics techniques using the data provided by the DrivenData competition of the SPHERE (Sensor Platform for Healthcare in Residential Environment) project.

This project was created with the aim of monitoring health conditions of elderly people through a series of low-cost sensors installed in their homes; in this way, the mentioned monitoring activities can be performed unobtrusively and respecting the privacy of the patients. Below, we describe the tasks we have carried out to address the issue raised in this scenario.

Data Description

In the project proposed in the competition, a pilot test of the complete project before launching a test to greater scale, the objective was to recognize a person's position in particular moments of time through the information collected by various sensors installed in the patients' houses.

The figure below shows the map of the house.

The available sensors are:

  • a wristband with accelerometers, worn by the patient
  • passive infrared motion detectors (PIR sensors) in each room
  • three video cameras that provide information in three dimensions
  • received signal strength indicators (RSSI) in four access points within the house

We have defined 20 activities to recognize, which are the following:

  • a_ascend - going upstairs
  • a_descend - going downstairs
  • a_jump - jumping
  • a_loadwalk - carrying something (walking with a load)
  • a_walk - walking
  • p_bent - bent
  • p_kneel - on knees
  • p_lie - lying
  • p_sit - sitting
  • p_squat - squatting
  • p_stand - standing
  • t_bend - from standing to bent
  • t_kneel_stand - from kneeling to standing
  • t_lie_sit - from lying to sitting
  • t_sit_lie - from sitting to lying
  • t_sit_stand - from sitting to standing
  • t_kneel_stand - from standing to kneeling
  • t_sit_stand - from standing to sitting
  • t_straighten - from bent to standing (straightening up)
  • t_turn - turning

The prefix "a_" indicates "ambulation activity", the prefix "p_" indicates "static posture" and "t_" stands for "transition" (transitions between postures).

We have collected the data for this case study in two phases: in the first one, movements are reproduced and, whereas in the second one, we have combined the data extracted from such representations with real movements. This data set constitutes training and validation steps for the study.

The accelerometer's signal is sent in real time to some access points (AP) distributed in the house. If the signal does not reach any of the APs, the accelerometer's variables receive a NaN value at that instant.

Data Preprocessing

As a first step, data must be pre-processed, due to the high volume of the data set and the great differences between values depending on the room. It is a long and tedious process that has consumed more than 70% of the time of this analysis, as described below.

Firstly, all the data offered by the organization is loaded. Data is divided into different files in CSV format, which we had to integrate.

In total, the training data set consists of 16611 measurements of 305 input and 20 output variables, which are the activities to identify.

As the dimensionality of the training data is considerable, we thought it would have been reasonable to reduce the number of dimensions, also because several of them provide redundant or useless information. Also, training a computational model with fewer dimensions would be quicker and more efficient than doing it considering all of them.

A typical problem in IoT projects is that sensors generate a lot of potentially noisy information, which can hinder the creation of models. In this particular case, motion detectors operate using infrared rays and are low cost and prone to failure. For example, the data set presents false positives resulting from the detection of changes in solar radiation, although nobody is in the room. Therefore, the value given by those sensors needs to be adjusted in some way.

The rooms equipped with a video camera give the simplest approximation. The project's participant is the only person living in the house, so if a video camera installed in one of the rooms collects information, it means that he or she is in that room with absolute certainty. That is, if the video camera does not indicate any activity, presence sensors can be deactivated. Obviously, this is not possible in rooms without a video camera.

As far as the other false positives or negatives are concerned, we have checked the values of the five previous instants and the subsequent five for each measurement. If the number of zeroes or ones exceeds a certain threshold, that value is assigned to such position. This task follows the principles of smoothing.

To complete the pre-processing phase, we need to determine the values of NaN data, which are the result of the sensors' wrong measurements. We have used linear interpolation between previous and following instants.

Activity Recognition

To further reduce the dimensionality and divide the problem, as we have the values of user presence, we have decided to separate training and validation data by room to build a particular model for each one of them. Taking into account that we did a preliminary cleaning, separation should not be a problem for prediction, and it simplifies the creation of the model, or rather, the models (one per room).

Thus, for example, for the living room (Living), we have 5283 measurements (rows), each with 20 output variables (20 activities) and 90 input columns (15 for the accelerometers and the remaining for the video cameras). However, for the bathroom (Bath), where there is no video camera, we have 484 measurements (rows), each with 20 output variables but only 15 input columns, the accelerometers.

The criterion used by the organization to assess the estimations made is Brier score, a cost function that measures the accuracy of predictions:

This function calculates the mean squared error between the predictions made and their real value, i.e., the more the obtained score approaches zero, the better, being zero the best score.

As this score is a weighted average, it includes a weight vector wc, whose function is to provide a level of importance to each of the 20 possible activities, penalizing more the errors related to the most frequent activities, or vice versa, valuing more the successes in less frequent events. This vector is given by the organization: the most penalized action is "jumping" (the most common in the data set), while the least penalized is "standing" (less common).

We have evaluated different algorithms. RandomForest, based on decision trees, obtained the best results, as it provided a good score without having to modify data too much or search for specific parameters. We used k-fold cross-validation with K = 5 to find the parameter for the optimal number of estimators.

Once obtained the optimal number of estimators for the algorithm, we trained and performed the predictions taking into account the data of each room individually. The algorithm gives a probability output (from 0 to 1) being each one of the 20 possible activities.

Then, we analyzed data to find out which is the most typical movement throughout the day for the person studied in each room. To do that, we represented the estimates for each room in a boxplot. In order to generate the boxplot, we have calculated all the predictions for the single room, each one with a probability value for all the 20 activities.We have also represented their maximum and minimum values (upper and lower limits of the dashed lines), the median (in red) and the 75% and 25% percentile values (limits of the box).

For example, the following chart displays the probabilities obtained when making estimates for the living room (Living).

As shown, the postures that appear more frequently are “sitting” and “standing”, including also several transitions or changes of position. These data makes sense since such postures are the most common in a living room. You can see some outliers, like “going upstairs” or “going downstairs”. These events do not make sense in this room and are probably due to some issues with the values of the sensors or the limitations of the training algorithm employed.

In the case of the kitchen, "standing" is much more frequent than "walking" or "turning". These data seem reasonable since they reflect what people usually do in a kitchen (“jumping” or “kneeling”, for example, are not habitual actions here).

The situation changes in the case of stairs. Here the chances of going upstairs or downstairs are higher, as well as walking. There are also detections of movements like “standing” or “turning”, which make sense but are less common when talking about stairs.

The activities detected in the bathroom, such as “standing” or “sitting” and their transitions, also seem logical.

Conclusions

Our solution achieves a score of 0.1847 applying the Brier Score, resulting in an excellent position in the ranking: 33 out of 579 (among the 6% top performant groups).

We believe that this approach is certainly a good starting point to build systems that can detect information from sensors, process it, and according to the results, act in compliance with a protocol.

As set out in SPHERE's original paper, a possible application could be a monitoring system for elderly people who live alone. After installing sensors in their home (or even in the rooms of nursing homes), it would be possible to send alerts to a monitoring center if unexpected or atypical activities are detected, as lying in the living room for an extended period.

The aim of this study is to demonstrate that Data Science techniques allow the analysis and interpretation of a data set; in this case the measurements of sensors in an IoT perspective. Our professional team can effectively address Data Analytics projects in any complex scenario with the maximum guarantees of success. If you would like more information about this area, please do not hesitate to contact us. We will be glad to help.

[translated by Luca de Filippis]