import numpy as np
from sklearn.neighbors import KNeighborsClassifier
from sklearn import datasets
# model_selection:模型选择
# cross_val_score:交叉 validation:验证
# 交叉验证
from sklearn.model_selection import cross_val_score
导包加载数据
X,y = datasets.load_iris(True)
X.shape
(150, 4)
150**0.5 # 样本数量的开平方
# K值选择时从1到13 大概是其开平方的数值,只是用于参考
12.24744871391589
cross_val_score交叉验证筛选最合适的参数
knn = KNeighborsClassifier()
score = cross_val_score(knn,X,y,scoring='accuracy',cv=