【问题标题】:Is there a way to draw confusion matrix with known True Positive, True Negative, False Positive and False Negative?有没有办法用已知的真阳性、真阴性、假阳性和假阴性来绘制混淆矩阵?
【发布时间】:2021-07-23 18:05:14
【问题描述】:
今天我完成了一些数据的处理并得出结论,我有以下最终表格,其中包含:
|
Counts. |
| True Positive |
23070 |
| True Negative |
4503 |
| False Positive |
28 |
| False Negative |
34 |
我正在尝试在这里构建一个混淆矩阵,scikit-learn.confusion_matrix 风格,但我不知道如何。我可以为此使用 Matplotlib 吗?
你们有没有来过他的任务类型?
我相信我们可以以某种方式绘制它。
谢谢!
【问题讨论】:
标签:
python
matplotlib
machine-learning
scikit-learn
confusion-matrix
【解决方案1】:
使用scikit-learn.confusion_matrix可以得到混淆矩阵
cm = confusion_matrix(y_true, y_pred)
并且混淆矩阵已经在表单中
TP|FN
FP|TN
您可以使用 seaborn 的热图来绘制数据:
import seaborn as sns
sns.heatmap(cm, annot=True, cmap='Blues')
如果您已经拥有数据,请尝试将其存储在列表中,然后使用 seaborn 绘制数据:
cm_data = [[23070, 34], [4503, 28]]
sns.heatmap(cm_data, annot=True, cmap='Blues', fmt='d')