mattshma/bigdata

AttributeError: 'XGBClassifier' object has no attribute 'n_jobs'

mattshma opened this issue · 0 comments

xgboost 执行时报错如下:

/usr/local/lib/python2.7/dist-packages/xgboost-0.72-py2.7.egg/xgboost/sklearn.pyc in apply(self, X, ntree_limit)
    339             ``[0; 2**(self.max_depth+1))``, possibly with gaps in the numbering.
    340         """
--> 341         test_dmatrix = DMatrix(X, missing=self.missing, nthread=self.n_jobs)
    342         return self.get_booster().predict(test_dmatrix,
    343                                           pred_leaf=True,

AttributeError: 'XGBClassifier' object has no attribute 'n_jobs'

一般而言出现这个问题是由于训练的 xgboost 和运行模型的 xgboost 不是一个版本导致的。

可以看到是 sklearn.py 这里出了问题,查看 xgboost 源文件中 python-package/xgboost/sklearn.py。确实是有 n_jobs

重新编译运行环境的 xgboost。再次运行,问题解决。