K-nearest neighbors (KNN) is a type of supervised learning algorithm used for both regression and classification.
Slider to set the K and then click the green flag.
Please run this project at:
https://turbowarp.org/727082120
The KNN Algorithm:
1. Load the data
2. Initialize K to your chosen number of neighbors
3. For each example in the data
3.1 Calculate the distance between the query example and the current example from the data.
3.2 Add the distance and the index of the example to an ordered collection
4. Sort the ordered collection of distances and indices from smallest to largest (in ascending order) by the distances
5. Pick the first K entries from the sorted collection
6. Get the labels of the selected K entries
7. If regression, return the mean of the K labels
8. If classification, return the mode of the K labels