python-3.x - 如何在嵌套的 sklearn 对象中优化 n_jobs 的使用?
问题描述
我正在使用带有 xgboost 和其他几个分类器的 StackingClassifier 运行一个集成模型,并希望利用始终可用的最多内核数(在我的情况下为 96 个)。
如果我必须选择,似乎并行化的最佳位置将在分类器本身内而不是在 StackingClassifier 中,因为它只需要运行交叉验证而不是树构建,但是即使在 StackingClassifier、随机森林中设置 n_jobs=1使用所有内核,但 xgboost 不使用多个内核。如何配置它以使 xgboost 使用所有可用内核?
rfc = RandomForestClassifier(
n_estimators=1000,
max_depth=None,
max_features = 0.2,
bootstrap=True,
random_state=0,
verbose=2,
n_jobs=-1
)
xgb = XGBClassifier(
n_estimators=1000,
max_depth=24,
max_features=0.2,
bootstrap=True,
objective="multi:softprob",
num_class=2,
colsample_bytree=0.3,
gamma=1,
learning_rate=0.01,
subsample=0.9,
random_state=0,
verbosity=2,
nthread=-1,
n_jobs=-1)
estimators = [
('rfc', rfc)
]
stacker = StackingClassifier(
estimators=estimators,
final_estimator=xgb,
stack_method="predict_proba",
verbose=2,
cv=2,
n_jobs=1,
passthrough=True)
calibrator = CalibratedClassifierCV(
base_estimator = stacker,
method="sigmoid",
cv=2)
解决方案
推荐阅读
- typescript - Vue 3 迁移如何扩展组件?
- r - Quanteda:我如何创建语料库和情节分散的单词?
- typescript - 如何在打字稿中将字符串 [对象对象] 转换为自定义类型?
- c++ - 使用 eigen 进行尾调用优化
- java - 使用 Jmeter 对 Keycloak 进行压力测试导致 100% 的 CPU 使用率
- javascript - 将 JavaScript 数组发送到 webhook
- git - Jenkins通过分支合并在重新出现的分支上触发构建
- reactjs - React formik - 如何在 setValues 之后运行函数
- r - 在 r 中,如何控制组合图中 (plot_grid) 中图与 x 轴的比例?
- git - 我的全栈应用程序文件没有上传到 GitHub,git add 挂了?