Issue
How to plot graph in Keras stating from 1 instead of 0. I have trained a model for 20 epochs and the graph is showing epoch x-axis from 0 to 19.
Code :
hist = model.fit(train_generator, validation_data=val_generator, epochs=20,
batch_size=batchsize)
plt.figure(figsize=(8,8))
plt.subplot(2,1,1)
plt.plot(hist.history['accuracy'],marker='o')
plt.plot(hist.history['val_accuracy'],marker='p')
plt.axis(ymin=0.0,ymax=1)
plt.grid()
plt.title('VGG16 Model Accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epochs')
plt.legend(['Training Accuracy', 'Validation Accuracy'])
plt.show()
How this problem could be resolved?
Solution
I've created the graph using only the train accuracies. But you can obtain the same adding also your validation accuracies:
import matplotlib.pyplot as plt
import numpy as np
# acc_history is the same as your hist.history['accuracy']
acc_history = [0.9002329707145691, 0.9219149351119995, 0.9280775785446167, 0.9322110414505005, 0.9352172017097473, 0.937546968460083, 0.9384863972663879, 0.9416428804397583, 0.9418307542800903, 0.9441981315612793, 0.9461145401000977, 0.9464902877807617, 0.9477679133415222, 0.9504734873771667, 0.9524274468421936, 0.954456627368927, 0.9550578594207764, 0.9591537714004517, 0.9588531255722046, 0.9635878801345825, 0.9638884663581848, 0.9652412533760071, 0.9674583077430725, 0.9688861966133118, 0.9716669321060181]
plt.figure(figsize=(8,8))
plt.subplot(2,1,1)
plt.plot(acc_history, marker='o')
# change the values on the ticks, starting from 1
plt.xticks(np.arange(len(acc_history)), np.arange(1, len(acc_history)+1))
plt.axis(ymin=0.0, ymax=1)
plt.grid()
plt.title('VGG16 Model Accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epochs')
plt.legend(['Training Accuracy'])
plt.show()
Basically xticks
lets you specify the labels that you want on your x axis.
The output graph is:
Answered By - ClaudiaR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.