【问题标题】:How can i get an index for true positive, false positive, true negative, and false negative using scikit learn?如何使用 scikit learn 获得真阳性、假阳性、真阴性和假阴性的索引?
【发布时间】:2021-11-15 14:11:12
【问题描述】:

我们可以使用scikit-learn easily 计算 tp、fp、tn 和 fn 的计数。但是,我想知道 tp、fp、tn 和 fn 的数据索引。

例如)

pred: [1, 1, 1, 0, 0, 0]
true: [1, 0, 1, 0, 1, 0]

tp = [0, 2]
fp = [1]
tn = [3, 5]
fn = [4]

我怎样才能得到它? 谢谢大家的回复。

【问题讨论】:

  • 你解决了这个问题吗?我的解决方案对你有用吗?

标签: python-3.x machine-learning scikit-learn metrics confusion-matrix


【解决方案1】:

使用np.array 并将truepred 加入一个列表。要创建唯一的组合,请使用二进制数字系统:

tn: 00 = 0
fp: 01 = 1
fn: 10 = 2
tp: 11 = 3

现在您可以使用numpy.where 函数来获取索引列表。

import numpy as np

pred = [1, 1, 1, 0, 0, 0]
true = [1, 0, 1, 0, 1, 0]

unq = np.array([x + 2*y for x, y in zip(pred, true)])

tp = np.array(np.where(unq == 3)).tolist()[0]
fp = np.array(np.where(unq == 1)).tolist()[0]
tn = np.array(np.where(unq == 0)).tolist()[0]
fn = np.array(np.where(unq == 2)).tolist()[0]

【讨论】:

    猜你喜欢
    • 2015-09-28
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2017-06-08
    • 2021-12-14
    相关资源
    最近更新 更多