【发布时间】:2020-01-05 09:37:53
【问题描述】:
我有这个时间序列数据框,它有 56 列和 36508 个样本; 55 个是预测变量,最后一个是输出。我正在尝试拟合 LSTM 神经网络,虽然我能够拟合模型,但我很难将特征转换为 Pytorch 张量对象。目前我已经对 0 和 1 之间的数据进行了归一化,并将数据拆分为训练集和测试集。
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,)
我将目标转换为张量对象没有问题,因为该系列只有 1D,如下所示:
y_train = torch.FloatTensor(y_train).view(-1)
print(y_train[:5])
tensor([0.7637, 0.6220, 0.6566, 0.6922, 0.6774])
但是在转换特征时,我无法确定需要指定的尺寸。我试过这个:
x_train = torch.FloatTensor(x_train).view(-1, 55)
ValueError: could not determine the shape of object type 'DataFrame'
如何正确地将特征数据集转换为张量对象?遗憾的是,文档似乎含糊不清。
【问题讨论】:
标签: python tensorflow pytorch