Reputation: 73
I am training a CNN model using tf.Keras, I splatted the training set into training and validation set, I want to visualize the accuracy on the validation set.
Here is the code, so please tell me whether the printed accuracy is related to training or validation set?
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
model.fit( x= X_train.reshape(X_train.shape[0],280,252,1),
y= train_Y_one_hot,
epochs=20,
batch_size=64,
validation_data=(X_val.reshape(X_val.shape[0],280,252,1),val_Y_one_hot),
verbose=1)
output: Train on 103658 samples, validate on 25915 samples Epoch 1/20 28288/103658 [=======>......................] - ETA: 40:01 - loss: 0.5309 - accuracy: 0.9063
Upvotes: 7
Views: 5842
Reputation:
accuracy = model.history.history["accuracy"]
val_accuracy = model.history.history["val_accuracy"]
loss = model.history.history["loss"]
val_loss = model.history.history["val_loss"]
plt.plot(accuracy, label="accuracy")
plt.plot(val_accuracy, label="validation accuracy")
plt.ylabel("Accuracy")
plt.xlabel("Epoch")
plt.legend()
plt.show()
plt.plot(loss, label="loss")
plt.plot(val_loss, label="validation loss")
plt.ylabel("Loss")
plt.xlabel("Epoch")
plt.legend()
plt.show()
Upvotes: 0
Reputation: 28
The accuracy of the model solely depends on the training data, pre-processing done in the training data and the type of classifier and its's parameters.
Upvotes: 0
Reputation: 3288
If you want to visualize accuracy as a plot, you can get the list of validation accuracy and loss for each epoch as follows (I ran only 5 epochs, so i get 5 values for each val_accuracy
and val_loss
)
model.fit(x_train, y_train, epochs=5,validation_data=(x_test,y_test))
model.evaluate(x_test, y_test)
# access validation accuracy for each epoch
acc = model.history.history['val_accuracy']
print(acc) # [0.9573, 0.9696, 0.9754, 0.9762, 0.9784]
# access validation loss for each epoch
loss_val = model.history.history['val_loss']
print(loss_val) # [0.13892182569280268, 0.10223265058882534, 0.08262962606661022, 0.08026109958332964, 0.07378015918848105]
Upvotes: 3
Reputation: 523
It is the training loss and accuracy. You'll get results for validation set at the end of epoch.
Upvotes: 0