parallel work on KNN in python

I have a question, related to parallel work on python

How I can use Processers =1,2,3... on k nearest neighbor algorithm when K=1, 2, 3,.. to find the change in time spent, speedup, and efficiency.

What is the appropriate code for that?

Topic time k-nn preprocessing python efficiency

Category Data Science


AFAIK KNN take time only if size of the data is very huge. Meanwhile normal GridSearchCV itself works well with more K values, Refer this site - https://machinelearningknowledge.ai/knn-classifier-in-sklearn-using-gridsearchcv-with-example/.
Still you want to run in parallel please create a method in which you fit the KNN by accepting the K value as parameter in the method.
Create subprocess for each K value in the main method and call the KNN method by passing the K value.
Code will be more complex if you write like this since we need to write logic to compare the accuracy of each fit w.r.t cross validation etc.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.