python - Picking n_neighbors for KNeighborsClassifier -
simple question couldn't find answer anywhere online. based on data, how pick number use n_neighbors? or best use default of 5? data set working uses 13 values predict target.
you should try different parameters , evaluate them via cross validation. sklearn has class that: gridsearchcv:
g = gridsearchcv(kneighborsclassifier(), { "n_neighbors" : [5, 7, 11, 13, 17] }) g.fit(x, y)
it's easy customize scoring function , (most importantly) run evaluations in parallel.
Comments
Post a Comment