-
machine learningCording/Python 2021. 2. 1. 23:07
from sklearn.datasets import load_iris
iris_dataset = load_iris()
print("iris_dataset의 키 : {}".format(iris_dataset.keys()))
print("타깃의 이름 : ", iris_dataset['feature_names'])
print("data type : ", type(iris_dataset['data']))
print("size of data : ", iris_dataset['data'].shape)
print("data : \n", iris_dataset['data'][:3])
print("target의 크기 : ", iris_dataset['target'].shape)
print("target : ", iris_dataset['target'])
print("target name : ", iris_dataset['target_names'])
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris_dataset['data'], iris_dataset['target'], random_state=0)
print("X_train :", X_train.shape)
print("X_test : ", X_teset.shape)
print("y_train: ", y_train.shape)
print("y_test : ", y_test.shape)
iris_dataframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names)
pd.plotting.scatter_matrix(iris_dataframe. c=y_train, figsize(15,15), marker='o', hist_kwds={'bins':20}, s=60, alpha=.8, cmap=mglearn.cm3)
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(ne_neighbors=1)
knn.fit(X_train, y_train)
X_new = np.arrary([[5,2,9,1,0,2]])
prediction = knn.predict(X_new)
print("예측 : ", prediction)
y_pred = knn.predcit(X_test)
print("예측값 : ", y_pred)
print("정확 : {:.2f}", format(knn.score(X_test, y_test))