Calculates how often predictions equal labels.

Inherits From: Mean, Metric, Layer, Module

Used in the notebooks

Used in the guide Used in the tutorials

This metric creates two local variables, total and count that are used to compute the frequency with which y_pred matches y_true. This frequency is ultimately returned as binary accuracy: an idempotent operation that simply divides total by count.

If sample_weight is None, weights default to 1. Use sample_weight of 0 to mask values.

name (Optional) string name of the metric instance.
dtype (Optional) data type of the metric result.

Standalone usage:

m = tf.keras.metrics.Accuracy()
m.update_state([[1], [2], [3], [4]], [[0], [2], [3], [4]])
m.update_state([[1], [2], [3], [4]], [[0], [2], [3], [4]],