MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / accuracy

Function accuracy

tensorflow/contrib/metrics/python/metrics/classification.py:32–67  ·  view source on GitHub ↗

Computes the percentage of times that predictions matches labels. Args: predictions: the predicted values, a `Tensor` whose dtype and shape matches 'labels'. labels: the ground truth values, a `Tensor` of any shape and bool, integer, or string dtype. weigh

(predictions, labels, weights=None, name=None)

Source from the content-addressed store, hash-verified

30
31
32def accuracy(predictions, labels, weights=None, name=None):
33 """Computes the percentage of times that predictions matches labels.
34
35 Args:
36 predictions: the predicted values, a `Tensor` whose dtype and shape
37 matches 'labels'.
38 labels: the ground truth values, a `Tensor` of any shape and
39 bool, integer, or string dtype.
40 weights: None or `Tensor` of float values to reweight the accuracy.
41 name: A name for the operation (optional).
42
43 Returns:
44 Accuracy `Tensor`.
45
46 Raises:
47 ValueError: if dtypes don't match or
48 if dtype is not bool, integer, or string.
49 """
50 if not (labels.dtype.is_integer or
51 labels.dtype in (dtypes.bool, dtypes.string)):
52 raise ValueError(
53 'Labels should have bool, integer, or string dtype, not %r' %
54 labels.dtype)
55 if not labels.dtype.is_compatible_with(predictions.dtype):
56 raise ValueError('Dtypes of predictions and labels should match. '
57 'Given: predictions (%r) and labels (%r)' %
58 (predictions.dtype, labels.dtype))
59 with ops.name_scope(name, 'accuracy', values=[predictions, labels]):
60 is_correct = math_ops.cast(
61 math_ops.equal(predictions, labels), dtypes.float32)
62 if weights is not None:
63 is_correct = math_ops.multiply(is_correct, weights)
64 num_values = math_ops.multiply(weights, array_ops.ones_like(is_correct))
65 return math_ops.div(math_ops.reduce_sum(is_correct),
66 math_ops.reduce_sum(num_values))
67 return math_ops.reduce_mean(is_correct)
68
69
70def f1_score(labels, predictions, weights=None, num_thresholds=200,

Callers 1

evaluateFunction · 0.50

Calls 8

equalMethod · 0.80
multiplyMethod · 0.80
divMethod · 0.80
reduce_sumMethod · 0.80
reduce_meanMethod · 0.80
is_compatible_withMethod · 0.45
name_scopeMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected