분류베이즈_KNN
분류베이즈_KNN
from sklearn.datasets import load_iris
iris = load_iris()
print(iris.data)
print(iris.feature_names)
print(iris.target)
from sklearn.model_selection import train_test_split
X = iris.data
Y = iris.target
X_train,X_test,y_train,y_test = train_test_split(X, Y, test_size=0.2, random_state=4)
print(X_train.shape)
print(X_test.shape)
from sklearn.neighbors import KNeighborsClassifier
from sklearn import metrics
knn = KNeighborsClassifier(n_neighbors=6)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
scores = metrics.accuracy_score(y_test, y_pred)
print(scores)
classes = {0:'setosa', 1:'versicolor',2:'virginica'}
x_new = [[3,4,5,2],
[5,4,2,2]]
y_predict = knn.predict(x_new)
print(classes[y_predict[0]])
print(classes[y_predict[1]])