Ensemble Learning

“Two heads are better than one.”

🌱第二版修订(2021.4.28)🌱

1. Introduction to ensemble learning

requirement: 

每个弱分类器需要good and different

使用ensemble learning的理由:

reason 1:

If the training examples are few and the hypothesis space is large then there are several equally accurate classifiers. Selecting one of them may lead to bad result on the test set

reason 2:

Algorithms may converge to local minima. Combining different hypotheses may lower the risk of bad local minimum

reason 3:

Hypothesis space determined by the current algorithm does not contain the true function, but it has several good approximations.

 

Weighted Majority Algorithm (加权多数算法)

对每个若判别器的输出结果加一个权重,最后的输出结果是所有判别器结果的加权平均。

 

Bagging

If we have only one weak learner, how to improve the performance by ensemble?

1. Intuition

  • Training on different data would yield a different base model
  • A naïve approach: sample different subsets from the training set and train different base models
    • These models should be quite different
    • But their performances may be very bad
  • Solution: Bootstrap sampling (Bagging)

2. Bootstrap Sampling (拔靴法采样)

3. Bagging Algorithm

4. Bagging: result

 ====

(e_S 是决策树/KNN的结果,e_B是决策树/KNN经过bagging的结果) 

bagging可以显著提升决策树的效果,但是不能提升KNN的效果的原因是:

  • Bagging helps when learner is unstable -- “The vital element is the instability of the prediction method”
    • E.g. Decision tree, neural network
  • Unstable: small change in training set cause large change in hypothesis produced  -- “If perturbing the learning set can cause significant changes in the predictor constructed, then bagging can improve accuracy.” (Breiman 1996)

 

Boosting

“Learn from failures”

Basic idea:

  • Assign a weight to each example
  • T iterations, increase weights of misclassified examples after each iteration – focus more on “hard” ones

1. Adaboost

1.2 AdaBoost.M1

 

1.3 Adaboost Example

                              (a)     每个点都有相同的权重

            (b)用一个简单的线性分类器分类,右侧的三个正例

                     分类错误,所以提高它们的权重

        (c)提高权重之后,线性分类器发生了变化,现在左侧的三个负例分类

            错误了,所以再提高它们的权重

     (d)现在的线性分类器又发生了变化

(e)最终的分类器是之前若干次分类器的加权平均,形成了一个更复杂的分类器

 

1.4 AdaBoost caveats

AdaBoost can fail if

  • Weak hypothesis too complex (overfitting)
  • Weak hypothesis too weak (\alpha _t->0 too quickly)

1.5 Reweighting vs. Resampling

Example weights might be harder to deal with:

Some learning methods can’t use weights on examples

Many common packages don’t support weighs on the train

We can resample instead:

Draw a bootstrap sample from the data with the probability of drawing each example is proportional to it’s weight

Reweighting usually works better but resampling is easier to implement

 


🦪集成学习常见面试题

 

1. 集成学习的算法有哪几类,简述其主要思想

(1) Bagging 的全称是 Bootstrap Aggregating,Bagging 采用有放回的采样。通过采样得到多个数据集,并在每个数据集上训练一个基分类器,然后将各分类器的结果结合起来得到最终预测结果(一般分类采取简单投票,回归采取简单平均)。

(2) Boosting 也就是所谓的提升方法,多数提升方法是首先改变训练数据的概率分布(或者权值),针对不同的训练数据分布调用弱学习算法学习多个弱分类器,然后采用加权多数表决(即加大误差小的弱分类器的权值,减小误差大的弱分类器的权值)的方法将各弱学习器结合在一起。

(3) Stacking是将不同模型的训练结果作为另一个模型的输入,然后得到最终的结果。也就是说,在此类算法中的学习算法可以分为两类,一类是以原数据为输入训练弱学习器的算法,另一类学习算法是以弱学习的输出为输入训练元学习器的算法,元学习器学习的其实是各个弱学习器的结合策略。

 

2. 集成学习可以带来哪些好处?

3. Bagging 和 Boosting 优缺点及两者比较?

(1)Bagging

优点:

  • 由于每个基学习器只用初始训练集中约 63.2% 的样本来训练,剩下的约 36.8% 的样本可用作验证集来对泛化性能进行包外 (Out-Of-Bag) 估计。
  • 有放回采样得到的训练集之间是相互独立的,这就使得个体学习器尽可能相互独立。
  • 各个基学习器的训练过程独立,因此可以并行化。

(2)Boosting

  • 由于各个基学习器的训练是序列化进行的,且后一个基学习器重点关注前一个基学习器上表现不好的样本,因此产生的各个基学习器相对互补,因此可以减少偏差。

(3)两者比较

         样本选择:

  • Bagging:训练集是有放回选取的,从原始集中选出的各轮训练集之间是独立的。
  • Boosting:每一轮的训练集不变,只是训练集中每个样例在分类器中的权重发生变化。而权值是根据上一轮的分类结果进行调整

        样例权重:

  • Bagging:使用均匀取样,每个样例的权重相等
  • Boosting:根据错误率不断调整样例的权值,错误率越大则权重越大

       预测函数:

  • Bagging:所有预测函数的权重相等。
  • Boosting:每个弱分类器都有相应的权重,对于分类误差小的分类器会有更大的权重

      并行计算:

  • Bagging:各个预测函数可以并行生成
  • Boosting:各个预测函数只能顺序生成,因为后一个模型参数需要前一轮模型的结果

       优化部分:

  • Bagging:主要减小模型的方差(Variance)。Bagging 就是在几乎不改变模型准确性的前提下尽可能减小模型的方差。因此 Bagging 中的基模型一定要为强模型,否则就会导致整体模型的偏差大,即准确度低
  • Boosting:主要减小模型的偏差(Bias)。Boosting 就是在几乎不改变模型方差的前提下减小模型的偏差。故 Boosting 中的基模型一定要为弱模型,否则就会导致整体模型的方差大(强模型容易过拟合,导致方差过大)

4. 简要介绍 Stacking 算法

Stacking 算法指训练一个元模型用于组合各个基模型。具体来说就是将训练好的各个基模型的输出作为元模型的输入来训练一个元模型,这样就能得到一个最终的输出。

具体的过程如下:
1.划分训练数据集为两个不相交的集合。
2. 在第一个集合上训练多个学习器。
3. 在第二个集合上测试这几个学习器
4. 把第三步得到的预测结果作为输入,把正确的回应作为输出,训练一个高层学习器(元模型)。

按照k折交叉验证的方法(例如k=5),对于model1,每次都在4/5的数据上训练,预测那1/5的数据,这样训练5个model1,最后把它们的输出拼起来,这就是一个完整测试集上的输出了。这样同样训练model2、model3、...model10,得到10个完整测试集输出(10列)。将这10列作为特征,真实标签作为label,来训练元模型(stacking 模型)。我的理解:Stacking相当于一种订正,把原始模型的输出继续订正,就像后处理一样。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值