[英]Accuracy for every epoch is starting with 0 instead of 1
如何在 Keras 中的 plot 圖表從 1 而不是 0 說明。我已經訓練了 model 20 個紀元,圖表顯示從 0 到 9 的紀元 x 軸。
代碼:
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()
如何解決這個問題?
你可以這樣做:
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()
基本上xticks
允許您在 x 軸上指定所需的標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.