K-Nearest Neighbors

k-Nearest Neighbors (k-NN) is a relatively simple machine learning algorithm. Each instance is classified by comparing it to its K-nearest examples as the majority class. In regression, the average value of neighbors is used. Scikit-learn's implementation lies within the sklearn.neighbors package of the library. As it is the naming convention of the library, KNeighborsClassifier implements the classification and KNeighborsRegressor implements the regression version of the algorithm. Using them in our examples, the regressor generates an R2 of 0.58 with an MSE of 2342, while the classifier achieves 93% accuracy. The following table shows the k-NN confusion matrix for the breast cancer dataset:

n = 169

Predicted: Malignant

Predicted: Benign

Target: Malignant

37

2

Target: Benign

9

121

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset