user1234
user1234

Reputation: 155

Having recall, F-score, precision 1 with KNN classifier

I'm running a python script that I've took from a website. It's a simple code that uses Iris dataset and performs a KNN classification on that dataset. But when I run this script I keep getting all of measurement scores as 1.0 which is I believe a wrong result. Where did I make the mistake?

Classification part of the script:

knn = KNeighborsClassifier(n_neighbors=5)

knn.fit(X_train, y_train)


y_pred = knn.predict(X_test)  
print(confusion_matrix(y_test, y_pred))  
print(classification_report(y_test, y_pred))

You can reach the full script from here

Upvotes: 0

Views: 1500

Answers (1)

Mahsa Jalali
Mahsa Jalali

Reputation: 11

Try another dataset. It will work. Maybe your algorithm works well that classify all the data correctly. I have run this kNN program and had such an issue but for another dataset, it shows the answer other than 1.

Upvotes: 1

Related Questions