1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| from sklearn.model_selection import GridSearchCV
para,_grid = [ { 'weights':['uniform'], 'n_neighbors':[i for i in range(1,11)] }, { 'weights':['distance'], 'n_neighbors':[i for i in range(1,11)], 'p':[i for i in range(1,6)] } ]
knn_clf = KneighborsClassifier() grid_search = GridSearchCV(knn_clf,param_grid,n_jobs=-1,verbose=2) grid_search.fit(X_train,y_train)
grid_search.best_score_
grid_search.best_params_
grid_search.best_estimator_
|