【发布时间】:2021-04-23 07:10:39
【问题描述】:
import matplotlib.pyplot as plt
from keras.models import load_model
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
我在尝试为以下代码 sn-p 绘制混淆矩阵时遇到错误
from sklearn.metrics import confusion_matrix
pred = model.predict(X_test)
pred = np.argmax(pred,axis = 1)
y_true = np.argmax(y_test,axis = 1)
上述sn-p的错误是“NameError: name 'model' is not defined”
CM = confusion_matrix(y_true, pred)
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=CM , figsize=(5, 5))
plt.show()
上述 sn-p 的错误是“NameError: name 'y_true' is not defined”
【问题讨论】:
-
您好!作为本网站的长期用户,您的问题已出现在我的审核队列中。恐怕这有点像XY problem:您在问如何“绘制混淆矩阵”,但是您对错误消息的困惑表明您对 Python 的理解还不够好,无法将其用于 ML 任务. (要明白我的意思,请尝试从命令提示符运行它:
python -c "print(model)"。)这里没有判断(不久前我自己还是个初学者),但我建议你在尝试使用之前阅读一本关于 Python 的介绍性书籍它适用于 ML。
标签: python keras deep-learning