简体   繁体   English

每个 epoch 的准确度都是从 0 而不是 1 开始

[英]Accuracy for every epoch is starting with 0 instead of 1

在此处输入图像描述

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.如何在 Keras 中的 plot 图表从 1 而不是 0 说明。我已经训练了 model 20 个纪元,图表显示从 0 到 9 的纪元 x 轴。

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?如何解决这个问题?

You can do like this:你可以这样做:

import matplotlib.pyplot as plt
import numpy as np

acc_train_history = hist.history['accuracy']
acc_val_history = hist.history['val_accuracy']

plt.figure(figsize=(8,8))
plt.subplot(2,1,1)

plt.plot(acc_train_history, marker='o')
plt.plot(acc_val_history,marker='p')
# change the values on the ticks, starting from 1
plt.xticks(np.arange(len(acc_train_history)), np.arange(1, len(acc_train_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', 'Validation Accuracy'])
plt.show()

Basically xticks lets you specify the labels that you want on your x axis.基本上xticks允许您在 x 轴上指定所需的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM