chainer.functions.binary_accuracy¶
- chainer.functions.binary_accuracy(y, t)[source]¶
Computes binary classification accuracy of the minibatch.
- Parameters
y (
Variable
or N-dimensional array) – Array whose i-th element indicates the score of positive at the i-th sample. The prediction label \(\hat t[i]\) is1
ify[i] >= 0
, otherwise0
.t (
Variable
or N-dimensional array) – Array holding a signed integer vector of ground truth labels. Ift[i] == 1
, it indicates that i-th sample is positive. Ift[i] == 0
, it indicates that i-th sample is negative. Ift[i] == -1
, correspondingy[i]
is ignored. Accuracy is zero if all ground truth labels are-1
.
- Returns
A variable holding a scalar array of the accuracy.
- Return type
Note
This function is non-differentiable.
Example
We show the most common case, when
y
is the two dimensional array.>>> y = np.array([[-2.0, 0.0], # prediction labels are [0, 1] ... [3.0, -5.0]]) # prediction labels are [1, 0] >>> t = np.array([[0, 1], ... [1, 0]], np.int32) >>> F.binary_accuracy(y, t).array # 100% accuracy because all samples are correct. array(1.) >>> t = np.array([[0, 0], ... [1, 1]], np.int32) >>> F.binary_accuracy(y, t).array # 50% accuracy because y[0][0] and y[1][0] are correct. array(0.5) >>> t = np.array([[0, -1], ... [1, -1]], np.int32) >>> F.binary_accuracy(y, t).array # 100% accuracy because of ignoring y[0][1] and y[1][1]. array(1.)