Time Series variable length

I am trying to run an SVM on time series data. My dataset is represented by multiple pandas dataframes and one sample is represented by one dataframe row where each column represents one time step. Unfortunately, the samples have different length. Does anyone know how to deal with that issue?

Could you describe your model a bit more, i.e. what kind of architecture you are using?
A common approach would be to pad your sequences to the same lengths.

This is the architecture I am using:

class SVM_Net(nn.Module):
    def __init__(self,n_feature,n_class):
        super(SVM_Net, self).__init__()
        self.fc=nn.Linear(n_feature,n_class)
        nn.init.kaiming_uniform(self.fc.weight)
        nn.init.constant(self.fc.bias,0.1)
        
    def forward(self,x):
        output = self.fc(x)
        return output

In the meantime I already found out that I can use padding in order to solve my problem.
I am using a custom collate_fn method, however is there a way to pad them to a fixed, predefined length?

def pad_collate(batch):
    xx = []
    for elt in batch:
        xx.append(elt['data'])
    
    xx_pad = torch.nn.utils.rnn.pad_sequence(xx, batch_first=True, padding_value=0)
    return xx_pad

If you want to pad the sequences to a pre-defined length, you could add the padding in the __getitem__ and return equal sequence lengths.

I am not exactly sure how to achieve this. I tried adding the following line to the getitem method:

max_len=50
data = nn.ConstantPad1d((0, max_len - data.shape[0]), 0)(data)

where data represents one sequence (sample) of my data. However, one time step has multiple values, meaning that data looks something like this:

data = [[0,1,30,40,56], [5,4,8,13,15], [90,81,76,3,22], ...]

and I would like to pad it to a maximum sequence length, meaning to add as much timesteps as needed in order to receive the maximum length. What the code I added does, is padding each time step (so each array inside the sequence) to the desired length.

Given your input data the constant padding would be added in dim1. I’m not sure if this is what you want or if you are hitting an issue with this approach.