Python keras预测模型的损失或准确性的绘图图

Python keras预测模型的损失或准确性的绘图图,python,matplotlib,tensorflow,graph,keras,Python,Matplotlib,Tensorflow,Graph,Keras,因此,我试图为我的模型绘制一个图表,假设我有20个历元,图表应该显示每个历元的精度/损失。到目前为止,我在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) 这就是我得到的错误

因此,我试图为我的模型绘制一个图表,假设我有20个历元,图表应该显示每个历元的精度/损失。到目前为止,我在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'
有没有办法纠正这个问题,或者用其他方法为每个历元绘制一张图表?
谢谢。

这段代码对我有用

model_history = model.fit(...

plt.figure()
plt.subplot(211)
plt.plot(model_history.history['accuracy'])
plt.subplot(212)
plt.plot(model_history.history['loss'])
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()

为什么要显示一个示例R代码而不是产生错误的Python代码?请提供一段时间,这段代码可能会回答这个问题,最好在代码中添加一些解释。你做了什么/改变了什么解决了这个问题?看见