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()
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)
Change into:
history = model.fit(x_train, y_train, nb_epoch=10, validation_split=0.2, shuffle=True)
I'm sorry, I always have utilized training set to train the NN, it's been an oversight. I am new in machine learning, and I am little bit confused about the result of
model.fit( ... )
, I get loss, acc, val__loss and val__acc, I suppose that values represent loss and accuracy on training and validation, but where can I find the value of loss about the test?@Simone You can use model.evaluate on the test set to get the loss and metrics over the test set. Just make you sure use the right variables.
I have used model.evaluete, and I get accuracy and loss, but I can't plot them because I can't distinguish accuracy obtained on training, from accuracy obtained on test.
@Simone What do you mean can't distinguish?
I should have an accuracy on training, an accuracy on validation, and an accuracy on test; but I get only two values: val__acc and acc, respectively for validation and training. From
model.evaluate(x_test, y_test)
model.metrics_names
I get acc, the same of training. What am I doing wrong?