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.
- ML - Saving a Deep Learning model in Keras
- DeepPose: Human Pose Estimation via Deep Neural Networks
- Difference Between Artificial Intelligence vs Machine Learning vs Deep Learning
- Artificial intelligence vs Machine Learning vs Deep Learning
- Introduction to Multi-Task Learning(MTL) for Deep Learning
- Deep Face Recognition
- Difference Between Machine Learning and Deep Learning
- Learning Model Building in Scikit-learn : A Python Machine Learning Library
- Deep Q-Learning
- Introduction to Deep Learning
- ML - List of Deep Learning Layers
- Implementing Deep Q-Learning using Tensorflow
- Deep Learning with PyTorch | An Introduction
- Differential Privacy and Deep Learning
- Prediction of Wine type using Deep Learning
- Residual Networks (ResNet) - Deep Learning
- ML | Natural Language Processing using Deep Learning
- DLSS - Deep Learning Super Sampling
- Deep Learning | Introduction to Long Short Term Memory
- seq2seq model in Machine Learning
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.