gpt4 book ai didi

python - 如何以指数形式将混淆矩阵中显示的值固定为标准形式

转载 作者:行者123 更新时间:2023-12-04 01:26:52 25 4
gpt4 key购买 nike

在处理我的项目时,我从测试数据中获得了一个混淆矩阵:

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cm

输出为:
array([[1102,   88],
[ 85, 725]], dtype=int64)

使用 seaborn 和 matplotlib,我使用代码对其进行了可视化:
import seaborn as sns
import matplotlib.pyplot as plt

ax= plt.subplot();
sns.heatmap(cm, annot=True,cmap='Blues',ax=ax);
# labels, title and ticks
ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels');
ax.set_ylim(2.0, 0)
ax.set_title('Confusion Matrix');
ax.xaxis.set_ticklabels(['Fake','Real']);
ax.yaxis.set_ticklabels(['Fake','Real']);

得到的输出是:

Confusion matrix

问题是 3 位数字(此处 1102 显示为 11e+03)或以上的值以指数形式显示。

有没有办法以正常形式显示它?

最佳答案

您可以使用 "fmt"选项:

cm = np.array([[1102,   88],[85,  725]])

import seaborn as sns
import matplotlib.pyplot as plt

sns.heatmap(cm, annot=True,fmt="d",cmap='Blues')

enter image description here

关于python - 如何以指数形式将混淆矩阵中显示的值固定为标准形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61748441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com