Keras RNN - 检查输入时的ValueError

时间:2018-01-14 21:21:37

标签: keras lstm

我最近购买了一张Nvidia卡,并希望尝试使用新的GPU支持LSTM-Models。可悲的是,我对LSTM并不了解。我构建了这个小模型来测试它:

import pandas as pd
from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Normalizer, StandardScaler
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.gpu_options.visible_device_list = "0"
set_session(tf.Session(config=config))

data = pd.read_excel("./data/google_data.xlsx", header=0)
X = data.drop("Close", axis=1)
y = data["Close"]

model = Sequential()
model.add(LSTM(units=10, activation='sigmoid', input_shape=(4,1),return_sequences=True))
model.add(Dropout(0.4))
model.add(Dense(10, activation="sigmoid"))
model.add(Dense(1, activation="sigmoid"))
model.compile(optimizer='adam', loss='mean_squared_error')

print(model.summary())

normalizer = StandardScaler()
normalizer.fit(X)
X = normalizer.fit_transform(X)

X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.20, shuffle=False)

model.fit(X, y, batch_size=64, epochs=40, verbose=1, validation_data=(X_test, y_test))

我总是得到一个ValueError,我尝试过Keras Docs中的Inputshape(batch_size,timesteps,features),但我仍然得到相同的 ValueError

Error Traceback

我想这可能是一个非常愚蠢的问题,但像我这样的新手可能需要一些帮助。谢谢!

0 个答案:

没有答案