Keras-情节训练,验证和测试集准确性 [英] Keras - Plot training, validation and test set accuracy
问题描述
我想绘制这个简单的神经网络的输出:
I want to plot the output of this simple neural network:
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
我绘制了训练和验证的准确性和损失:
I have plotted accuracy and loss of training and validation:
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
我获得了用于在训练数据plt.plot(history.history['acc'])
上绘制精度的相同值'acc'.如何绘制测试仪的精度?
Now I want to add and plot test set's accuracy from model.test_on_batch(x_test, y_test)
, but from model.metrics_names
I obtain the same value 'acc' utilized for plotting accuracy on training data plt.plot(history.history['acc'])
. How could I plot test set's accuracy?
推荐答案
这是相同的,因为您是在测试集中进行训练,而不是在训练集中进行训练.不要这样做,只需在训练集上进行训练即可:
It is the same because you are training on the test set, not on the train set. Don't do that, just train on the training set:
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)
这篇关于Keras-情节训练,验证和测试集准确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!