avatarPetros Demetrakopoulos

Summary

The article outlines the development of a fall detection model using unsupervised learning techniques applied to smartphone sensor data.

Abstract

In response to the growing concern for fall-related injuries among the elderly, the article presents a practical approach to fall detection by leveraging the motion sensors embedded in smartphones. The author collected data using a sensor logger app, simulating falls, and analyzed the sensor readings to identify distinct patterns associated with falling. Through data preprocessing, normalization, and feature extraction, the model focuses on time-based analysis using sliding windows and statistical moments to classify movements. The application of clustering algorithms, specifically K-Means, enables the detection of falls by distinguishing between 'walking' and 'falling' signals. The project demonstrates the potential of machine learning in enhancing senior care and emergency response, with the full code available on GitHub.

Opinions

  • The author emphasizes the importance of fall detection technology in an aging society, suggesting it as a potentially lifesaving solution.
  • Smartphones are posited as a readily available tool for fall detection due to their built-in motion sensors, eliminating the need for specialized hardware.
  • The use of unsupervised learning, particularly K-Means clustering, is presented as an effective method for distinguishing between different types of movement without the need for labeled datasets.
  • The article suggests that the integration of smartphone sensors and machine learning could significantly improve the quality of life for the elderly and prompt timely interventions in the event of a fall.
  • The author advocates for the broader application of existing algorithms and methods in fall detection, indicating their significant performance in real-world scenarios.

Creating a Fall Detection Model Using Unsupervised Learning

Source: Image by Harlie Raethel on Unsplash

Introduction

In our rapidly aging society, the risk of falling has become a growing concern. For elderly individuals, a fall can have grave consequences, ranging from painful fractures to hospitalization and, tragically, even death. Moreover, for those who live alone, there’s often no one around to call for help in the event of a fall. In such challenging circumstances, a wearable fall detector emerges as a practical and potentially lifesaving solution.

What’s remarkable is that many smartphones are already equipped with an array of sensors designed to measure motion. These sensors include accelerometers, gyroscopes, and gravity sensors. When worn on the body, be it in a pocket or with a cord around the neck, smartphones can effectively detect movements associated with our daily activities. Thanks to the availability of apps, it’s now possible to access and analyze the raw sensor data collected by these smartphones.

One particularly promising approach to detecting falls from movement sensors input involves the use of clustering algorithms. These powerful tools enable us to distinguish signals with different characteristics. Falling behavior, for instance, exhibits distinct patterns of acceleration and orientation when compared to our regular daily activities like walking or standing still. By applying clustering algorithms, we can effectively isolate falling movements from the noise of everyday motion, thereby enhancing our ability to detect and respond to potential falls promptly.

The data

In order to gather data for the project I installed a sensor logger app on my smartphone (available App Store for iOS and on Play Store for Android) and I started recording the values from accelerometer, gravity and gyroscope sensors while walking. Then, after walking for a while, I simulated a fall by suddenly kneeling in a quick way while walking. I repeated the pattern 5 times and then exported the recorded signals to .csv files using the relevant feature of the sensor logger app.

The raw signal from the accelerometer in the 3 axis that the sensor counts the acceleration on is presented in the following plot. Horizontal axis represents the seconds elapsed since the beginning of the recording and vertical axis represents the reading of the accelerometer sensor on each of the 3 axis. Signals for gravity and gyroscope sensors are similar.

Source: Image by the author.

From the plotting of the accelerometer signal on the 3 axis, we can already easily distinguish the patterns that correspond to a simulated fall. The high fluctuation (which is more dominant on the Z-axis) around 10, 25, 45, 60 and 80 seconds is caused by the increased acceleration in the Z-axis during the fall. This is the pattern that our model needs to capture.

As readings for each sensor are saved by the sensor logging app on separate .csv files, we need to merge them. Thankfully, the sampling rate for the 3 different sensors are identical and as long as the readings of different sensors have been captured within the same recording, they are aligned in time (if they were not, we would have additional work to align the signals / time series).

The reading and merging of readings from the 3 different sensors (Accelerometer, Gyroscope, Gravity) is performed with the function shown below

Data Preprocessing

A good practice when tackling with signal from various input sources (as in our case) is to normalize the signal. We do so for various reasons that are out of the scope of this short article and are related to avoiding numerical stability, invariance of possibly different scales of the different components of the signal and convergence speed of the machine learning algorithms applied at later stages.

Normalization is performed by subtracting the mean of each column and then dividing by the standard deviation. This method is known as the z-score normalization method (or standardization). Obviously, we perform this normalization only on the sensors readings columns and not on the time column (containing the timestamps for each sensor reading)

Feature extraction

Despite what we may believe, a fall does not occur in a single time moment, or at least this is the case for the immense sampling rates of the sensors of our smartphones. A fall typically follows a specific pattern in the sensors signals that is evolving over a short, but existing, period of time (aka a time window). Thus, we have to shift our focus from instantaneous detection of a fall to time-based analysis.

In order to achieve this, we use the sliding window method, which computes/extracts the features that are important to classify if a fall has happened within a specific time window or not by “sliding” a window of fixed time length (usually given as an integer indicating the discrete time moments when each sample was recorded) over the whole signal. However, to better capture the relations between different time windows, we set a fixed overlap between each window and the previous one. Thus, each window has a part of samples that is common to the previous window.

But which features of data may be meaningful? There are many techniques out there that can extract meaningful features for a continuous signal. These methods include Frequency Domain Analysis (usually implemented using Fast Fourier Transform to identify dominant frequencies), Signal Magnitude Area (SMA), Signal Entropy, Cross-Correlation and Signal Decomposition. However, we will focus and use the simplest one which is the calculation of Statistical Moments (min, max, mean, standard deviation, skewness and kurtosis) of the signal for each time window.

The function below performs the feature extraction as described and returned the statistical moments for each time window

Plotting extracted features

After performing Principal Component Analysis ((imported from scikit-learn), we can plot the 2 most important components to observe possible clusters.

Source: Image by the author.

From the plot above, it is evident that there is a cluster for the majority of the points (most probably related to the “walking” part of our signal, as this part covered the most part during data recording) and the rest of the points are scattered across the grid. These points probably correspond to the part of the signal (time windows) captured during the fall.

So now we have to find a machine learning method that distinguishes between these 2 categories. As our data are unlabeled, we should certainly look for an unsupervised machine learning method. The most appropriate task to distinguish between categories of unlabeled data is clustering.

Clustering using K-Means

K-Means is a simple yet efficient algorithm that can discover clusters in unlabeled data. The main parameter needed to define an instance of the algorithm is the number of clusters that we need to split data into. Despite there are formal methods to find out the optimal number of clusters, such as the Elbow method , we select 2 clusters because there are only 2 discrete patterns in our signal (walking and falling).

Keep in mind that this is a simplification we did for demonstration purposes, as in real life signal may be far more complex and noisy including several other patterns.

Then we fit the K-means algorithm (imported from scikit-learn) on the features extracted from the captured signal and then predict the clusters for them. Then, we plot again the 2 first principal components but this time we assign a color to each point corresponding to the cluster predicted by the model for it.

Source: Image by the author.

We observe that the model has correctly assigned the points corresponding to the walking pattern (red) in a single cluster and the rest of the points (blue) that correspond to the fall to another cluster. This is an indication that the model is able to detect fall.

In order to verify this, we can plot predictions for clusters over time and see how aligned they are with the signal from the accelerometer sensor we presented in the beginning of the article.

Source: Image by the author.

Putting it all together

The following code performs all the procedures mentioned from the beginning of the article and produces all relevant plots.

The full code of the project can be found on this GitHub repo.

Conclusion

The integration of smartphone sensors and advanced data analysis techniques presents a promising solution to the issue of fall detection among the elderly. Existing algorithms and methods exhibit a significant performance in effectively detecting falls and thus they should probably be used on a broader level. This article / demonstration underscores the potential of machine learning not only to enhance the quality of life for seniors but also to save lives by enabling timely responses to falls.

Rsources

[1] Data Normalization with Pandas, GeeksforGeeks, geeksforgeeks.org. https://www.geeksforgeeks.org/data-normalization-with-pandas/, [Accessed 04–10–2023]

[2] Carnegie Mellon University, Lecture Slides: Machine Learning for Signal Processing, 2013, http://mlsp.cs.cmu.edu/courses/fall2013/lectures/handouts/Class12.pdf

[3] Jothi, R. (2022). Wearable Fall-Detection Using Deep Embedded Clustering Algorithm. In: Mathur, G., Bundele, M., Lalwani, M., Paprzycki, M. (eds) Proceedings of 2nd International Conference on Artificial Intelligence: Advances and Applications. Algorithms for Intelligent Systems. Springer, Singapore. https://doi.org/10.1007/978-981-16-6332-1_69

[4] Albert MV, Kording K, Herrmann M, Jayaraman A (2012) Fall classification by machine learning using mobile phones. PLoS ONE 7(5):e36556

[5] Özdemir AT, Barshan B. Detecting Falls with Wearable Sensors Using Machine Learning Techniques. Sensors. 2014; 14(6):10691–10708. https://doi.org/10.3390/s140610691

[6] Elbow Method for optimal value of k in KMeans, GeeksforGeeks, geeksforgeeks.org. https://www.geeksforgeeks.org/elbow-method-for-optimal-value-of-k-in-kmeans/, [Accessed 04–10–2023]

Machine Learning
AI
Data Science
Clustering
Python
Recommended from ReadMedium