/Human-Activity-Recognition

This project aims to classify human activities using data obtained from accelerometer and gyroscope sensors from phone and watch.

Primary LanguageJupyter Notebook

HAR Logo

Human Activity Recognition

A Comparative Study between Different Pre-processing Approaches and Classifiers


Sample signal

πŸ“– Table of Contents

Table of Contents
  1. ➀ About The Project
  2. ➀ Prerequisites
  3. ➀ Folder Structure
  4. ➀ Dataset
  5. ➀ Roadmap
  6. ➀ Preprocessing
  7. ➀ Results and Discussion
  8. ➀ References
  9. ➀ Contributors

-----------------------------------------------------

πŸ“ About The Project

This project aims to classify human activities using data obtained from accelerometer and gyroscope sensors from phone and watch. The raw data will be preprocessed using two different approaches such as topological data analysis and statistical features extraction from segmented time series. The goal is to compare and evaluate the performance of different classifiers (Decision Tree, k Nearest Neighbors, Random Forest, SVM and CNN) which are trained on the two sets of preprocessed data.

Table1: 18 Activities

-----------------------------------------------------

🍴 Prerequisites

made-with-python
Made withJupyter

The following open source packages are used in this project:

  • Numpy
  • Pandas
  • Matplotlib
  • Scikit-Learn
  • Scikit-tda
  • Giotto-tda
  • TensorFlow
  • Keras

-----------------------------------------------------

🌡 Folder Structure

code
.
β”‚
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ raw_data
β”‚   β”‚   β”œβ”€β”€ phone
β”‚   β”‚   β”‚   β”œβ”€β”€ accel
β”‚   β”‚   β”‚   └── gyro
β”‚   β”‚   β”œβ”€β”€ watch
β”‚   β”‚       β”œβ”€β”€ accel
β”‚   β”‚       └── gyro
β”‚   β”‚
β”‚   β”œβ”€β”€ transformed_data
β”‚   β”‚   β”œβ”€β”€ phone
β”‚   β”‚   β”‚   β”œβ”€β”€ accel
β”‚   β”‚   β”‚   └── gyro
β”‚   β”‚   β”œβ”€β”€ watch
β”‚   β”‚       β”œβ”€β”€ accel
β”‚   β”‚       └── gyro
β”‚   β”‚
β”‚   β”œβ”€β”€ feature_label_tables
β”‚   β”‚    β”œβ”€β”€ feature_phone_accel
β”‚   β”‚    β”œβ”€β”€ feature_phone_gyro
β”‚   β”‚    β”œβ”€β”€ feature_watch_accel
β”‚   β”‚    β”œβ”€β”€ feature_watch_gyro
β”‚   β”‚
β”‚   β”œβ”€β”€ wisdm-dataset
β”‚        β”œβ”€β”€ raw
β”‚        β”‚   β”œβ”€β”€ phone
β”‚        β”‚   β”œβ”€β”€ accel
β”‚        β”‚   └── gyro
β”‚        β”œβ”€β”€ watch
β”‚            β”œβ”€β”€ accel
β”‚            └── gyro
β”‚
β”œβ”€β”€ CNN_Impersonal_TransformedData.ipynb
β”œβ”€β”€ CNN_Personal_TransformedData.ipynb  
β”œβ”€β”€ CNN_Impersonal_RawData.ipynb    
β”œβ”€β”€ CNN_Personal_RawData.ipynb 
β”œβ”€β”€ Classifier_SVM_Personal.ipynb
β”œβ”€β”€ Classifier_SVM_Impersonal.ipynb
β”œβ”€β”€ statistical_analysis_time_domain.py
β”œβ”€β”€ Topological data analysis.ipynb  

-----------------------------------------------------

πŸ’Ύ Dataset

The WISDM (Wireless Sensor Data Mining) dataset includes raw time-series data collected from accelerometer and gyroscope sensors of a smartphone and smartwatch with their corresponding labels for each activity. The sensor data was collected at a rate of 20 Hz (i.e., every 50ms). Weiss et.al., collected this dataset from 51 subjects who performed 18 different activities listed in Table 2, each for 3 minutes, while having the smartphone in their right pant pocket and wearing the smartwatch in their dominant hand. Each line of the time-series sensor file is considered as input.

Human Activity.gif

The WISDM dataset is publicly available. Please refer to the Link

The following table shows the 18 activities represented in data set.

Table1: 18 Activities

-----------------------------------------------------

🎯 Roadmap

Weiss et. al. has trained three models namely Decision Tree, k-Nearest Neighbors, and Random Forest for human activity classification by preprocessing the raw time series data using statistical feature extraction from segmented time series. The goals of this project include the following:

  1. Train the same models - Decision Tree, k Nearest Neighbors, and Random Forest using the preprocessed data obtained from topological data analysis and compare the performance against the results obtained by Weiss et. al.

  2. Train SVM and CNN using the preprocessed data generated by Weiss et. al. and evaluate the performance against their Decision Tree, k Nearest Neighbors, and Random Forest models.

-----------------------------------------------------

πŸ”¨ Preprocessing

The WISDM (Wireless Sensor Data Mining) dataset includes raw time-series data collected from accelerometer and gyroscope sensors of a smartphone and smartwatch with their corresponding labels for each activity. The sensor data was collected at a rate of 20 Hz (i.e., every 50ms). Weiss et.al., collected this dataset from 51 subjects who performed 18 different activities listed in the previous table, each for 3 minutes, while having the smartphone in their right pant pocket and wearing the smartwatch in their dominant hand.
In this project we tried three different feature sets, extracted from the raw data, which are as follows:

  1. Pre-processed data generated by Weiss et. al.
  2. Statistical feature extraction
  3. Topological feature extraction

All these three approaches used windowing technique to segment the raw time series and extract features from each segment.

-----------------------------------------------------

πŸ’  Pre-processed data

Weiss et.al used windowing technique with window size of 10 seconds to extract statistical features. They extracted 93 features out of which 43 were used to train their models. We also used the same 43 features to train our SVM and CNN. The 43 features are 1. average sensor value 2. standard deviation 3. absolute difference 4. average resultant acceleration 5. Binned distribution (10 equal sized bins per axis) and 5. time between peaks, for each axis.

-----------------------------------------------------

πŸ”Ά Statistical feature

For this approach, we segmented the dataset using 10 second window size (200 datapoints) with no overlapping. We decided to keep the window size same as whatWeiss et.al. applied in their study, for the sake of comparison. After segmentation, for each segment we calculated eight statistical features, namely, β€˜min’, β€˜max’, β€˜mean’, β€˜standard deviation’, β€˜median’, β€˜variance’, β€˜zero crossing’ and β€˜mean crossing’, for each axes. The zero and mean crossing features are calculated by counting the rate of when a signal passes line y=0 (if we let y-axis to be the specific measurement and x-axis to represent time) and the frequency at which the signal passes the line y = mean(signal), respectively. However, these two features did not show a significant difference between different activities, so we decided to ignore them.

-----------------------------------------------------

πŸ”· Topological feature

Topological data analysis provides various techniques toexplore the topological properties and shape of the data. Since time series sensor data obtained from performing an activity may have topological properties, we tried extracting features using the topology of the data and perform the classification task on those features. For a given time segment we explore the topology of each segment using persistence diagram generated via persistence homology. Persistent homology can be created through filtrations such as Vietoris- Rips, SparseRips, Cubical Persistence etc., on the data and capture the growth, birth, and death of different topological features across dimensions (e.g., components, tunnels, voids) [2]. One of the main challenges in computing the persistent homology is finding the appropriate filtration for the time segments. In total 18 topological features where extracted for each time segment.

-----------------------------------------------------

πŸ” Results and Discussion

The overall accuracy score of personal and impersonal models are shown in the following tables. Some of the results we observed are similar to the results obtained by Weiss et.al and they are discussed below:

  • Since accelerometers senses acceleration based on vibration which can be more prominent during an activity and gyroscope only senses rotational changes, accelerometers outperformed gyroscope in all our models.
  • As the style of performing an activity differs from each person, it is difficult to aggregate those features among all subjects. So our personal models vastly outperformed our impersonal models.
  • It is also observed that non hand-oriented activities are classified better with sensors from smartphone and handoriented activities are classified better with sensors from smartwatch. Refer appendix for activity wise recall scores. Some key take-aways based on our results are listed below:
  • CNN trained on raw sensor data performed better for personal models, however it performed poorly on impersonal models.

Table 3 and 4

-----------------------------------------------------

πŸ“š References

  • Matthew B. Kennel, Reggie Brown, and Henry D. I. Abarbanel. Determining embedding dimension for phase-space reconstruction using a geometrical construction. Phys. Rev. A, 45:3403–3411, Mar 1992.

  • L. M. Seversky, S. Davis, and M. Berger. On time-series topological data analysis: New data and opportunities. In 2016 IEEE Conference on Computer Vision and Pattern Recognition Workshops (CVPRW), pages 1014–1022, 2016.

  • Floris Takens. Detecting strange attractors in turbulence. In David Rand and Lai-Sang Young, editors, Dynamical Systems and Turbulence, Warwick 1980, pages 366–381, Berlin, Heidelberg, 1981. Springer Berlin Heidelberg.

  • Guillaume Tauzin, Umberto Lupo, Lewis Tunstall, Julian Burella PΒ΄erez, Matteo Caorsi, Anibal Medina-Mardones, Alberto Dassatti, and Kathryn Hess. giotto-tda: A topological data analysis toolkit for machine learning and data exploration, 2020.

  • G. M. Weiss and A. E. O’Neill. Smartphone and smartwatchbased activity recognition. Jul 2019.

  • G. M. Weiss, K. Yoneda, and T. Hayajneh. Smartphone and smartwatch-based biometrics using activities of daily living. IEEE Access, 7:133190–133202, 2019.

  • Jian-Bo Yang, Nguyen Nhut, Phyo San, Xiaoli li, and Priyadarsini Shonali. Deep convolutional neural networks on multichannel time series for human activity recognition. IJCAI, 07 2015.

-----------------------------------------------------

πŸ“œ Contributors

πŸŽ“ All participants in this project are graduate students in the Department of Computer Science and Software Engineering @ Concordia University

πŸ‘© Divya Bhagavathiappan Shiva
      Email: divya.bhagavathiappanshiva@mail.concordia.ca
      GitHub: @divyabhagavathiappan

πŸ‘© Reethu Navale
      Email: reethu.navale@mail.concordia.ca
      GitHub: @reethunavale

πŸ‘© Mahsa Sadat Afzali Arani
      Email: m_afzali93@yahoo.com
      GitHub: @MahsaAfzali

πŸ‘¦ Mohammad Amin Shamshiri
      Email: mohammadamin.shamshiri@mail.concordia.ca
      GitHub: @ma-shamshiri


✀ This was the final project for the course COMP 6321 - Machine Learning (Fall 2020), at Concordia University