以下是Coursera上的How to Win a Data Science Competition: Learn from Top Kagglers课程笔记。
Hyperparameter Optimization
- List most important hyperparameters in major models; describe their impact
- Understand the hyperparameter tuning process in general
- Arrange hyperparameters by their importance
Hyperparameter tuning I
Plan for the lecture
- Hyperparameter tuning in general
- General pipeline
- Manual and automatic tuning
- What should we understand about hyperparameters?
- Models,libraries and hyperparameter optimization
- Tree-based models
- Neural networks
- Linear models
Plan for the lecture:models
- Tree-based models
- GBDT: XGBoost, LightGBM, CatBoost
- RandomForest/ExtraTrees
- Neural nets
- Pytorch, Tensorflow, Keras...
- Linear models
- SVM, logistic regression
- Vowpal Wabbit, FTRL
- Factorization Machines(out of scope)
- libFM, libFFM
How do we tune hyperparameters
Hyperparameter optimization software自动调参工具
运行调参工具可能需要很长时间,因此最好的策略是在夜间运行它。
- A lot of libraries to try:
- Hyperopt
- Scikit-optimize
- Spearmint
- GPyOpt
- RoBO
- SMAC3
从广义上讲,不同的参数会导致三种不同的结果
- 1.Underfitting(bad)
- 2.Good fit and generalization(good)
- 3.Overfitting(bad)
因此我们需要把想要调整的参数分为两组。第一组是约束模型的参数,第二组与第一组效果相反。
- A parameter in red
- Increasing it impedes fitting
- Increase it to reduce overfitting
- Decrease to allow model fit easier
- A parameter in green
- Increasing it leads to a batter fit(overfit) on train set
- Increase it, if model underfits
- Decrease if overfits
上面提到的颜色只是视频中的标记
Hyperparameter tuning II
一些基于树模型的超参数优化
GBDT
max_depth |
max_depth/num_leaves |
subsample |
bagging_fraction |
colsample_bytree, colsample_bylevel |
frature_fraction |
min_child_weight,
lambda,alpha |
min_data_in_leaf,
lambda_l1,lambda_l2 |
eta num_round |
learning_rate num_iterations |
Others: seed |
Others: *_seed |
- max_depth:
树越深,越能拟合数据集,但这可以会导致过拟合。根据任务的不同,最大深度可能会有很大差异,有时是2,有时是27。建议max_depth大约从7开始,直到未过拟合的最大深度。需要注意的是深度增加,学习时间就更长。
- num_leaves:
在LightGBM中,可以控制叶的数量,而不是最大深度。因为树可以很深,但如果叶子数量少就不会导致过拟合。
- subsample、bagging_fraction:
这个参数可以控制每次喂给模型的数据量,取值在0,1之间。每次喂给它一小部分数据,可以让它不那么过拟合,并且可以得到更好的泛化效果,但是模型的训练会更慢。这有点像正则化的作用。
- colsample_bytree、colsample_bylevel:
这个参数可以控制subsample中的分裂点。如果模型过拟合,可以尝试降低这些值。
- min_child_weight,lambda,alpha:
正则化参数。
- min_child_weight:
经验中,这是最重要的参数。增加它可以让模型更保守,减少它会让模型有更少约束。根据不同的任务,我发现最佳值为0,5,15,300,所以不要犹豫,尝试各种值,这取决于数据。
- eta、num_round:eta本质上是一种学习权重,就像梯度下降一样。num_round是我们想要执行的学习步数,换句话说,是我们想要建多少棵树。每次迭代都会构建一个新树,以学习率eta添加到模型中。
- 当我们找到合适的轮数时,可以做一个通常会提高分数的技巧。我们将num_round乘以α,将eta除以α,模型通常会变得更好。可能应用的参数也需要调整,但通常可以保留原样。
Other
- seed:
一般情况下随机种子对于模型影响不大。但如果随机种子对你的影响非常大时,建议你可以多次提交,或者根据随机性调整你的验证方案。
sklearn.RandomForest/ExtraTrees
- n_estimators:
RandomForest构建每棵树是独立于其他树的,这意味这拥有大量树的模型不会导致过拟合,这于Gradient Boosting相反。我们通常首先将n_estimators设置为非常小的数字,例如10,并看看这将花费多少时间,如果不太长,就把它设为一个比较大的值,例如300。
- max_deep:
控制树的深度,于XGBoost不同,它可以被设置为None,这对应于无限深度。当数据集中的特征具有重复值和重要交互时,它实际上非常有用。在其他情况下,无约束深度的模型将立即过拟合。建议随机森林的深度从7左右开始。通常随机深林的最佳深度高于Gradient Boosting,所有不要犹豫尝试10,20或更高的值。
- max_feature:
与XGBoost中的参数相同。
- min_samples_leaf:
是一个类似正则化的参数,与XGBoost的min_child_weight和LightGBM的min_data_leaf相同。
Other
- criterion:
根据我的经验,Gini更常见,但有时Entropy更好。
- random_state:
随机种子参数
- n_jobs:设置拥有多个核心数。默认情况下sklearn的RandomForest由于某种原因仅使用一个核心。
Hyperparameter tuning III
- Neural nets
- Pytorch, Tensorflow, Keras...
- Linear models
- SVM, logistic regression
- Vowpal Wabbit, FTRL
Neural Nets
这里讨论的是dense neural nets,即只含有全连接层的网络
自适应算法已高亮+斜体显示
Linear models
Linear models
Tips
相关链接
高级调参技巧
原文:https://www.cnblogs.com/ishero/p/11136374.html