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