用于HpBandSter超参数搜索的scikitlearn包装器
hpbandster-sklearn的Python项目详细描述
hpbandster学习
hpbandster-sklearn
是一个Python库,为^{HpBandSterSearchCV
-一个超参数调整库。在
动机
HpBandSter
实现了几种前沿的超参数算法,包括hyband和BOHB。它们的性能往往优于标准随机搜索,在更短的时间内找到最佳参数组合。在
HpBandSter
功能强大且可配置,但对于初学者来说,它的用法通常不直观,需要大量的样板代码。为了解决这个问题,HpBandSterSearchCV
被创建为scikit-learn
超参数搜索器的一个替代品,它遵循其众所周知和流行的API,使得可以用最小的设置来优化scikit-learn
API估计器。在
HpBandSterSearchCV
API基于scikit-learn
的^{
安装
pip install hpbandster-sklearn
使用
像其他任何scikit-learn
超参数搜索器一样使用它:
您也可以使用ConfigSpace.ConfigurationSpace
对象来代替dict(事实上,这是推荐的)!在
importnumpyasnpfromsklearn.datasetsimportload_irisfromsklearn.ensembleimportRandomForestClassifierfromsklearn.utils.validationimportcheck_is_fittedfromhpbandster_sklearnimportHpBandSterSearchCVimportConfigSpaceasCSimportConfigSpace.hyperparametersasCSHX,y=load_iris(return_X_y=True)clf=RandomForestClassifier(random_state=0)np.random.seed(0)param_distributions=CS.ConfigurationSpace(seed=42)param_distributions.add_hyperparameter(CSH.UniformIntegerHyperparameter("min_samples_split",2,11))param_distributions.add_hyperparameter(CSH.UniformIntegerHyperparameter("max_depth",2,4))search=HpBandSterSearchCV(clf,param_distributions,random_state=0,n_jobs=1,n_iter=10,verbose=1).fit(X,y)search.best_params_
有关详细信息,请参阅documentation of this library,以及^{
还支持管道和TransformedTargetRegressor
。如果您使用其中一个(或两个都使用),请确保相应地为超参数和资源名称加前缀-例如,final_estimator__n_estimators
。n_samples
不加前缀。在
提前停车
由于HpBandSter
中的几乎每个搜索算法都利用了早期停止(主要是通过连续的减半),用户可以通过HpBandSterSearchCV
对象的参数配置要使用的资源和预算。在
search=HpBandSterSearchCV(clf,param_distributions,resource_name='n_samples',# can be either 'n_samples' or a string corresponding to an estimator attribute, eg. 'n_estimators' for an ensembleresource_type=float,# if specified, the resource value will be cast to that type before being passed to the estimator, otherwise it will be derived automaticallymin_budget=0.2,max_budget=1,)search=HpBandSterSearchCV(clf,param_distributions,resource_name='n_estimators',# can be either 'n_samples' or a string corresponding to an estimator attribute, eg. 'n_estimators' for an ensembleresource_type=int,# if specified, the resource value will be cast to that type before being passed to the estimator, otherwise it will be derived automaticallymin_budget=20,max_budget=200,)
默认情况下,对象将尝试通过按顺序检查以下内容来自动确定最佳资源:
'n_estimators'
,如果模型具有该属性和warm_start
属性'max_iter'
,如果模型具有该属性和warm_start
属性'n_samples'
-如果模型不支持warm_start
,数据集样本将被用作资源,测量模型将迭代地拟合到越来越大的数据集部分上。在
此外,还添加了对LightGBM
、XGBoost
和{scikit-learn
估计量的特殊支持。在
文件
https://hpbandster-sklearn.readthedocs.io/en/latest/
参考文献
HpBandSter
-https://github.com/automl/HpBandSterConfigSpace
-https://github.com/automl/ConfigSpacescikit-learn
-http://scikit-learn.org/
作者
安东尼鲍姆(Yard1)
许可证
- 项目
标签: