简体   繁体   中英

LSTM accuracy too low

I'm a new learner, I just try to get accuracy and validate accuracy using the below code

model = Sequential()
model.add(LSTM(10, input_shape=(train_X.shape[1], train_X.shape[2])))
#model.add(Dropout(0.2))
#model.add(LSTM(30, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dense(1), return_sequences=True)
model.compile(loss=’mae’, optimizer=’adam’, metrics=[‘accuracy’])
# fit network
history = model.fit(train_X, train_y, epochs=50, batch_size=120, validation_data=(test_X, test_y), verbose=2, shuffle=False)
# plot history
pyplot.plot(history.history[‘loss’], label=’train’)
pyplot.plot(history.history[‘val_loss’], label=’test’)
pyplot.legend()
pyplot.show()
print(history.history[‘acc’])

As the loss value is very low (which is round 0.0136) inspite of that I'm getting the accuracy is 6.9% and validate accuracy is 2.3% respectively, which is very low

That is because accuracy is meaningful only for classification problems; for regression (ie numeric prediction) ones, such as yours, accuracy is meaningless .

What's more, the fact is that Keras unfortunately will not "protect" you or any other user from putting such meaningless requests in your code, ie you will not get any error, or even a warning, that you are attempting something that does not make sense, such as requesting the accuracy in a regression setting; see my answer in What function defines accuracy in Keras when the loss is mean squared error (MSE)? for more details and a practical demonstration (the argument is identical in the case of MAE instead of MSE, since both loss functions signify regression problems).

In regression settings, usually the performance metric is the same with the loss (here MAE), so you should just remove the metrics=['accuracy'] argument from your model compilation and worry only for your loss (which, as you say, is low indeed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM