【问题标题】:Is there any downside in using multiple "n_jobs=-1" statements?使用多个 \"n_jobs=-1\" 语句有什么缺点吗?
【发布时间】:2023-02-03 20:15:39
【问题描述】:

在分类问题的模型选择上下文中,在运行交叉验证时,是否可以在模型规范和交叉验证函数中指定 n_jobs=-1 以充分利用机器的功能?

例如,比较 sklearn RandomForestClassifier 和 xgboost XGBClassifier:

RF_model = RandomForestClassifier( ..., n_jobs=-1)
XGB_model = XGBClassifier( ..., n_jobs=-1)

RF_cv = cross_validate(RF_model, ..., n_jobs=-1)
XGB_cv = cross_validate(XGB_model, ..., n_jobs=-1)

可以在两者中指定参数吗?还是我应该只指定一次?在其中的哪一个中,模型或交叉验证语句?

我使用来自两个不同库(sklearn 和 xgboost)的示例模型,因为它的工作方式可能有所不同,cross_validate 函数也来自 sklearn。

【问题讨论】:

    标签: python performance scikit-learn parallel-processing cross-validation


    【解决方案1】:

    每个类都使用所有可用内核运行。

    通过设置n_jobs=-1,您要求并行使用最大数量的 CPU 内核来训练和评估模型。这可以加快训练和评估过程,尤其是在您拥有大型数据集的情况下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 2011-04-26
      • 2011-02-28
      相关资源
      最近更新 更多