【问题标题】:How to prepare confusion matrix from the predicted class probabilities?如何根据预测的类别概率准备混淆矩阵?
【发布时间】:2021-05-01 18:51:26
【问题描述】:
有一个使用给定训练数据创建的朴素贝叶斯分类器。在表中,显示了预测的正类概率和实际的类标签。我想准备混淆矩阵,但只知道概率我不知道怎么做。
| ID |
Actual class label |
Predicted positive class probability |
| 1 |
+ |
0.6 |
| 2 |
+ |
0.8 |
| 3 |
- |
0.2 |
| 4 |
+ |
0.3 |
| 5 |
- |
0.4 |
【问题讨论】:
标签:
machine-learning
classification
naivebayes
confusion-matrix
【解决方案1】:
首先,您需要有离散的类标签来计算混淆矩阵。在预测的正类概率上定义一个阈值来预测类标签 (y_pred)。
然后,您可以使用实际的类标签 (y_actual) 和 y_pred 来计算混淆矩阵。
from sklearn.metrics import confusion_matrix
confusion_matrix(y_actual, y_pred)