Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tfa.metrics.hamming_distance

View source on GitHub

Computes hamming distance.

tfa.metrics.hamming_distance(
    actuals,
    predictions
)

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

Args:

  • actuals: actual target value
  • predictions: predicted value

Returns:

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())