So I have the multiple time series data in this format --

id  Week    X1    X2   X3   y

1   201901  10.   34.9 52.8 0

1   201902  20.   44.1 12.6 1

1   201903  30.   54.2 84.3 1

1   201904  40.   64.4 77.1 0

2   201901  10.   64.9 62.8 1

2   201902  20.   54.1 22.6 1

2   201903  30.   34.2 54.3 1

2   201904  40.   44.4 17.1 0

I want to predict y for the next two weeks. How can I approach this problem?

One way I thought is to train on the data set and then the test data would look like this -

id  Week   X1   X2    X3  
1   201905 20.  45.2. 33.2
2   201905 10.  65.2. 23.2

Is this the correct way to do such a classification? Or should I train the model for each time series independently.


  • $\begingroup$ What do your ids represent? Are these fixed? As in, you know will have 2? Or could they be more that you do not have in your training data? $\endgroup$ May 14 '20 at 8:58
  • 1
    $\begingroup$ The ids represents each individual time series. They can 10 or they can be a million. $\endgroup$
    – Slayer
    May 14 '20 at 9:03

To be clear, here, time-series classification refers to forecasting discrete values. In another context, time-series classification could refer to predicting a single class for the entire time-series (i.e. heart disease vs healthy heart). Thanks @mloning for pointing this out.

When it comes to forecasting discrete outputs, models are trained to predict the next value based on the previous ones, which means that

  • The input is the historical data up to timestamp t (in your scenario, the data up to week = 201904)
  • The output is the value at timestamp t + 1 (y when week = 201905)

If you want to predict more than 1 value into the future, you should perform predictions in a recurrent way, i.e.:

  • use data up to t to predict t + 1
  • add your prediction to your data
  • use data up to t + 1 (where t + 1 is your own prediction) to predict t + 2
  • and so on

How far into the future you want to look is called the horizon. And you are free to use as big of a horizon as you like. Of course, since every new step into the future is based on guesses and not actual data, it is expected that the further you look, the worse your predictions will become. Which makes perfect sense. That's why it's easier to predict what the weather will be like tomorrow than in 7 days.

Splitting data into training and testing is not very different than for a normal classification problem. The only constraint is that your test data should only contain data "in the future" compared to the training data. Here is a good blog about it: https://towardsdatascience.com/time-based-cross-validation-d259b13d42b8

  • should I train the model for each time series independently?

Short answer: try both approaches and see which one works best

Long answer:

All of this depends on whether you believe that each time-series represent a different "process" or "pattern". It could be that a single model could make good predictions for either time-series. It could also be that both time-series represent different processes and therefore, it might be wiser to train different models for each.

Think about it like a weather forecast. I could have time-series data for a bunch of cities. I could train a model specific to each city, but it might also help to train a model using data from all cities so that it can capture generic weather patterns. This can help if all of a sudden, I need to predict the weather for a new city I didn't know about. Since I didn't know about it, I don't have a model specifically for it, so I would need to reuse one, which ideally should be general enough.

  • 1
    $\begingroup$ As far as I know, time series classification is usually understood as the problem of labelling an entire time series (see e.g. timeseriesclassification.com), whereas here the problem is about labelling each time point of a time series, which is usually called time series annotation. But of course you can use time series classification to solve time series annotation as you describe. $\endgroup$
    – mloning
    Jun 10 '20 at 10:01
  • 1
    $\begingroup$ Indeed. The vocabulary can be ambiguous. I will edit my answer to make this even clearer. I also find that something similar happens with "object detection". Some people use it to mean classifying an entire image, and others use it to mean, finding the bounding box and classify it within an image. $\endgroup$ Jun 10 '20 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.