简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM