tfa.metrics.hamming_distance

View source on GitHub

Computes hamming distance.

Hamming distance is for comparing two binary strings. It is the number of bit positions in which two bits are different.

actuals actual target value
predictions predicted value

hamming distance: float

Usage:

actuals = tf.constant([1, 1, 0, 0, 1, 0, 1, 0, 0, 1],
                      dtype=tf.int32)
predictions = tf.constant([1, 0, 0, 0, 1, 0, 0, 1, 0, 1],
                          dtype=tf.int32)
result = hamming_distance(actuals, predictions)
print('Hamming distance: ', result.numpy())