python - 使用 Python 绘制已经计算好的混淆矩阵
问题描述
对于已经给定的混淆矩阵值,我如何在 Python 中绘制一个类似于此处显示的混淆矩阵?
在代码中,他们使用sklearn.metrics.plot_confusion_matrix
基于基本事实和预测计算混淆矩阵的方法。
但就我而言,我已经计算了我的混淆矩阵。例如,我的混淆矩阵是(百分比值):
[[0.612, 0.388]
[0.228, 0.772]]
解决方案
如果您检查 的来源,sklearn.metrics.plot_confusion_matrix
您可以看到如何处理数据以创建绘图。然后您可以重用构造函数ConfusionMatrixDisplay
并绘制自己的混淆矩阵。
import matplotlib.pyplot as plt
from sklearn.metrics import ConfusionMatrixDisplay
cm = [0.612, 0.388, 0.228, 0.772] # your confusion matrix
ls = [0, 1] # your y labels
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=ls)
disp.plot(include_values=include_values, cmap=cmap, ax=ax, xticks_rotation=xticks_rotation)
plt.show()
推荐阅读
- python - 指示 Pycharm 是否正在使用“Debug”或“Run”运行代码的标志
- c# - 组成列表的类的枚举器
- c# - 递归算法 C#
- c - 从(汇编)指令序列到 C 代码的映射
- c# - 在 Azure 云服务上运行 Selenium Chrome WebDriver?
- haskell - 如何正确实现 Foreign.Storable 以创建向量?
- python - 如何扩展数据(插值?)
- ios - 如何在 UITableViewCell 中创建 TextField?
- bash - .bash_profile 带有变量的别名
- c# - 在不阻塞 ui UWP 的情况下调用数据库异步方法的最佳实践