What might be some key factors for increasing or stabilizing the accuracy score (NOT TO significantly vary) of this basic KNN model on IRIS data?
Attempt
from sklearn import neighbors, datasets, preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
iris = datasets.load_iris()
X, y = iris.data[:, :], iris.target
Xtrain, Xtest, y_train, y_test = train_test_split(X, y)
scaler = preprocessing.StandardScaler().fit(Xtrain)
Xtrain = scaler.transform(Xtrain)
Xtest = scaler.transform(Xtest)
knn = neighbors.KNeighborsClassifier(n_neighbors=4)
knn.fit(Xtrain, y_train)
y_pred = knn.predict(Xtest)
print(accuracy_score(y_test, y_pred))
print(classification_report(y_test, y_pred))
print(confusion_matrix(y_test, y_pred))
Sample Accuracy Scores
0.9736842105263158
0.9473684210526315
1.0
0.9210526315789473
Classification Report
precision recall f1-score support
0 1.00 1.00 1.00 12
1 0.79 1.00 0.88 11
2 1.00 0.80 0.89 15
accuracy 0.92 38
macro avg 0.93 0.93 0.92 38
weighted avg 0.94 0.92 0.92 38
Sample Confusion Matrix
[[12 0 0]
[ 0 11 0]
[ 0 3 12]]