0
votes

I have this time-series data frame that has 56 columns and 36508 samples; 55 are predictors and the last one is the output. I'm trying to fit a LSTM neural network and while I'll be able to fit the model, I'm having some hard time converting the features to Pytorch tensor objects. Currently I have already normalised the data between 0 and 1 and also split the data into train and test sets.

import torch
import torch.nn as nn

print(x_train.shape)
(27380, 55)

print(y_train.shape)
(27380,)

print(x_test.shape)
(9128, 55)

print(y_test.shape)
(9128,)

I've had no problems converting the target to a tensor object, since the series is only 1D like so:

y_train = torch.FloatTensor(y_train).view(-1)
print(y_train[:5])
tensor([0.7637, 0.6220, 0.6566, 0.6922, 0.6774])

But when it comes to converting the features, then I'm unable to figure out the dimensions that need to be specified. I've tried this:

x_train = torch.FloatTensor(x_train).view(-1, 55)

ValueError: could not determine the shape of object type 'DataFrame'

How do I properly convert the features dataset to a tensor object? Sadly the documentation seems vague.

1

1 Answers

0
votes

Try converting to numpy and then to tensors:

x_train = torch.from_numpy(np.array(x_train).astype(np.float32))