【问题标题】:Specificity at different thresholds (in the same way as sklearn.metrics.precision_recall_curve)不同阈值下的特异性(与 sklearn.metrics.precision_recall_curve 相同)
【发布时间】:2020-05-17 00:09:14
【问题描述】:

我想以与precision_recall_curve 给出的精确率和召回率相同的方式获得特异性。

precisions, recalls, thresholds = sklearn.metrics.precision_recall_curve(ground_truth, predictions)

我怎样才能做到这一点?

【问题讨论】:

  • 你的问题是什么?
  • @PV8 sklearn.metrics.precision_recall_curve 为我提供了不同阈值下的精度和召回值。我也想/相反以类似的方式获得特异性/“真阴性率”。

标签: python machine-learning scikit-learn classification


【解决方案1】:

所以,我查看了sklearn.metrics.precision_recall_curve (https://github.com/scikit-learn/scikit-learn/blob/2e90b897768fd360ef855cb46e0b37f2b6faaf72/sklearn/metrics/_ranking.py) 的源代码并对其进行了修改以满足我的需要。

import numpy as np
from sklearn.metrics.ranking import _binary_clf_curve

def specificity_sensitivity_curve(y_true, probas_pred):
    """
    Compute specificity-sensitivity pairs for different probability thresholds.
    For reference, see 'precision_recall_curve'
    """
    fps, tps, thresholds = _binary_clf_curve(y_true, probas_pred)
    sensitivity = tps / tps[-1]
    specificity = (fps[-1] - fps) / fps[-1]
    last_ind = tps.searchsorted(tps[-1])
    sl = slice(last_ind, None, -1)
    return np.r_[specificity[sl], 1], np.r_[sensitivity[sl], 0], thresholds[sl]

【讨论】:

    猜你喜欢
    • 2014-09-22
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 2023-01-03
    相关资源
    最近更新 更多