def clean_params_for_sk(params: dict) -> dict:
"""
Given a dictionary of XGB parameters, return a copy without parameters that will cause issues with scikit-learn's grid or
randomized search estimators.
:param params:
A dictionary of XGB parameters.
:return:
A copy of the same dictionary without the aforementioned problematic parameters.
"""
# In the xgb.cv call, nthread should be equal to the CPU count, but this causes a hang when
# called through GridSearchCV - parallelism should be achieved through its n_jobs parameter.
# See https://github.com/scikit-learn/scikit-learn/issues/6627 for more details.
params_copy = params.copy()
params_copy['nthread'] = 1
# In multiclass problems, this parameter is required for XGBoost, but is not a parameter of interest to be tuned.
if 'num_class' in params_copy.keys():
del params_copy['num_class']
return params_copy
评论列表
文章目录