【问题标题】:Plot graph for either loss or accuracy of the keras predictive model绘制 keras 预测模型的损失或准确性的图表
【发布时间】:2018-08-01 06:18:33
【问题描述】:

所以我试图为我的模型绘制一个图表,假设我有 20 个 epoch,图表应该显示每个 epoch 的准确性/损失。截至目前,我在 Keras 网站上找到了这段代码。

history = model.fit(x_train, y_train, epochs = 30, batch_size = 128,validation_split = 0.2)
plot(history)

我尝试在我的数据上使用它。

import matplotlib.pyplot as plt
plt.plot(history)

所以这是我得到的错误

TypeError: float() argument must be a string or a number, not 'History'

有什么方法可以纠正这个或任何其他为每个时期绘制图表的方法吗? 谢谢。

【问题讨论】:

标签: python matplotlib tensorflow graph keras


【解决方案1】:
model_history = model.fit(...

plt.figure()
plt.subplot(211)
plt.plot(model_history.history['accuracy'])
plt.subplot(212)
plt.plot(model_history.history['loss'])

【讨论】:

  • 虽然此代码可能会回答问题,但通常最好在您的代码中添加一些解释。你做了什么/改变了什么解决了这个问题?见How to write a good answer
【解决方案2】:

这段代码对我有用。

print(history.history.keys()) # Displays keys from history, in my case loss,acc
plt.plot(history.history['acc']) #here I am trying to plot only accuracy, the same can be used for loss as well
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.show()

【讨论】:

    猜你喜欢
    • 2018-01-03
    • 2017-07-16
    • 1970-01-01
    • 2019-03-07
    • 2019-10-23
    • 2019-12-22
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多