【发布时间】:2021-04-28 05:51:35
【问题描述】:
我有两个要计算混淆矩阵的 DataFrame。
以下是“df_responses”结构的示例:
Question 1 | Red | Blue | Yellow | None of the Above |
Participant ID | | | | |
1 | 1 | 1 | 1 | 0 |
2 | 0 | 0 | 0 | 1 |
3 | 1 | 0 | 1 | 0 |
以下是“df_actual”的结构示例:
Question 1 | Red | Blue | Yellow | None of the Above |
| | | | |
1 | 1 | 0 | 1 | 0 |
2 | 1 | 0 | 1 | 0 |
3 | 1 | 0 | 1 | 0 |
理想情况下,我还想创建一个新的 DataFrame,其中包含每个参与者的 True Positive 和 False Negative 分数,如下所示:
Question 1 | True Positive | False Negative |
Participant ID | | |
1 | 2 | 0 |
2 | 0 | 2 |
3 | 2 | 0 |
我试过了(@John Mommers):
for x in range(len(df_responses)):
tn, fp, fn, tp = confusion_matrix(df_responses, df_actual).ravel()
print (f'Nr:{i} true neg:{tn} false pos:{fp} false neg:{fn} true pos:{tp}')
但是,我得到了一个
ValueError: multilabel-indicator is not supported.
是否有其他方法可以计算 TP 和 FN?
加法(数据作为文本):
df_responses
{'Red': {1: 1, 2: 0, 3: 1},
'Blue': {1: 1, 2: 0, 3: 0},
'Yellow': {1: 1, 2: 0, 3: 1},
'None of the above': {1: 0, 2: 1, 3: 0}}
df_actual
{'Red': {1: 1, 2: 1, 3: 1},
'Blue': {1: 0, 2: 0, 3: 0},
'Yellow': {1: 1, 2: 1, 3: 1},
'None of the above': {1: 0, 2: 0, 3: 0}}
【问题讨论】:
-
你能用
df.to_dict()将你的数据作为文本重新发布吗? -
是的,我已经添加了!
-
参与者2的真阳性是什么
-
参与者2的真阳性为零
标签: python scikit-learn confusion-matrix