Switch to full stage
Loading Project
Loading project …

Instructions

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

Notes and Credits

Project Reference: https://scratch.mit.edu/projects/375033920/ Thank you piano_miles. https://medium.com/swlh/k-nearest-neighbor- ca2593d7a3c4 https://www.javatpoint.com/k-nearest-neighbor-algorithm-for-machine-learning Sorting: Binary Sort from Zro716's project - https://scratch.mit.edu/projects/26497383/ Thank you Zro716.

TurboWarp is a Scratch mod that compiles projects to JavaScript to make them run really fast. Try it out by inputting a project ID or URL above or choosing a featured project below.