1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # # µû¶óÇÏ¸ç ¹è¿ì´Â ÆÄÀ̽ã°ú µ¥ÀÌÅÍ°úÇÐ(»ý´ÉÃâÆÇ»ç 2020) # 14.19 »õ·Î¿î ²É¿¡ ´ëÇؼ ¸ðµ¨À» Àû¿ëÇÏ°í ºÐ·ùÇØ º¸ÀÚ, 389ÂÊ # from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier iris = load_iris() knn = KNeighborsClassifier(n_neighbors=6) knn.fit(iris.data, iris.target) classes = {0:'setosa', 1:'versicolor', 2:'virginica'} # ¾ÆÁ÷ º¸Áö ¸øÇÑ »õ·Î¿î µ¥ÀÌÅ͸¦ Á¦½ÃÇØ º¸ÀÚ. X = [[3,4,5,2], [5,4,2,2]] y = knn.predict(X) print(classes[y[0]]) print(classes[y[1]]) | cs |