mindspore.nn.Fbeta
- class mindspore.nn.Fbeta(beta)[source]
Calculates the Fbeta score.
Fbeta score is a weighted mean of precision and recall.
- Parameters
beta (Union[float, int]) – Beta coefficient in the F measure. beta should be greater than 0.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import nn, Tensor >>> >>> x = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]])) >>> y = Tensor(np.array([1, 0, 1])) >>> metric = nn.Fbeta(1) >>> metric.clear() >>> metric.update(x, y) >>> fbeta = metric.eval() >>> print(fbeta) [0.66666667 0.66666667]
- eval(average=False)[source]
Computes the fbeta.
- Parameters
average (bool) – Whether to calculate the average fbeta. Default: False.
- Returns
numpy.ndarray or numpy.float64, the computed result.
- update(*inputs)[source]
Updates the internal evaluation result y_pred and y.
- Parameters
inputs – Input y_pred and y. y_pred and y are Tensor, list or numpy.ndarray. y_pred is in most cases (not strictly) a list of floating numbers in range
and the shape is , where is the number of cases and is the number of categories. y contains values of integers. The shape is if one-hot encoding is used. Shape can also be if category index is used.- Raises
ValueError – class numbers of last input predicted data and current predicted data not match.
ValueError – If the predicted value and true value contain different classes.