13

Do you know if models from scikit-learn use automatically multithreading or just sequential instructions?

Thanks

1 Answer 1

23

No. All scikit-learn estimators will by default work on a single thread only.

But then again, it all depends on the algorithm and the problem. If the algorithm is such that which want sequential data, we cannot do anything. If the dataset is multi-class or multi-label and algorithm works on a one-vs-rest basis, then yes it can use multi-threading.

Look for a param n_jobs in the utilities or algorithm you want to use, and set it to -1 for using the multi-threading.

For eg.

  • LogisticRegression if working in a binary problem will only train a single model, which will require data sequentially, so here using n_jobs have no effect. But it handles multi-class problems as OvR, so it will have to train those many estimators using the same data. In this case you can use the n_jobs=-1.

  • DecisionTreeClassifier is inherently multi-class enabled and dont need to train multiple models. So we dont have that param there.

  • Ensemble methods like RandomForestClassifier will train multiple estimators (irrespective of problem type) which individually work on some part of data, so here again we can make use of n_jobs.

  • Cross-validation utilities like cross_val_score or GridSearchCV will again work on some part of data or some individual parameters, which is independent of other folds, so here also we can use multi-threading capabilities.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for clarification

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.