from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV
def knn_iris_gscv():
iris = load_iris()
x_train,x_test,y_train,y_test = train_test_split(iris.data,iris.target,random_state=6)
transfer = StandardScaler()
x_trains = transfer.fit_transform(x_train)
x_test = transfer.transform(x_test)
estimate = KNeighborsClassifier()
param_dict={"n_neighbors":[1,3,5,7,11]}
estimater = GridSearchCV(estimate,param_grid=param_dict,cv=10)
estimate.fit(x_train,y_train)
y_predict = estimate.predict(x_test)
print(y_predict)
print(y_predict==y_test)
score = estimate.score(x_test,y_test)
print("准确率为"+score)
print("最佳的k" + estimater.best_params_)
print("最佳结果"+estimater.best_score_)
print("最佳估计器"+estimater.best_estimator_)
return None