如何将2D pandas阵列安装到Keras LSTM层?

时间:2018-04-19 04:57:49

标签: python machine-learning keras time-series lstm

我有一个2D数组(pandas),它是3180行的时间序列,每行有8列(数组)作为特征。我正在尝试训练LSTM层

sc = StandardScaler()
X_train = sc.fit_transform(X_train)
print (X_train.shape)
classifier = Sequential()
classifier.add(LSTM(units=128, input_shape=(1, len(X_train), x.shape[1])))

this中所述。但错误就像,

ValueError: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4

1 个答案:

答案 0 :(得分:0)

LSTM期望3D数组作为输入,因此input_shape形状的长度应为2 ...

假设X_train.shape(3180, 8, 1),这应该有效:

LSTM(units=128, input_shape=X_train.shape[1:]))