分类指标

class ClassificationMetric[source]

基础类:Metric, ABC

分类指标的基础类。

属性摘要

binarize

指标是否需要二值化分数

closed_expectation

是否存在期望的闭式解

closed_variance

是否存在方差的闭式解

key

返回用于度量结果字典的键。

supports_weights

指标是否支持权重

synonyms

此指标的同义词

方法总结

__call__(y_true, y_score[, weights])

评估指标。

extra_repr()

生成额外的 repr,参见。

forward(y_true, y_score[, sample_weight])

计算指标。

get_description()

获取描述。

get_link()

从docdata中获取链接。

get_range()

获取此指标范围的数学表示。

iter_extra_repr()

遍历extra_repr()的组件。

属性文档

binarize: ClassVar[bool | None] = None

指标是否需要二值化分数

closed_expectation: ClassVar[bool] = False

是否存在期望的闭式解

closed_variance: ClassVar[bool] = False

是否存在方差的闭式解

key

返回用于度量结果字典的键。

supports_weights: ClassVar[bool] = False

指标是否支持权重

synonyms: ClassVar[Collection[str]] = ()

此指标的同义词

方法文档

__call__(y_true: ndarray, y_score: ndarray, weights: ndarray | None = None) float[来源]

评估指标。

Parameters:
  • y_true (ndarray) – 形状: (num_samples,) 真实标签,值为0或1。

  • y_score (ndarray) – 形状: (num_samples,) 预测值,可以是连续的或二值化的。

  • weights (ndarray | None) –

    形状: (num_samples,) 个体预测的权重

    警告

    并非所有指标都支持样本权重 - 请先检查 supports_weights

Returns:

标量度量值

Raises:

ValueError – 当提供了权重但函数不支持它们时。

Return type:

float

extra_repr() str

生成额外的 repr,参见 :meth`torch.nn.Module.extra_repr`。

Returns:

repr() 的额外部分

Return type:

str

abstract forward(y_true: ndarray, y_score: ndarray, sample_weight: ndarray | None = None) float[source]

计算指标。

Parameters:
  • y_true (ndarray) – 形状: (num_samples,) 真实标签,0 或 1。

  • y_score (ndarray) – 形状: (num_samples,) 预测值,可以是连续分数,也可以是二值化预测 (取决于具体的度量标准)。

  • sample_weight (ndarray | None) – 形状: (num_samples,) 样本权重

Returns:

一个标量度量值

Return type:

float

# noqa:DAR202

classmethod get_description() str

获取描述。

Return type:

str

从docdata中获取链接。

Return type:

str

classmethod get_range() str

获取此指标范围的数学表示。

Return type:

str

iter_extra_repr() Iterable[str]

遍历extra_repr()的组件。

此方法通常被重写。一个常见的模式是

def iter_extra_repr(self) -> Iterable[str]:
    yield from super().iter_extra_repr()
    yield "<key1>=<value1>"
    yield "<key2>=<value2>"
Returns:

一个可迭代的单个组件,用于extra_repr()

Return type:

Iterable[str]