tf.keras.metrics.TopKCategoricalAccuracy

Computes how often targets are in the top K predictions.

Inherits From: Mean, Metric, Layer, Module

k (Optional) Number of top elements to look at for computing accuracy. Defaults to 5.
name (Optional) string name of the metric instance.
dtype (Optional) data type of the metric result.

Standalone usage:

m = tf.keras.metrics.TopKCategoricalAccuracy(k=1)
m.update_state([[0, 0, 1], [0, 1, 0]],
               [[0.1, 0.9, 0.8], [0.05, 0.95, 0]])
m.result().numpy()
0.5
m.reset_state()
m.update_state([[0, 0, 1], [0, 1, 0]],
               [[0.1, 0.9, 0.8], [0.05, 0.95, 0]],</