Source: Deep Learning on Medium

Welcome back, this is the final part of signal processing with machine learning hands-on. We are going to leverage the power of deep learning on our same dataset of accelerometer and gyroscope signals for human activity classification.

What is deep learning?

Deep learning is an advanced machine learning technique based on neural networks inspired by the human brain. Deep learning is performed using neural networks which are mathematically matrices or tensors that resemble self learnt features of fed data. Deep learning outperforms classical machine learning techniques in terms of model building time, accuracy and most important expense. Deep learning works with passing batches of high dimensional data often called tensors through a network repeatedly. Each neuron of the network is associated with some linear or non linear weight and optional bias. After passing every batch of data, the weight of each neuron is adjusted by an optimizer using backpropagation, which is passing the loss backward through the neurons, so that the neurons can adjust their weight to reduce the final loss using gradient descent technique. The most useful factor of deep learning is the low-cost development of a model. Wonder why?? The most important part of machine learning is the feature engineering and feature selection. Organizations spend a lot in domain experts and data analysts who filter and generate the most important features for the model development. The best part of neural networks is we can mostly skip the feature engineering part and feed preprocessed data directly into the neural networks. The deep and dense neural network figures out important and unimportant features itself and adjusts their weight. Deep learning needs no domain expertise and can be developed by a team of developers only.

We will see how deep learning shows similar performance in prediction with our human activity classification task with raw sensor data fed into deep neural networks like LSTM(Long Short Term Memory) and CNN(Convolutional Neural Networks)

We will work with Keras which is a deep learning wrapper on top of TensorFlow for designing and testing our neural network.

To start with we will import the raw time-sliced signals data from 9 sensors. The time slice is a sequence of 128 float values corresponding to sensor value each millisecond. The window is slid by 1 step and the next data point is a sequence of 128 values with 127 old ones and 1 new one. The labels are categorical activities.

Following is how we will import the data and split into train and test sets. This section also has some helper functions that we will be using most often.