mindspore.train.Fbeta

View Source On Gitee
class mindspore.train.Fbeta(beta)[source]

Calculates the Fbeta score.

Fbeta score is a weighted mean of precision and recall.

\[F_\beta=\frac{(1+\beta^2) \cdot true\_positive} {(1+\beta^2) \cdot true\_positive +\beta^2 \cdot false\_negative + false\_positive}\]
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 Tensor
>>> from mindspore.train import Fbeta
>>>
>>> x = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]]))
>>> y = Tensor(np.array([1, 0, 1]))
>>> metric = Fbeta(1)
>>> metric.clear()
>>> metric.update(x, y)
>>> fbeta = metric.eval()
>>> print(fbeta)
[0.66666667 0.66666667]
clear()[source]

Clears the internal evaluation result.

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 \([0, 1]\) and the shape is \((N, C)\), where \(N\) is the number of cases and \(C\) is the number of categories. y contains values of integers. The shape is \((N, C)\) if one-hot encoding is used. Shape can also be \((N,)\) 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.