【问题标题】:Parallel threading with xgboost?使用 xgboost 并行线程?
【发布时间】:2018-02-28 20:05:56
【问题描述】:

根据其文档,xgboost 有一个 n_jobs 参数。但是,当我尝试设置 n_jobs 时,出现此错误:

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

对于一些其他参数(如 random_state)也存在同样的问题。我认为这可能是一个更新问题,但似乎我有最新版本(0.6a2,安装了 pip)。

我不需要太多就可以重现错误:

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

有什么想法吗?

【问题讨论】:

  • 您能添加一个Minimal, Complete, and Verifiable 示例吗?
  • 已添加。这就是我得到错误所需要的全部
  • 我重现了这个问题,所以你的安装并不奇怪。这似乎是xgboost 中的一个错误,尽管我无法弄清楚这是如何发生的(n_jobs 是 XGBClassifier 的一个明确的 kwarg)。尝试在 Github 上打开问题?
  • 已提交,感谢帮助
  • 你是如何检查版本的?您是否在相同的环境中运行代码?

标签: python machine-learning xgboost


【解决方案1】:

我昨天(2017 年 9 月 25 日)安装了 xgboost:

如果使用 pip 或 conda 安装,xgboost 版本不支持 n_jobs 参数;只有 nthreads 参数。

如果您从 github 存储库构建 xgboost,则可以使用 n_jobs。

更新:n_jobs 是用于运行 xgboost 的并行线程数。 (替换 nthread)适用于所有算法,如 XGBClassifier、XGBRanker、XGBRegressor 等。

参考 - here

【讨论】:

  • 至于 2018-01-18,n_jobspip (xgboost v0.7) 一起安装时存在。
【解决方案2】:

nthreadn_jobs 相同,但目前首选 n_jobs。 也许你可以试试nthread

nthread : 整数 用于运行 xgboost 的并行线程数。 (已弃用,请使用 n_jobs)

n_jobs : 整数 用于运行 xgboost 的并行线程数。 (替换 nthread)

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

【讨论】:

    【解决方案3】:

    将此用于您机器的 n_jobs 值

    import multiprocessing
    n_jobs = multiprocessing.cpu_count()-1
    print(n_jobs)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-11
      • 2017-01-24
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      相关资源
      最近更新 更多