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

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -