Improve docs of accuracy
@@ -59,9 +59,15 @@ def accuracy(y, t, ignore_label=None):
"""Computes multiclass classification accuracy of the minibatch.
Args:
- y (Variable): Variable holding a matrix whose (i, j)-th element
- indicates the score of the class j at the i-th example.
- t (Variable): Variable holding an int32 vector of ground truth labels.
+ y (:class:`~chainer.Variable` or :class:`numpy.ndarray` or \
+ :class:`cupy.ndarray`):
+ Array whose (i, j, k, ...)-th element indicates the score of
+ the class j at the (i, k, ...)-th sample.
+ The prediction label :math:`\\hat t` is calculated by the formula
+ :math:`\\hat t_(i, k, ...) = argmax_j y(i, j, k, ...)`.
+ t (:class:`~chainer.Variable` or :class:`numpy.ndarray` or \
+ :class:`cupy.ndarray` of :class:`numpy.int32`):
+ Array of ground truth labels.
ignore_label (int or None): Skip calculating accuracy
if the true label is ``ignore_label``.
@@ -70,5 +76,25 @@ def accuracy(y, t, ignore_label=None):
.. note:: This function is non-differentiable.
+ .. admonition:: Example
+
+ We show the most common case, when``y`` is two dimensinal array.
+
+ >>> y = np.array([[0.1, 0.7, 0.2], # prediction label is 1
+ ... [8.0, 1.0, 2.0], # prediction label is 0
+ ... [-8.0, 1.0, 2.0], # prediction label is 2
+ ... [-8.0, -1.0, -2.0]]) # prediction label is 1
+ >>> t = np.array([1, 0, 2, 1], 'i')
+ >>> F.accuracy(y, t).data \
+# 100% accuracy because all samples are correct
+ array(1.0)
+ >>> t = np.array([1, 0, 0, 0], 'i')
+ >>> F.accuracy(y, t).data \
+# 50% accuracy because 1st and 2nd samples are correct.
+ array(0.5)
+ >>> F.accuracy(y, t, ignore_label=0).data \
+# 100% accuracy because of ignoring the 2nd, 3rd and 4th samples.
+ array(1.0)
+
"""
return Accuracy(ignore_label=ignore_label)(y, t)
