fork download
  1. import numpy as np
  2. from sklearn.neighbors import KNeighborsClassifier
  3. from sklearn.model_selection import train_test_split
  4. from sklearn.metrics import accuracy_score
  5. x=np.array([[3,5],[4,7],[5,3],[6,4],[8,2],[9,6]])
  6. y=np.array([0,0,1,1,1,0])
  7. x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=42)
  8. model=KNeighborsClassifier(n_neighbors=3)
  9. model.fit(x_train,y_train)
  10. y_pred=model.predict(x_test)
  11. accuracy=accuracy_score(y_test,y_pred)
  12. print("Accuracy:",accuracy)
Success #stdin #stdout 0.44s 61492KB
stdin
Standard input is empty
stdout
('Accuracy:', 0.0)