k-Nearest Neighbour is the most simple machine learning and image classification algorithm. This algorithm depends on the distance between features vectors. In our cases, these features are pixel values in image matrix (height x width) k-NN algorithm classifies new unknown data points by finding the most common class among the k-closet examples.
k-NN can also be used for regression. In this case, output is a continuous variable which is the average of k-closet data points.
k-NN is a non-parametric learning algorithm, which means that it doesn't assume anything about the underlying data
Some useful links
A Quick Introduction to K-Nearest Neighbors Algorithm
K-Nearest Neighbors Algorithm in Python and Scikit-Learn
- One main advantage of k-NN algorithm is that it's simple to implement and understand.
- It is lazy learning algorithm and therefore requires no training prior to making real time predictions. This makes the KNN algorithm much faster than other algorithms that require training e.g SVM, linear regression, etc.
- There are only two parameters required to implement KNN i.e. the value of K and the distance function (e.g. Euclidean or Manhattan etc.)
- k-NN is more suited for low-dimensional features spaces(which images are not). Distances in high-dimensional features spaces are often unintuitive (curse of dimensionality)
- k-NN doesn't learn anything, that means it does not work towrads improving the performance(error) by looking at previous steps
- Sharing of k-NN models can be a problem when the data size is really huge as it requires to share all the data.
- k-NN algorithm doesn't work well with categorical features since it is difficult to find the distance between dimensions with categorical features.
- Python3
- OpenCV 3
- Packages mentioned in knn.py
- Pycharm/ Jupyter Notebook
- Download the dataset and save it in the folder "datasets"
- Name of sub-folders in parent folder "datasets" represnt lables (class). In our case, it's "Dog", and "Cat"
- Clone the repository
- Run knn_model.py using cmd/pycharm/jupyter notebook
Happy Learning !!!