Underfitting and OverfittingCode with Python
scikit-learn's KNeighborsClassifier is KNN. n_neighbors is the k, and model.score returns the accuracy — the fraction of bushes predicted right. The loop tries four values of k and scores each on the known bushes and on the 12 new ones. Run the program.
KNN by Hand
KNN needs no training at all: to judge a new bush, measure its distance to every known bush, sort, and count the votes of the nearest k. math.dist gives the straight-line distance between two points. Run it, then change k.