How can I identify the records inside each cluster in a KNN model in SciKit-Learn Python?
KNN is not clustering, but classification.
The parameter k is not the k of k-means; it is the number of neighbors not the number of clusters...
Hence, setting k to 5 dors not suddenly produce 5 labels. Your training data has 2 labels, hence you get 2 labels.
KNN = k-nearest neighbors classification. For k=5 this means 5 nearest neighbors.
K-means clustering = approximate the data with k center vectors. An entirely different k.
I am making a KNN model. The target variable is divided in 2 categories, and the features are 3 categorical variables (country, language and company). The model says the optimal is 5 clusters, so I did it with 5.
I need to know how can I see the records in each of the 5 clusters (I mean, the countries, languages and companies that the model is grouping in each of them). Is there a way to add the labels of the clusters to the dataframe?
I tried:
predictions = knn.predict(features)
But that is only returning the estimations for the 2 labels of the target variable
I did some research and found:
km.labels_
But that only applies for KMeans, and I am using KNN
I hope somebody can tell me the equivalent for that or how to solve the problem for KNN Model please