The objective of activity recognition is to recognize human activities in real life situations. The major challenge of this type of problems relies on the complexity of human activity.
The aim of this example is to use artificial neural networks in order to predict human activity from data collected by a smartphone.
The experiments have been carried out with a group of 30 volunteers within an age bracket of 19-48 years. Each person performed six activities (WALKING, WALKING_UPSTAIRS, WALKING_DOWNSTAIRS, SITTING, STANDING, LAYING) wearing a smartphone on the waist. Using its embedded accelerometer and gyroscope, we captured 3-axial linear acceleration and 3-axial angular velocity at a constant rate of 50Hz. The experiments have been video-recorded to label the data manually.
The sensor signals (accelerometer and gyroscope) were pre-processed by applying noise filters and then sampled in fixed-width sliding windows of 2.56 sec and 50% overlap (128 readings/window). The sensor acceleration signal, which has gravitational and body motion components, was separated using a Butterworth low-pass filter into body acceleration and gravity. The gravitational force is assumed to have only low-frequency components, therefore a filter with 0.3 Hz cutoff frequency was used. From each window, a vector of features was obtained by calculating variables from the time and frequency domain.
The data set contains 10299 instances, each of them with 561 inputs and one categorical target. The target has six different classes, each of them corresponding to one of the previously mentioned activities. The next chart shows the number of instances belonging to each class in the data set.
As we can see, the data set is well balanced since the number of instances belonging to each category is similar. The class with the largest number of instances (1906) is "STANDING" while the one that has the least number is "WALKING_UPSTAIRS" with 1544.
In this section, we are going to design the model that we will train later to approximate the number of particles adhering per unit area.
The model will be a neural network composed by:
The following table depicts the size of each layer and its corresponding activation function. The number of layers in the neural network is 2, the number of inputs is 561, the number of outputs is 6 and the number of hidden nuerons in the hidden layer is 3.
The scaling and unscaling method that we are going to use is the minimum-maximum and we will set the normalized squared error as error method for the loss index.
The procedure used to carry out the learning process is called training (or learning) strategy. The training strategy is applied to the neural network in order to obtain the best possible performance. The type of training is determined by the way in which the adjustment of the parameters in the neural network takes place.
The following chart shows how the training loss and the selection loss decrease with the iterations of the quasi-Newton method during the training process.
As we can see, the behaviour of both curves is similar along the iterations which means that no over-fitting has appeared. The initial values of the training loss and the selection loss were 1.34579 and 1.33511, respectively. After 345 iterations, the training loss has decreased to 0.120958 and the selection loss is 0.0718509.
The next table shows the training results by the quasi-Newton method. They include some final states from the neural network, the loss functional and the training algorithm.
Here the final parameters norm is not very big and the final loss and gradient norm are closed to zero. The total training time was around 108 second.
Once the model is trained, we are going to test its prediction capacity with a subset of data that have not been used before neither for training nor for selection.
The next table shows the confusion matrix for our problem. In the confusion matrix, the rows represent the target classes and the columns the output classes for the testing target data set.
As we can see, the number of instances that the model can correctly predict is 2022 while it misclassifies only 37. This shows that our predictive model has a great classification accuracy.
The neural network is now ready to be used to predict activity of new people in what it is called the production phase.
By clicking on "write expression" task yo can obtain the mathematical expression that represents the model of this study. It can be implemented in other software to make predictions on new data.