Skip to content

Homebrew k-nearest neighbors algorithm (k-NN) vs scikit-learn's built-in KNeighborsClassifier on the Iris flower data set

License

Notifications You must be signed in to change notification settings

kurtcms/knn-sklearn-iris

Repository files navigation

Homebrew k-Nearest Neighbors Algorithm (k-NN) vs scikit-learn's built-in KNeighborsClassifier on the Iris Flower Dataset

This Python script does the following:

  1. Builds a homebrew k-nearest neighbors algorithm (k-NN);
  2. Uses the homebrew k-NN as well as scikit-learn's built-in KNeighborsClassifier function, to classify the 3 different types of Iris flowers (Setosa, Versicolour, and Virginica), by their sepal length and width, from Ronald Fisher's Iris flower data set, and measures their accuracies, for k equals to 1 to the number of entries in the Iris flower data set minus 1;
  3. Plots the Iris flower data set on prediction grids generated by the homebrew k-NN and scikit-learn's KNeighborsClassifier, each using a value of k that maximises their respective prediction accuracies; and
  4. Plots also the prediction accuracies against k of both the homebrew k-NN and scikit-learn's KNeighborsClassifier for comparison.

alt text

Table of Content

Getting Started

Get started in three simple steps:

  1. Download a copy of the script;
  2. Install the dependencies; and
  3. Run the script manually.

Git Clone

Download a copy of the script with git clone.

$ git clone https://github.com/kurtcms/knn-sklearn-iris /app/knn-sklearn-iris/

Dependencies

This script requires the following libraries:

  1. NumPy
  2. Matplotlib
  3. scikit-learn

Install them with pip3:

$ pip3 install numpy matplotlib scikit-learn

Run

Run the script with python3.

$ python3 /app/knn-sklearn-iris/knn-sklearn-iris.py

About

Homebrew k-nearest neighbors algorithm (k-NN) vs scikit-learn's built-in KNeighborsClassifier on the Iris flower data set

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages