1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # # µû¶óÇÏ¸ç ¹è¿ì´Â ÆÄÀ̽ã°ú µ¥ÀÌÅÍ°úÇÐ(»ý´ÉÃâÆÇ»ç 2020) # 14.18 k-NN ¾Ë°í¸®ÁòÀ» Àû¿ëÇغ¸ÀÚ, 388ÂÊ # # (80:20)À¸·Î ºÐÇÒÇÑ´Ù. from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split iris = load_iris() X_train,X_test,y_train,y_test = train_test_split(iris.data, iris.target, test_size=0.2) from sklearn.neighbors import KNeighborsClassifier from sklearn import metrics num_neigh = 3 knn = KNeighborsClassifier(n_neighbors = num_neigh) knn.fit(X_train, y_train) y_pred = knn.predict(X_test) scores = metrics.accuracy_score(y_test, y_pred) print('n_neighbors°¡ {0:d}À϶§ Á¤È®µµ: {1:.3f}'.format(num_neigh, scores)) | cs |