title: Accuracy score for a KNN model (IRIS data)
body: <p>What might be some key factors for increasing or stabilizing the <strong>accuracy score</strong> (<strong>NOT TO</strong> significantly vary) of this basic KNN model on IRIS data?</p>
  
  <h3>Attempt</h3>
  
  <pre><code>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))
  </code></pre>
  
  <h3>Sample Accuracy Scores</h3>
  
  <pre><code>0.9736842105263158
  0.9473684210526315
  1.0
  0.9210526315789473
  </code></pre>
  
  <h3>Classification Report</h3>
  
  <pre><code>              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
  </code></pre>
  
  <h3>Sample Confusion Matrix</h3>
  
  <pre><code>[[12  0  0]
   [ 0 11  0]
   [ 0  3 12]]
  </code></pre>