# Finding an appropriate binary classification algorithm for time series data intervals

Maybe someone here has experience in this matter and can point me in the right direction. I want to classify parts of an interval of numerical movement data as either resting or not resting. I have training data of what resting intervals look like. And am looking for the right algorithm to tackle this problem. I don't need the code, just a friendly push in the right direction.

Here is a rundown of the expected process.

1. I have an array of values that represent measurement over 5 minutes.
testData = [0, 4, 3, 5, 2, 4, 3, 4, 6, 11, 9, 10, 3, 15, 21, 5]


1. I have training data
trainingDataResting = [[1, 2, 1, 6, 4, 2], [3, 2, 2, 0, 4, 1, 5, 2], [3, 6, 2, 1, 0, 4, 5, 2]]
trainingDataActive = [[10, 4, 5, 9, 19, 13], [12, 8, 20, 9, 14], [13, 22, 19, 21, 11, 7, 9]]


A resting interval has to be at least 6 measurements long, and the longest possible resting interval is of interest. Is there a way to classify portion of the testData as resting, based on the trainingData? Something like:

testData = [0, 4, 3, 5, 2, 4, 3, 4, 6, 11, 9, 10, 3, 15, 21, 5]
'-------------------------' '----------------------'
Resting                 Not Resting

testResting = [0, 4, 3, 5, 2, 4, 3, 4, 6]
testActive = [11, 9, 10, 3, 15, 21, 5]


I get that there will be many solutions of possible resting intervals, but I am particularly interested in the longest and most resting one. Of course I am working with a lot more training data than I provided here.

I was working on a decision tree -> Decision Tree, before I was informed that there is prelabeled data that I could use for training.

I was thinking about long short term memory networks, do you know whether this applies here?

Thank you for the help.

Best,

Jo

• Curious -- why does a resting interval have to be at least 6 measurements long? If not for that requirement I would think about a hidden markov model with 2 states. Commented Mar 18, 2021 at 19:08
• Thanks for the suggestion :) This is a bit tricky to explain. Short version: We are measuring Heart Rate Variability (HRV) for resting intervals. HRV is only informative if it is calculated for a hear rate interval with a decent length. Thus the resting interval needs to have at least a certain length. Commented Mar 20, 2021 at 2:34

You could do logistic regression combined with an additional moving average/ clustering step.

Combine your data into training rest and active data into a single array X, and have an additional array y which would represent the labels e.g. 0 - active / 1 - resting for each row in your training dataset.

from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(random_state=0).fit(X, y)


Then predict for each step whether it is resting or active.

The predictions of the test set would look something like:

[0,1,1,1,0,1,1,0,0,0,0,1,0,0,0]


The additional step would be to find the groups. You could do this with a moving window like "if 5 active states in a window of 7, label it as active". You could also solve that final step with clustering, e.g. "if 0 is surrounded by 1s it is 0", or find local clusters of binary values.

• Thank you, I will try this approach as well. I will see what gives me the most reliable result . The clustering of binary values is a good idea. Commented Mar 20, 2021 at 2:41
• You're welcome. Consider upvoting/ accepting the answer if you're found it helpful
– WBM
Commented Mar 20, 2021 at 13:13
• I did :) My reputation seems not to be high enough for my upvote to be publicly visible :D Commented Mar 26, 2021 at 0:17