[英]Error when checking target: expected activation_1 to have shape (1,) but got array with shape (10,)
I'm having issues with this model, which is trying to forecast stock market 10 days in the future: 我对此模型有疑问,该模型正试图在未来10天预测股市:
model = Sequential()
model.add(LSTM(input_shape=(None, INPUT_DIM),
units=UNROLL_LENGTH, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(128, return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
model.add(Activation('linear'))
start = time.time()
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam')
model.fit(x_train_unroll, y_train_unroll, batch_size=BATCH_SIZE,epochs=EPOCHS, verbose=2, validation_split=0.05)
The error: 错误:
ValueError: Error when checking target: expected activation_1 to have shape (1,) but got array with shape (10,)
ValueError:检查目标时出错:预期activation_1的形状为(1,),但数组的形状为(10,)
Shapes of the numpy arrays: numpy数组的形状:
x_train (1968, 50, 3), y_train (1968, 10), x_test (450, 50, 3), y_test (450, 10)
x_train(1968,50,3),y_train(1968,10),x_test(450,50,3),y_test(450,10)
*X_TRAIN_UNROLL*
[[[0.12339965 0.1352139 0.11937183]
[0.12231633 0.16698145 0.12354637]
[0.12261178 0.13978988 0.11837789]
...
[0.04057514 0.16677908 0.03448961]
[0.03998424 0.16039329 0.03439022]
[0.03407524 0.18277416 0.03906172]]
*Y_TRAIN_UNROLL*
[[0.06529447 0.06007485 0.06165058 ... 0.06342328 0.0627339 0.05465826]
[0.06007485 0.06165058 0.06204451 ... 0.0627339 0.05465826 0.05515068]
[0.06165058 0.06204451 0.06135513 ... 0.05465826 0.05515068 0.04687808]
...
[0.68505023 0.67096711 0.66988379 ... 0.66525507 0.66289147 0.64171755]
[0.67096711 0.66988379 0.66968682 ... 0.66289147 0.64171755 0.65195982]
[0.66988379 0.66968682 0.67234587 ... 0.64171755 0.65195982 0.64250542]]
Your outputs are not sparsely encoded so you should use categorical_crossentropy
as a loss function instead of sparse_categorical_crossentropy
. 您的输出未经过稀疏编码,因此应使用
categorical_crossentropy
作为损失函数,而不是sparse_categorical_crossentropy
。 Also, the Linear
activation at the end of your model can be removed, it does nothing here. 此外,可以删除模型末尾的
Linear
激活,此处不执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.