Human activity recognition using smartphone sensors like accelerometer is one of the hectic topics of research. HAR is one of the time series classification problem. In this project various machine learning and deep learning models have been worked out to get the best final result. In the same sequence, we can use LSTM (long short term memory) model of the Recurrent Neural Network (RNN) to recognize various activities of humans like standing, climbing upstairs and downstairs etc.
LSTM model is a type of recurrent neural network capable of learning order dependence in sequence prediction problems. This model is used as this helps in remembering values over arbitrary intervals.
Human Activity Recognition dataset can be downloaded from the link given below: HAR dataset
Accelerometers detect magnitude and direction of the proper acceleration, as a vector quantity, and can be used to sense orientation (because direction of weight changes). GyroScope maintains orientation along a axis so that the orientation is unaffected by tilting or rotation of the mounting, according to the conservation of angular momentum.
Understanding the dataset:
- Both the sensors generate data in 3D space over time.
(‘XYZ’ represents 3-axial signals in X, Y, and Z directions.)
- The available data is pre-processed by applying noise filters and then sampled in fixed-width windows ie., each window has 128 readings.
Train and Test data were separated as
The readings from 80% of the volunteers were taken as training data and remaining 20% volunteers records were taken for test data. All the data is present in the folder downloaded using the link provided above.
- Choosing a dataset
- Uploading the dataset in the drive to work on google colaboratory
- Dataset cleaning and data Preprocessing
- Choosing a model and building deep learned network model
- Exporting in Android Studio.
The IDE used for this project is Google Colaboratory which is the best of the times to deal with deep learning projects. Phase 1 was explained above as from where the dataset is downloaded. In this sequence to start with the project open a new notebook in Google Colaboratory first import all the necessary libraries.
It is uploading dataset in the notebook, before doing that we need to mount the notebook on drive so that this notebook is saved on our drive and retrieved whenever required.
You will see a pop up similar to one shown in the screenshot below, open the link and copy the authorization code and paste it in the authorization code bar and enter the drive will be mounted.
Code: Uploading the dataset
Now moving on to model building and training phase, we need to look for different models which can help in building better accuracy model. Here, LSTM model of Recurrent Neural Network is chosen. The image given below shows how the data looks.
It begins with the data pre-processing. It is the phase where ~90% of time is consumed in actual data science projects. Here, raw data is taken and converted in some useful and efficient formats.
Code: Data transformation is performed to normalize the data
Code: Splitting the dataset
The test size is taken as 20% i.e. out of the total records 20% of records are used for test accuracy while rest is used for training model.
Number of classes = 6 (Walking, Sitting, Standing, Running, Upstairs and Downstairs)
Phase 4: In this phase model chosen is the LSTM model of RNN.
Code: Model building
Code: Performing optimization using AdamOptimizer to modifier loss values wrt the variables to improve accuracy and reduce loss.
Code: Performing 50 iterations of model training to get the highest accuracy and reduced loss
So, with this approach the accuracy reaches nearly ~1 at 50th iteration. This indicates that most of the labels are identified clearly by this approach. To get the exact count of correctly identified activities confusion matrix is created.
Code: Accuracy graph
Confusion Matrix: A confusion matrix is no less then a 2D matrix unlike it helps calculating exact count of activities correctly identified. In other words, it describes the performance of the classification model on the set of test dataset.
Code: Confusion matrix
This is the complete description about the project so far. It can be built using ther models like CNN or machine learning models like KNN.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course