How to classify movement data (time series) in real time

I have some movement data sampled over a time series. I am trying to classify the movements in real time as either smooth or shaky. For example, as the movement is smooth it is classified as smooth until it suddenly becomes shaky and is then classified as so.

I am having some serious trouble doing this. Aside from using an RNN and feeding it subsets of the time series data to classify (which I do not have enough data to train), does anybody know of any time series classification algorithms? I plan on feeding subsets of the time series into the algorithm with a single label for training and prediction.

Any help is greatly appreciated.

• IMPORTANT: The data is labelled so supervised learning is on the table. Feb 12 '18 at 1:28
• How large is the dataset? How many samples are their for each time window? How many instances of smooth do you have over shaky? Feb 12 '18 at 3:11
• Data is still being collected so I do not have final numbers yet. there will be around 300 samples for each time window, data is expected to be 90% smooth 10% shaky. Only expecting around 10-50 data points. Feb 12 '18 at 4:15
• If it’s IMPORTANT then put it in the question Apr 13 '18 at 22:48

Supervised learning for classification in machine learning trains a model in order to determine which distribution a certain novel instance belongs to. Model complexity is directly correlated with the performance of a specific algorithm given a set number of instances.

Your dataset is comprised of instances $x_i \in \mathbb{R}^{300}, i \in {1, ..., n}$ and $10 < n < 50$.

This is a very small number of instances $n$. Usually I recommend to have ten times more instances than features for a two class classification problem. Furthermore, less than $50,000$ instances is not sufficient for training any deep learning model. You will need to consider using traditional machine learning algorithms (SVM, KNN, Random Forests, etc.). Lastly, the class imbalance in your dataset will introduce some bias, this will lead to poorer results.

All hope is not lost, we can still do something to solve this problem!

Feature selection

The first step which I would suggest is to consider performing some feature reduction. You want to map your $X \in \mathbb{R}^{300}$ to a lower dimensional set $\mathbb{R}^{p}$ where $p<300$. However, in removing features you will evidently be losing information, so you want to be able to learn what are the relevant features to your decision smooth/shaky. For example, when classifying cat/dog, the weight may be a highly informative feature thus its contribution in the decision should be highly considered, whereas the number of feet would not provide any useful information.

Some techniques to do this include PCA, LDA, and theres others as well. You can try them, its one line in scikit-learn.

Choosing an algorithm

Due to the heavy class imbalance, I would suggest that classification based algorithms will perform poorly. In contrast, I would attempt to use anomaly detection algorithms. These techniques will learn the distribution of your nominal set (smooth) and attempt to detect when signals differ significantly from this distribution and will then classify them as anomalous (shaky).

Using time series data from a sensor for ML

How to train model to predict events 30 minutes prior, from multi-dimensionnal timeseries

• Wow thank you so much, this is a great answer. I think I was getting overly complex by only looking for algorithms that exhibit dynamic temporal behavior. I think that simply feeding in series data with labels may suffice. I also pray that I end up with a massive dataset (This will happen if initial tests go well). I do have one last question. Each sample is represented as a tuple(X, Y, Z, Yaw, Roll, Pitch). How do you recommend that I represent these tuples? the input to a classifier in my case would be [[[X, Y, Z, Yaw, Pitch, Roll],....[X, Y, Z, Yaw, Pitch, Roll]]......]. Feb 12 '18 at 19:07
• Do you recommend flattening each tuple? This would increase dimensionality by a factor of 6. Feb 12 '18 at 19:12
• Perhaps I can vastly reduce the size of the sliding window to reduce dimensionality and increase training samples. Feb 12 '18 at 19:25
• I think including the X, Y, Z, Yaw, Pitch and Roll would probably be quite informative for the decision boundary. And yes, decreasing the number of retained samples can help as well. You can test different amount of samples and see what is best. Feb 13 '18 at 1:56

I have to wonder why you are classifying entire instances as either smooth or shaky? Would it be possible to model each instance as a hidden Markov model (HMM) with two states, smooth vs shaky? Your task would be to model the transition probabilities and estimate the current state of the instances. Do instances ever transition from shaky back to smooth?

Estimating the model parameters can be heavy work, but you have a small dataset. I recently ran an analysis similar to this using the msm package in R. I had around 3000 instances of varying lengths (typically < 20 each). The code ran quickly (under a minute but noticeable wait).

If the effect is strong -- i.e. the measurements really change when you go from "smooth" to "shaky", you should still be able to estimate the parameters even with the "class imbalance" that you have. If not, you could take a subset of the data that achieves better balance (or better, randomly select subsets of the smooth data and bootstrap the parameter estimates). The transition probabilities are conditional on the state you are in, so you can change the overall proportion of being in one state or another without harm to your analysis. Of course, global estimates of how long the system remains in one state would need to be adjusted in light of population prevalence.

If the transition to the shaky state is anticipated by changes in the observed movement data, then you need to consider one of those Poisson intensity models where the intensity function depends on the observations. Check out R package PtProcess and the references therein. It offers a variety of models, which could meet your needs.