Jim Olness
Jim Olness

Reputation: 53

How to enable multicore processing with sklearn LogisticRegression?

Sklearn's LogisticRegression model refuses to run in parallel. I set n_jobs=-1, and also tried n_jobs=4. No luck -- only one core is engaged. I've run other sklearn models in parallel, e.g., RandomForestClassifier and XGBoostClassifier.

I'm running Python 2.7.12 with sklearn 0.18 on Ubuntu 14.04.

Other people have asked the same question (e.g., here), thus far without receiving any promising replies. I'm hoping my luck will be better.

Upvotes: 4

Views: 11162

Answers (2)

Coding elephant
Coding elephant

Reputation: 33

In the source code of Logistic Regression you can see that there is a parameter "n_threads" which is explicitly set to 1. That parameter might be limiting the CPU usage.

Upvotes: 0

maxymoo
maxymoo

Reputation: 36555

From the doco for LogisticRegresssion it looks like the n_jobs parameter is only used for separate cross-validation folds (unlike the case for RandomForestClassifier where the individual trees are computed in parallel).

n_jobs : int, default: 1

Number of CPU cores used during the cross-validation loop. If given a value of -1, all cores are used.

Upvotes: 5

Related Questions