Let's assume for the samples $\{(x_i,y_i)\},$ the $dim\ x_i$ is variable, e.g. a time series $x_i = (x_{i1},\cdot,x_{iT_i}).$ Then how do we train a linear regression for such samples? Especially how do we deal with such case in sklearn?

Currently I naively fixed a length $l$ (usually the maximal length of $x_i$ in samples), then add $0$ for the length of sample being short than $l;$ or cut off for the length of sample being longer than $l$ (test sample).

Since I never used the deep learning library, do you have any example for the code of LSTM? I think such input samples must be very common in LSTM.

Another way I think is interpolate/extrapolate each time series (sample) to get a continuous curve. Then fix some common synthetic time points to obtain a synthetic time series for each sample. Then the training is based on those synthetic time series with same length.


If we train a time series prediction (no label) like ARMA, then it is easy to use a moving window to obtain the equal length data. However if it is a Supervised learning, The samples are something like:


Then even for RNN or LSTM, how to deal with it? It seems Keras also demands the equal length on $x.$

  • $\begingroup$ Maybe compute some features from the time series? For a better answer you need to give some context, what does the outcome $y_i$ measure? $\endgroup$ – kjetil b halvorsen Jun 6 at 20:38
  • $\begingroup$ @kjetilbhalvorsen for example, $y_i$ is a float number to measure the intensity of time series curve. $\endgroup$ – user6703592 Jun 7 at 2:32
  • $\begingroup$ Yes, I think in vanilla linear regression, you do need fixed-length inputs, so unless you calculate a set of summary features, yeah, you might be stuck. LSTM is an alternative but it seems super heavyweight -- you could do sequence regression with it though. Keras is pretty friendly with a small learning curve; here's a tutorial for sequence classification, which you can adapt to regression by changing the objective function. $\endgroup$ – tchainzzz Jun 7 at 6:49
  • $\begingroup$ @tchainzzz pls see my update, actually is there any reference specific to introduce this part of Machine learning? $\endgroup$ – user6703592 Jun 30 at 7:15

Your Answer

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

Browse other questions tagged or ask your own question.