Keras验证准确性为0,在整个培训过程中保持不变 [英] Keras validation accuracy is 0, and stays constant throughout the training

查看:40
本文介绍了Keras验证准确性为0,在整个培训过程中保持不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tensorflow/Keras在Python中进行时间序列分析.整个LSTM模型看起来像

I am doing a time series analysis using Tensorflow/ Keras in Python. The overall LSTM model looks like,

model = keras.models.Sequential()
model.add(keras.layers.LSTM(25, input_shape = (1,1), activation =    'relu', dropout = 0.2, return_sequences = False))
model.add(keras.layers.Dense(1))
model.compile(optimizer = 'adam', loss = 'mean_squared_error', metrics=['acc'])
tensorboard = keras.callbacks.TensorBoard(log_dir="logs/{}".format(time()))
es = keras.callbacks.EarlyStopping(monitor='val_acc', mode='max', verbose=1, patience=50)
mc = keras.callbacks.ModelCheckpoint('/home/sukriti/best_model.h5',   monitor='val_loss', mode='min', save_best_only=True)
history = model.fit(trainX_3d, trainY_1d, epochs=50, batch_size=10, verbose=2, validation_data = (testX_3d, testY_1d), callbacks=[mc, es, tensorboard])

我有以下结果

Train on 14015 samples, validate on 3503 samples
Epoch 1/50
- 3s - loss: 0.0222 - acc: 7.1352e-05 - val_loss: 0.0064 - val_acc:  0.0000e+00
Epoch 2/50
- 2s - loss: 0.0120 - acc: 7.1352e-05 - val_loss: 0.0054 - val_acc: 0.0000e+00
Epoch 3/50
- 2s - loss: 0.0108 - acc: 7.1352e-05 - val_loss: 0.0047 - val_acc: 0.0000e+00

现在, val_acc 保持不变.正常吗它代表什么?

Now the val_acc remains unchanged. Is it normal? what does it signify?

推荐答案

loss ='mean_squared_error'所示,您处于回归设置,其中(仅在分类问题中有意义).

As signified by loss = 'mean_squared_error', you are in a regression setting, where accuracy is meaningless (it is meaningful only in classification problems).

不幸的是,尽管事实证明Keras对您的问题毫无意义且不合适,但Keras不会在这种情况下保护"您,而是坚持计算并向您报告准确性"-请参阅

Unfortunately, Keras will not "protect" you in such a case, insisting in computing and reporting back an "accuracy", despite the fact that it is meaningless and inappropriate for your problem - see my answer in What function defines accuracy in Keras when the loss is mean squared error (MSE)?

您应该只从模型编译中删除 metrics = ['acc'] ,并且不要打扰-在回归设置中,MSE本身也可以(通常也)用作性能指标

You should simply remove metrics=['acc'] from your model compilation, and don't bother - in regression settings, MSE itself can (and usually does) serve also as the performance metric.

这篇关于Keras验证准确性为0,在整个培训过程中保持不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆