A garden centre identifies leaves from two measurements, length and width in centimetres, by comparing each new leaf with leaves it has already labelled. That is K-Nearest Neighbors: no formula is learned; every prediction is a fresh look at the stored examples.
To classify one new point, KNN:
Real data needs two tie rules, and you must follow both exactly:
X_train counts as nearer. This decides which points make it into the .Task: write knn_classify(X_train, y_train, queries, k).
X_train is a list of points, each a list of numbers; y_train holds one label per point. Labels may be strings or integers.queries is a list of new points with the same number of features.k is a whole number from 1 up to the number of training points.Return a list with one predicted label per query, in the same order as queries.