text: # -*- coding: utf-8 -*-
  """09_k_Nearest_Neighbour_algorithm.ipynb
  
  Automatically generated by Colaboratory.
  
  Original file is located at
      https://colab.research.google.com/drive/1o3c3XadkX-gRlIUrTqEG8-wfufLktfjn
  
  **9. Write a program to implement k-Nearest Neighbour algorithm to classify the iris data set.
  Print both correct and wrong predictions. Java/Python ML library classes can be used for this
  problem**
  """
  
  from sklearn.datasets import load_iris
  from sklearn.neighbors import KNeighborsClassifier
  from sklearn.model_selection import train_test_split
  import numpy as np
  
  dataset = load_iris()
  print(dataset)
  X_train, X_test, y_train, y_test =train_test_split(dataset["data"],dataset["target"],random_state=0)
  
  print(len(dataset["data"]))
  print(len(X_train))
  print(len(x_test))
  #print(y_train)
  #print(y_test)
  
  kn=KNeighborsClassifier(n_neighbors=1)
  kn.fit(X_train,y_train)
  KNeighborsClassifier(n_neighbors=1)
  
  for i in range(len(X_test)):
    x=X_test[i]
    x_new=np.array([x])
    prediction=kn.predict(x_new)
    print("TARGET=",y_test[i],dataset["target_names"][y_test[i]],"PREDICTION=",prediction,dataset["target_names"][prediction])
    print(kn.score(X_test, y_test))