from sklearn model_selection import train_test_split xy mglearn datasets make_forge(x_trainx_testy_trainy_test train_test_split(xyrandom_state= nextwe import and instantiate the class this is when we can set parameterslike the number of neighbors to use herewe set it to in[ ]from sklearn neighbors import kneighborsclassifier clf kneighborsclassifier(n_neighbors= nowwe fit the classifier using the training set for kneighborsclassifier this means storing the datasetso we can compute neighbors during predictionin[ ]clf fit(x_trainy_trainto make predictions on the test datawe call the predict method for each data point in the test setthis computes its nearest neighbors in the training set and finds the most common class among thesein[ ]print("test set predictions{}format(clf predict(x_test))out[ ]test set predictions[ to evaluate how well our model generalizeswe can call the score method with the test data together with the test labelsin[ ]print("test set accuracy{ }format(clf score(x_testy_test))out[ ]test set accuracy we see that our model is about accuratemeaning the model predicted the class correctly for of the samples in the test dataset analyzing kneighborsclassifier for two-dimensional datasetswe can also illustrate the prediction for all possible test points in the xy-plane we color the plane according to the class that would be assigned to point in this region this lets us view the decision boundarywhich is the divide between where the algorithm assigns class versus where it assigns class supervised machine learning algorithms