使用iris数据集进行构建模型
from sklearn.neighbors import KNeighborsClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
iris = load_iris()
x, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=4)
knn = KNeighborsClassifier()
knn.fit(X_train, y_train)
knn_pred = knn.predict(X_test)