1. AdaBoost算法简介

AdaBoost (Adaptive Boosting)并不是一种全新的机器学习算法,而是一种提升(boosting)方法或者集成学习。其主要思想是:对于复杂的任务来说,将多个分类器的结果进行综合,从而得出更为精确地结果。

2. AdaBoost模型

AdaBoost模型包括弱分类器、权重更新和分类规则,下面分别介绍

2.1 弱分类器

AdaBoost是将多个弱分类器通过一定的策略进行组合,从而得到一个强分类器的过程,如图所示。 在一轮迭代过程中,被弱分类器分错的样本权值会变大,这样在下一次迭代过程中这些样本会被弱分类器“特殊关照”,如此反复,将多个弱分类器组合在一起就可以得到一个强分类器。

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

2.2 权值更新

AdaDoost学习过程中,有两个权重,一个是所有训练集从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost) 中的每个样本对应的权重 从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost) 和每个弱分类器对应的权重 从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost) 。初始时

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost) 分别为训练集中的数目和弱分类器的数目。

AdaBoost在每次迭代过程中训练一个弱分类器 从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost) ,该分类器在训练数据集上的误差为:

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

根据误差更新弱分类器的权重

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

根据误差更新每个样本的权重

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

AdaBoost训练代码如下,采用列表来存储分类器和其权重,每次更新在列表中添加一个(权重,弱分类器)元组。

    def train(self, train_data, train_label):
        if self.norm_type == "Standardization":
            train_data = preProcess.Standardization(train_data)
        else:
            train_data = preProcess.Normalization(train_data)

        train_label = np.expand_dims(train_label, axis=1)
        sample_num = len(train_data)

        weak_classifier = []

        # initialize weights
        w = np.ones([sample_num, 1])
        w = w/sample_num

        # predictions
        agg_predicts = np.zeros([sample_num, 1]) # aggregate value of prediction

        # start train
        for i in range(self.iterations):
            base_clf, error, base_prediction = self.baseClassifier(train_data, train_label, w)
            alpha = self.updateAlpha(error)
            weak_classifier.append((alpha, base_clf))

            # update parameters in page of 139 Eq.(8.4)
            expon = np.multiply(-1 * alpha * train_label, base_prediction)
            w = np.multiply(w, np.exp(expon))
            w = w/w.sum()

            # calculate the total error rate
            agg_predicts += alpha*base_prediction
            error_rate = np.multiply(np.sign(agg_predicts) != train_label, np.ones([sample_num, 1]))
            error_rate = error_rate.sum()/sample_num

            if error_rate == 0:
                break
            self.classifier_set = weak_classifier
        return weak_classifier

2.3 分类规则

迭代完毕后,将所有的弱分类器组合成一个强分类器

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

3. 总结与分析

AdaBoost模型可以视为加法模型+指数损失函数+前向分布算法。在AdaBoost中,弱分类器可以不一样,本文的弱分类器全部以SVM为例。最后看一下AdaBoost的提升效果,这里与从零实现机器学习算法(五)支持向量机 实现的SVM算法进行比较,其结果如下

从零实现机器学习算法(六)自适应提升(Adaptive Boosting, AdaBoost)

 

本文使用了五个弱分类器,可以看到运行时间大约是5个SVM的时间,效果就提升了5%,还是不错的。

本文相关代码和数据集:

DandelionLau/MachineLearning​github.com

参考文献:

[1] 李航, 统计学习方法

[2] Peter Harrington, Machine Learning IN ACTION

相关文章:

  • 2022-01-15
  • 2022-12-23
  • 2021-04-13
  • 2022-12-23
  • 2021-07-05
  • 2021-12-13
  • 2021-12-18
猜你喜欢
  • 2021-10-19
  • 2021-11-22
  • 2021-12-03
  • 2021-05-14
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案