mindspore2022/docs/api/api_python/nn/mindspore.nn.Precision.rst

51 lines
1.8 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.Precision
======================
.. py:class:: mindspore.nn.Precision(eval_type='classification')
计算数据分类的精度,包括单标签场景和多标签场景。
此函数创建两个局部变量 :math:`\text{true_positive}`:math:`\text{false_positive}` 用于计算精度。计算方式如下:
.. math::
\text{precision} = \frac{\text{true_positive}}{\text{true_positive} + \text{false_positive}}
.. note::
在多标签情况下, :math:`y`:math:`y_{pred}` 的元素必须为0或1。
**参数:**
- **eval_type** str- 支持'classification'和'multilabel'。默认值:'classification'。
.. py:method:: clear()
内部评估结果清零。
.. py:method:: eval(average=False)
计算精度。
**参数:**
- **average** (bool) - 指定是否计算平均精度。默认值False。
**返回:**
numpy.float64计算结果。
.. py:method:: update(*inputs)
使用预测值 `y_pred` 和真实标签 `y` 更新局部变量。
**参数:**
- **inputs** - 输入 `y_pred``y``y_pred``y` 支持Tensor、list或numpy.ndarray类型。
对于'classification'情况,`y_pred` 在大多数情况下由范围 :math:`[0, 1]` 中的浮点数组成shape为 :math:`(N, C)` ,其中 :math:`N` 是样本数, :math:`C` 是类别数。`y` 由整数值组成如果是one_hot编码格式shape是 :math:`(N,C)` 如果是类别索引shape是 :math:`(N,)`
对于'multilabel'情况,`y_pred``y` 只能是值为0或1的one-hot编码格式其中值为1的索引表示正类别。`y_pred``y` 的shape都是 :math:`(N,C)`
**异常:**
- **ValueError** - inputs数量不是2。