Shi*_* RD 4 python matplotlib seaborn
在处理我的项目时,我从测试数据中获得了一个混淆矩阵,如下所示:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cm
Run Code Online (Sandbox Code Playgroud)
输出为:
array([[1102, 88],
[ 85, 725]], dtype=int64)
Run Code Online (Sandbox Code Playgroud)
使用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']);
Run Code Online (Sandbox Code Playgroud)
得到的输出是:
问题是 3 位数字(此处 1102 显示为 11e+03)或以上的值以指数形式显示。
有没有办法以正常形式显示它?
Stu*_*olf 12
您可以使用以下"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')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5533 次 |
| 最近记录: |