( -nearest neighbor figure the data science process ( -nearest neighbor ( -nearest neighbor -nearest neighbor techniques look at the -nearest point to make prediction let' try it in python code using the scikit learn libraryas in this next listing listing executing -nearest neighbor classification on semi-random data imports modules creates random predictor from sklearn import neighbors data and semi-random predictors np random random( reshape( , target data based on target np around(predictors dot(np array([ ])predictor data np random random( )clf neighbors kneighborsclassifier(n_neighbors= fits -nearest knn clf fit(predictors,targetneighbors model knn score(predictorstargetgets model fit scorewhat percent of the classification was correctas beforewe construct random correlated data and surprisesurprise we get of cases correctly classified if we want to look in depthwe need to score the model don' let knn score(fool youit returns the model accuracybut by "scoring modelwe often mean applying it on data to make prediction prediction knn predict(predictorsnow we can use the prediction and compare it to the real thing using confusion matrix metrics confusion_matrix(target,predictionwe get -by- matrix as shown in figure