Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel threading with xgboost?

According to its documentation, xgboost has an n_jobs parameter. However, when I attempt to set n_jobs, I get this error:

TypeError: __init__() got an unexpected keyword argument 'n_jobs'

Same issue for some other parameters like random_state. I assumed this might be an update issue, but it seems I have the latest version (0.6a2, installed with pip).

There isn't much needed for me to reproduce the error:

from xgboost import XGBClassifier 
estimator_xGBM = XGBClassifier(max_depth = 5, learning_rate = 0.05, n_estimators = 400, n_jobs = -1).fit(x_train)

Any ideas?

like image 451
mowglis_diaper Avatar asked Sep 19 '17 22:09

mowglis_diaper


People also ask

Does XGBoost use parallel processing?

What is XGBoost architecture? XGBoost stands for Extreme Gradient Boosting. It's a parallelized and carefully optimized version of the gradient boosting algorithm. Parallelizing the whole boosting process hugely improves the training time.

Does XGBoost need DMatrix?

DMatrix is an internal data structure that is used by XGBoost, which is optimized for both memory efficiency and training speed. You can construct DMatrix from multiple different sources of data. Data source of DMatrix.


2 Answers

I installed xgboost yesterday (25.09.2017):

If you install with pip or conda, the xgboost version does not support the n_jobs parameter; only the nthreads parameter.

If you build xgboost from github repository, you can use n_jobs though.

Update: n_jobs is the number of parallel threads used to run xgboost. (replaces nthread) for all algorithms like XGBClassifier, XGBRanker, XGBRegressor etc.

Reference - here

like image 183
stgrmks Avatar answered Nov 14 '22 23:11

stgrmks


nthread is same with n_jobs but n_jobs is prefered for now. maybe you can try nthread instead.

nthread : int Number of parallel threads used to run xgboost. (Deprecated, please use n_jobs)

n_jobs : int Number of parallel threads used to run xgboost. (replaces nthread)

https://github.com/dmlc/xgboost/blob/master/python-package/xgboost/sklearn.py#L71-L74

like image 22
BugKiller Avatar answered Nov 14 '22 23:11

BugKiller