K Nearest Neighbor in TF v2

As I am going through the Google Developer Expert process I was asked with coding up KNN in TensorFlow. I couldn’t find an example online so I decided to create it.

The gist was that I could use *tf.math.squared_difference* to measure the difference. Then, I used reduce_sum to combine the 4 feature differences to a single number. Then, I would reverse the values using tf.negative and call tf.math.top_k to grab the nearest. Pretty straight forward.

GitHub: https://github.com/ehennis/Blog/blob/master/TensorFlow/K_Nearest_Neighbor.ipynb

YouTube: https://youtu.be/dA7QK80jTzA

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s