from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=13, stratify=iris.target)
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(X_train, y_train) # 학습은 아니고 그냥 컴퓨터 언어
pred = knn.predict(X_test)
print(accuracy_score(y_test, pred))
print(confusion_matrix(y_test, pred))
print(classification_report(y_test, pred))
Reference
1) 제로베이스 데이터스쿨 강의자료