Warm tip: This article is reproduced from serverfault.com, please click

Keras-绘图训练,验证和测试集准确性

(Keras - Plot training, validation and test set accuracy)

发布于 2017-01-28 09:46:13

我想绘制这个简单的神经网络的输出:

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(x_test, y_test, nb_epoch=10, validation_split=0.2, shuffle=True)

model.test_on_batch(x_test, y_test)
model.metrics_names

我已经绘制了准确性以及训练和验证的损失

print(history.history.keys())
#  "Accuracy"
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper left')
plt.show()
# "Loss"
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper left')
plt.show()

现在,我想从中添加并绘制测试集的精度model.test_on_batch(x_test, y_test),但是从中model.metrics_names我获得了用于在训练数据上绘制精度的相同值“ acc”plt.plot(history.history['acc'])如何绘制测试仪的精度?

Questioner
Simone
Viewed
12
Dr. Snoopy 2017-01-28 19:11:48

这是相同的,因为你正在测试集上训练,而不是在训练集上训练。不要那样做,只需在训练集上进行训练即可:

history = model.fit(x_test, y_test, nb_epoch=10, validation_split=0.2, shuffle=True)

变成:

history = model.fit(x_train, y_train, nb_epoch=10, validation_split=0.2, shuffle=True)