<jupyter_start><jupyter_text>通用学习模式<jupyter_code>import numpy as np
# 导入数据集
from sklearn import datasets

from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
# 加载数据
iris = datasets.load_iris()
# 获取花的属性信息
iris_x = iris.data
# 获取花的标签信息
iris_y = iris.target

iris_x[:2,:]
iris_y
# 把数据分为训练集和测试集，测试集数据占总数据的30%

x_train, x_test, y_train, y_test = train_test_split(iris_x , iris_y , test_size=0.3)
y_train
# 定义模型
knn = KNeighborsClassifier()
# 使用fit来训练
knn.fit(x_train, y_train)
print(knn.predict(x_test))
print(y_test)<jupyter_output>[2 2 2 1 1 2 0 0 0 2 2 0 2 2 2 2 1 1 0 0 1 0 2 1 1 0 2 0 2 0 2 1 1 0 1 2 2
 1 1 0 1 2 0 0 1]
[2 2 2 2 2 2 0 0 0 2 2 0 2 2 2 2 1 1 0 0 1 0 2 1 1 0 2 0 2 0 2 1 1 0 1 2 2
 1 1 0 1 2 0 0 1]
StarcoderdataJupyterStructuredCleanDedup