Thursday, October 18, 2018

k-Nearest Neighbor Classifier




First try with one of the simplest classifier: The k-Nearest Neighbor Classifier...




This post is inspired by the video of Josh Gordon (below) about the Python implementation of a k-NN classifier. Watch this video to understand the principle and after that let's see how to do the same thing in JavaScript/ImageJ.



1. The data

Just to remind you the image of Fig. 1 which is composed of three different shapes: (i) circles, (ii) squares, and (iii) triangles of various sizes and orientations. Here, we would like to count their numbers.


Fig.1: Image of squares, circles, and triangles.

Several features were calculated from this image thanks to ImageJ and saved as a CSV file.


4. Our implementation

In the video, the kNN classifier is based on two main functions:
  • fit(x_train,y_train) returning an object containing the "model".
  • predict(x_test) returning an array of numbers (the predictions).
  • closest(self,x) is an auxiliary function used by the function predict(..).

Here is the skeleton of the implementation of the kNN classifier

TODO


<<  Previous: Dataset Next: ???  >>

5. Other crazybiocomputing posts

Further readings are available in ...

No comments:

Post a Comment