Grouping similar data to predict a new point's label is called classification. KNN is the most intuitive classifier: it looks at the k nearest neighbors of a new point and takes a majority vote for the label. Complete knn_predict(X_train, y_train, X_test, k). X_train, y_train training features and labels. X_test new data whose labels you must predict. k the number of neighbors to consult. Train scikit-learn's KNN and return the predicted label for each row of X_test as an array. Example Given training data split into two groups, a new point is predicted as the label of the nearer group.
This challenge asks you to complete a function that trains scikit-learn's KNN (nearest-neighbors) classifier and returns a predicted label for each row of new data as an array. It takes training features and labels, the new data to predict, and the neighbor count k, and trains only on the training data. It practices the fundamentals of a classification model that judges by distance.
KNN looks at the k nearest neighbors of a new point and takes a majority vote — a classification method grounded in distance. This problem implements KNN with scikit-learn and verifies the result against the actual numbers.