奇怪的验证损失和准确性
Posted
技术标签:
【中文标题】奇怪的验证损失和准确性【英文标题】:Strange validation loss and accuracy 【发布时间】:2018-04-03 08:24:25 【问题描述】:我正在尝试使用 MLP 进行分类。这是模型的样子。
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.utils import np_utils
model = Sequential()
model.add(Dense(256, activation='relu', input_dim=400))
model.add(Dropout(0.5))
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(number_of_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
X_train = input_data
y_train = np_utils.to_categorical(encoded_labels, number_of_classes)
history = model.fit(X_train, y_train, validation_split=0.2, nb_epoch=10, verbose=1)
但是当我训练我的模型时,我发现训练准确度提高了,但验证准确度没有变化并且具有很高的价值。
Using TensorFlow backend.
Train on 41827 samples, validate on 10457 samples
Epoch 1/10
41827/41827 [==============================] - 7s - loss: 2.5783 - acc: 0.3853 - val_loss: 14.2315 - val_acc: 0.0031
Epoch 2/10
41827/41827 [==============================] - 6s - loss: 1.0356 - acc: 0.7011 - val_loss: 14.8957 - val_acc: 0.0153
Epoch 3/10
41827/41827 [==============================] - 6s - loss: 0.7935 - acc: 0.7691 - val_loss: 15.2258 - val_acc: 0.0154
Epoch 4/10
41827/41827 [==============================] - 6s - loss: 0.6734 - acc: 0.8013 - val_loss: 15.4279 - val_acc: 0.0153
Epoch 5/10
41827/41827 [==============================] - 6s - loss: 0.6188 - acc: 0.8185 - val_loss: 15.4588 - val_acc: 0.0165
Epoch 6/10
41827/41827 [==============================] - 6s - loss: 0.5847 - acc: 0.8269 - val_loss: 15.5796 - val_acc: 0.0176
Epoch 7/10
41827/41827 [==============================] - 6s - loss: 0.5488 - acc: 0.8395 - val_loss: 15.6464 - val_acc: 0.0154
Epoch 8/10
41827/41827 [==============================] - 6s - loss: 0.5398 - acc: 0.8418 - val_loss: 15.6705 - val_acc: 0.0164
Epoch 9/10
41827/41827 [==============================] - 6s - loss: 0.5287 - acc: 0.8439 - val_loss: 15.7259 - val_acc: 0.0163
Epoch 10/10
41827/41827 [==============================] - 6s - loss: 0.4923 - acc: 0.8547 - val_loss: 15.7484 - val_acc: 0.0187
问题与训练数据有关还是我的训练过程设置有问题?
【问题讨论】:
【参考方案1】:您的模型似乎严重过度拟合。这可能与数据有关,但您可以先尝试降低学习率,以防万一。
from keras.optimizers import Adam
model.compile(loss='categorical_crossentropy',
optimizer=Adam(lr=0.0001),
metrics=['accuracy'])
【讨论】:
是的,数据有问题。我想我需要做预处理。以上是关于奇怪的验证损失和准确性的主要内容,如果未能解决你的问题,请参考以下文章