# How can I use variable length inputs to train a regression model?

I'm working predicting a value $y \in \mathbb{R}$ from the value of $x_{n+1}$, where $n$ is the number of samples ($x_{i \in [1,n]}$) used for training.

Each training sample $x_{i}$ is a time series of variable lengths. How can I engineer features to predict $y$ while making the most of the samples available?

Nota bene:

• I'm working with Python & Scikit-learn
• the length of the time series may be considered as an explanatory variable

• Hello, I have asked the same question here while providing my current solution: datascience.stackexchange.com/questions/16929/… This forum seems not so active or perhaps my question was not properly asked
– Wli
Feb 17, 2017 at 11:57

If I got your question right, the $x_i$ has different length $l$ over $i\in[1,n]$ as your training data. A very common method is to padding each training sample and testing sample to the same length, or use a fixed length time window for sampling your time series data. As for here, you may pad all the $x_i$ to the length of $L$ with $L = max(l_i), i \in [1,2,...,n,n+1...]$. The values for padding depends on your data, use some values that are not supposed to occur in your data to represent the "padding".
To make the prediction on $x_{n+1}$, you also pad or use time window to sample the $x_{n+1}$ first, and then make the prediction using the model you trained.