本文主要是介绍PoSH-autosklearn源码分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
论文:(2018ICML)
https://ml.informatik.uni-freiburg.de/papers/18-AUTOML-AutoChallenge.pdf
代码:
http://ml.informatik.uni-freiburg.de/downloads/automl_competition_2018.zip
数据:(codalab平台,需要注册)
https://competitions.codalab.org/competitions/17767#participate-get_data
TODO LIST
- PoSH对时序数据是怎么处理的?
文章目录
- 特别苟的Manual design decisions
- 特征选择
- 少样本数不采用SH
- Budget 的计算
特别苟的Manual design decisions
- 如果特征数>500, 用单变量特征选择(听起来很牛逼,看代码就知道怎么回事了)
- 如果样本数<1000, 不采用SuccessiveHaving。并且采用交叉验证的方式,而不是
HoldOut
在附录A.3
和A.4
有比较详细的需求。
特征选择
特征选择
logic.project_data_via_feature_selection
imp = sklearn.preprocessing.Imputer(strategy='median')
pca = sklearn.feature_selection.SelectKBest(k=n_keep)
pipeline = sklearn.pipeline.Pipeline((('imp', imp), ('pca', pca)))
如果特征数>500, 强行将为500.
lib/logic.py:114
D.feat_type = [ft for i, ft in enumerate(D.feat_type) if rval[2][i] == True]
更新feat_type
少样本数不采用SH
回到logic
lib/logic.py:227
if min_budget == max_budget:res = SSB.run(len(autosklearn_portfolio), min_n_workers=1)else:res = SSB.run(1, min_n_workers=1)
如果样本数<1000, 则设置min_budget = max_budget
, 且不采用SH,强行迭代16次。
Budget 的计算
max_budget = 1.0min_budget = 1.0 / 16eta = 4
eta是什么意思呢?可以回顾我的这篇文章:HpBandSter源码分析
n_iterations
是用户指定的,stages
是根据max_budget
,min_budget
,eta
决定的,详见hpbandster.optimizers.bohb.BOHB#__init__
hpbandster/optimizers/bohb.py:101
self.max_SH_iter = -int(np.log(min_budget/max_budget)/np.log(eta)) + 1
max_budget=243
min_budget=9
eta=3
s m a x = l o g η ( R ) s_{max}=log_{\eta}(R) smax=logη(R)
B = ( S m a x + 1 ) R B=(S_{max}+1)R B=(Smax+1)R
eta
η \eta η 其实是SuccessiveHaving的budget扩增倍数,从9到243,每次增加3倍,即:
9, 27, 81, 243
再看到PoSH的代码
max_budget = 1.0min_budget = 1.0 / 16eta = 4
hp_util.SideShowBOHB
self.max_SH_iter = -int(np.log(min_budget / max_budget) / np.log(eta)) + 1
self.budgets = max_budget * np.power(eta,-np.linspace(self.max_SH_iter - 1,0, self.max_SH_iter))
self.max_SH_iter
Out[5]: 3
self.budgets
Out[6]: array([0.0625, 0.25 , 1. ])
1 16 ⇒ 4 16 ⇒ 16 16 \frac{1}{16} \Rightarrow \frac{4}{16} \Rightarrow \frac{16}{16} 161⇒164⇒1616
lib/hp_util.py:62
self.budget_converter = {'libsvm_svc': lambda b: b,'random_forest': lambda b: int(b*128),'sgd': lambda b: int(b*512),'xgradient_boosting': lambda b: int(b*512),'extra_trees': lambda b: int(b*1024)}
budget与iterations的转换数与论文也是对应的
lib/logic.py:202
worker.run(background=True)
在用线程跑
portfolio.get_hydra_portfolio
获取混合文件夹
balancing
的策略还是存在的
SSB = hp_util.SideShowBOHB(configspace=worker.get_config_space(),initial_configs=autosklearn_portfolio,run_id=run_id,eta=eta, min_budget=min_budget, max_budget=max_budget,SH_only=True, # suppresses Hyperband's outer loop and runs SuccessiveHalving onlynameserver=ns_host,nameserver_port=ns_port,ping_interval=sleep,job_queue_sizes=(-1, 0),dynamic_queue_size=True,)
eta
Out[4]: 4
min_budget
Out[5]: 0.0625
max_budget
Out[6]: 1.0
sleep
Out[7]: 5
run_id
Out[8]: '0'
SideShowBOHB
是Master
, AutoMLWorker
是Worker
。
class PortfolioBOHB(BOHB):""" subclasses the config_generator BOHB"""def __init__(self, initial_configs=None, *args, **kwargs):super().__init__(*args, **kwargs)if initial_configs is None:# dummy initial portfolioself.initial_configs = [self.configspace.sample_configuration().get_dictionary() for i in range(5)]else:self.initial_configs = initial_configs
继承BOHB
,仅仅多个initial_configs
cg = PortfolioBOHB(initial_configs=initial_configs,configspace=configspace,min_points_in_model=min_points_in_model,top_n_percent=top_n_percent,num_samples=num_samples,random_fraction=random_fraction,bandwidth_factor=bandwidth_factor,)
cg
: ConfigGenerate
min_points_in_model
top_n_percent
Out[10]: 15
num_samples
Out[11]: 64
random_fraction
Out[12]: 0.5
bandwidth_factor
Out[13]: 3
min_points_in_model
= None
hp_util.SideShowBOHB#get_next_iteration
iteration
Out[2]: 0
s
Out[3]: 2
n0
Out[4]: 16
ns
Out[5]: [16, 4, 1]
self.budgets[(-s - 1):]
Out[6]: array([0.0625, 0.25 , 1. ])
s
是HyperBand的bracket
,代表stages
数目。
ns
代表配置数,依次递减。budgets
预算数依次递增。
hpbandster.iterations.base.BaseIteration#add_configuration
self.config_sampler
Out[7]: <bound method PortfolioBOHB.get_config of <hp_util.PortfolioBOHB object at 0x7f1670208208>>
hp_util.PortfolioBOHB#get_config
def get_config(self, budget):# return a portfolio member firstif len(self.initial_configs) > 0 and True:c = self.initial_configs.pop()return (c, {'portfolio_member': True})return (super().get_config(budget))
用元学习文件夹代替了随机推荐
最后用SH的方法迭代1000次
这篇关于PoSH-autosklearn源码分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!