梯度提升树(GBDT)原理小结
Posted change_world
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了梯度提升树(GBDT)原理小结相关的知识,希望对你有一定的参考价值。
在集成学习之Adaboost算法原理小结中,我们对Boosting家族的Adaboost算法做了总结,本文就对Boosting家族中另一个重要的算法梯度提升树(Gradient Boosting Decison Tree, 以下简称GBDT)做一个总结。GBDT有很多简称,有GBT(Gradient Boosting Tree), GTB(Gradient Tree Boosting ), GBRT(Gradient Boosting Regression Tree), MART(Multiple Additive Regression Tree),其实都是指的同一种算法,本文统一简称GBDT。GBDT在BAT大厂中也有广泛的应用,假如要选择3个最重要的机器学习算法的话,个人认为GBDT应该占一席之地。
1. GBDT概述
GBDT也是集成学习Boosting家族的成员,但是却和传统的Adaboost有很大的不同。回顾下Adaboost,我们是利用前一轮迭代弱学习器的误差率来更新训练集的权重,这样一轮轮的迭代下去。GBDT也是迭代,使用了前向分布算法,但是弱学习器限定了只能使用CART回归树模型,同时迭代思路和Adaboost也有所不同。
在GBDT的迭代中,假设我们前一轮迭代得到的强学习器是ft−1(x), 损失函数是
L(y,ft−1(x)), 我们本轮迭代的目标是找到一个CART回归树模型的弱学习器
ht(x),让本轮的损失损失
L(y,ft(x)=L(y,ft−1(x)+ht(x))最小。也就是说,本轮迭代找到决策树,要让样本的损失尽量变得更小。
GBDT的思想可以用一个通俗的例子解释,假如有个人30岁,我们首先用20岁去拟合,发现损失有10岁,这时我们用6岁去拟合剩下的损失,发现差距还有4岁,第三轮我们用3岁拟合剩下的差距,差距就只有一岁了。如果我们的迭代轮数还没有完,可以继续迭代下面,每一轮迭代,拟合的岁数误差都会减小。
从上面的例子看这个思想还是蛮简单的,但是有个问题是这个损失的拟合不好度量,损失函数各种各样,怎么找到一种通用的拟合方法呢?
2. GBDT的负梯度拟合
在上一节中,我们介绍了GBDT的基本思路,但是没有解决损失函数拟合方法的问题。针对这个问题,大牛Freidman提出了用损失函数的负梯度来拟合本轮损失的近似值,进而拟合一个CART回归树。第t轮的第i个样本的损失函数的负梯度表示为
![](https://image.cha138.com/20210607/22d23b84790f415d9191d9919f54de38.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/d4ff6fe9428f4f48b946ce7645ae681c.jpg)
![](https://image.cha138.com/20210607/04a6dc25b86542b8a17d47c4863c97ad.jpg)
![](https://image.cha138.com/20210607/8b8c881653d444e3bdd245ba821c93dc.jpg)
![](https://image.cha138.com/20210607/ea961dcf52d54a6d867f2f94eb4ce62d.jpg)
![](https://image.cha138.com/20210607/df40bf8608c84237950bda78c83b8fa4.jpg)
![](https://image.cha138.com/20210607/ab574bb1b5524bfda19f3118d95d693e.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/469d73c201584ef39ad3bff78bf138ad.jpg)
![](https://image.cha138.com/20210607/dbf8b95b29844bc581d41f719265d106.jpg)
![](https://image.cha138.com/20210607/6ee978f200b24da19b2b65b399bba393.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/d4ff6fe9428f4f48b946ce7645ae681c.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/df40bf8608c84237950bda78c83b8fa4.jpg)
![](https://image.cha138.com/20210607/6ee978f200b24da19b2b65b399bba393.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/d4ff6fe9428f4f48b946ce7645ae681c.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/805e2f72f958401f927756b9895d1eb6.jpg)
![](https://image.cha138.com/20210607/74c4fccebf444b7eb0450d8064b0bf59.jpg)
![](https://image.cha138.com/20210607/b1c08f42d7194c13938d14d5fff7fa2b.jpg)
![](https://image.cha138.com/20210607/abb4c1220f1547c7967ca78bed4731ef.jpg)
![](https://image.cha138.com/20210607/315df06d66c74e98b79d125cc8fa4eba.jpg)
![](https://image.cha138.com/20210607/b84d2a4356314361bff146ce9cbe97f2.jpg)
![](https://image.cha138.com/20210607/74c4fccebf444b7eb0450d8064b0bf59.jpg)
![](https://image.cha138.com/20210607/828c21d1d2744537b574fd3fb2949b1e.jpg)
![](https://image.cha138.com/20210607/6e1b8d8116b1414fb2d66438b406050d.jpg)
![](https://image.cha138.com/20210607/d7a8c15c98a64703bb627dfc2dd3bc26.jpg)
![](https://image.cha138.com/20210607/b1c08f42d7194c13938d14d5fff7fa2b.jpg)
![](https://image.cha138.com/20210607/abb4c1220f1547c7967ca78bed4731ef.jpg)
![](https://image.cha138.com/20210607/315df06d66c74e98b79d125cc8fa4eba.jpg)
利用(xi,rti)(i=1,2,..m),我们可以拟合一颗CART回归树,得到了第t颗回归树,其对应的叶节点区域
Rtj,j=1,2,...,J。其中J为叶子节点的个数。
针对每一个叶子节点里的样本,我们求出使损失函数最小,也就是拟合叶子节点最好的的输出值ctj如下:
![](https://image.cha138.com/20210607/1e38979d34e64ce0ad0ee048212e5904.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/04a6dc25b86542b8a17d47c4863c97ad.jpg)
![](https://image.cha138.com/20210607/ddd6ec1c8830432e8cf35f99bcaa06ee.jpg)
![](https://image.cha138.com/20210607/22d23b84790f415d9191d9919f54de38.jpg)
![](https://image.cha138.com/20210607/473b7bdef5f04728b4b832f482f059f1.jpg)
![](https://image.cha138.com/20210607/e803efc9c02f4e8f8a47c0f178152992.jpg)
![](https://image.cha138.com/20210607/427fc436bc8a469fb50fa31d351897a5.jpg)
![](https://image.cha138.com/20210607/a944ae13b558484f829a9519a03e2340.jpg)
![](https://image.cha138.com/20210607/b442801d179943ce9fe1ceb209d17ce4.jpg)
![](https://image.cha138.com/20210607/5009c52916f6488081edf15701f220ee.jpg)
![](https://image.cha138.com/20210607/d69395c961c84ac181ce6a88cc949de1.jpg)
![](https://image.cha138.com/20210607/a2fa663f4c6146589020950fb06a9b26.jpg)
![](https://image.cha138.com/20210607/57de151813c24ef4a2baf5cd690bc30c.jpg)
![](https://image.cha138.com/20210607/57de151813c24ef4a2baf5cd690bc30c.jpg)
![](https://image.cha138.com/20210607/57de151813c24ef4a2baf5cd690bc30c.jpg)
![](https://image.cha138.com/20210607/57de151813c24ef4a2baf5cd690bc30c.jpg)
![](https://image.cha138.com/20210607/57de151813c24ef4a2baf5cd690bc30c.jpg)
![](https://image.cha138.com/20210607/57de151813c24ef4a2baf5cd690bc30c.jpg)
![](https://image.cha138.com/20210607/cabddfe3f68c4813b5ce329c6f7f35c7.jpg)
![](https://image.cha138.com/20210607/0a6b7c8a660f4bcfa127853501762cfb.jpg)
![](https://image.cha138.com/20210607/abb4c1220f1547c7967ca78bed4731ef.jpg)
![](https://image.cha138.com/20210607/e05bea51e3254f5aa37a8fc9eaeb8896.jpg)
![](https://image.cha138.com/20210607/cf911c6c210f4ab2be056213aacbd7d9.jpg)
![](https://image.cha138.com/20210607/4d3098e421944a1cacb5219f4ddc3e95.jpg)
![](https://image.cha138.com/20210607/828c21d1d2744537b574fd3fb2949b1e.jpg)
![](https://image.cha138.com/20210607/87238ce698c14c70815a81e9c3d28833.jpg)
![](https://image.cha138.com/20210607/ab574bb1b5524bfda19f3118d95d693e.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/469d73c201584ef39ad3bff78bf138ad.jpg)
![](https://image.cha138.com/20210607/d4ff6fe9428f4f48b946ce7645ae681c.jpg)
![](https://image.cha138.com/20210607/dbf8b95b29844bc581d41f719265d106.jpg)
![](https://image.cha138.com/20210607/6ee978f200b24da19b2b65b399bba393.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/45fd7199ce8a4177a6f74e7d7f370699.jpg)
![](https://image.cha138.com/20210607/4f71dffe252b4d869500a8baf5520cad.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/d4ff6fe9428f4f48b946ce7645ae681c.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/3dcca1512ceb4ace946cb54723c21952.jpg)
![](https://image.cha138.com/20210607/1e38979d34e64ce0ad0ee048212e5904.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
这样我们就得到了本轮的决策树拟合函数如下:
![](https://image.cha138.com/20210607/0a9435420dd84515921a8aa776740f04.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/04a6dc25b86542b8a17d47c4863c97ad.jpg)
![](https://image.cha138.com/20210607/0a6b7c8a660f4bcfa127853501762cfb.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/b84d2a4356314361bff146ce9cbe97f2.jpg)
![](https://image.cha138.com/20210607/4f71dffe252b4d869500a8baf5520cad.jpg)
![](https://image.cha138.com/20210607/e35b0bd106354ab786e71d19d1ef6614.jpg)
![](https://image.cha138.com/20210607/1e38979d34e64ce0ad0ee048212e5904.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/adc3187bc4904b4a90fe0226e144bc97.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/1fb8e136bdc246ba8021ff57a9edc009.jpg)
![](https://image.cha138.com/20210607/87fd6c565a004fc09c391ec3c1d1b705.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
从而本轮最终得到的强学习器的表达式如下:
![](https://image.cha138.com/20210607/6ee978f200b24da19b2b65b399bba393.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/04a6dc25b86542b8a17d47c4863c97ad.jpg)
![](https://image.cha138.com/20210607/6ee978f200b24da19b2b65b399bba393.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/45fd7199ce8a4177a6f74e7d7f370699.jpg)
![](https://image.cha138.com/20210607/4f71dffe252b4d869500a8baf5520cad.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/3dcca1512ceb4ace946cb54723c21952.jpg)
![](https://image.cha138.com/20210607/0a6b7c8a660f4bcfa127853501762cfb.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/b84d2a4356314361bff146ce9cbe97f2.jpg)
![](https://image.cha138.com/20210607/4f71dffe252b4d869500a8baf5520cad.jpg)
![](https://image.cha138.com/20210607/e35b0bd106354ab786e71d19d1ef6614.jpg)
![](https://image.cha138.com/20210607/1e38979d34e64ce0ad0ee048212e5904.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/adc3187bc4904b4a90fe0226e144bc97.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/1fb8e136bdc246ba8021ff57a9edc009.jpg)
![](https://image.cha138.com/20210607/87fd6c565a004fc09c391ec3c1d1b705.jpg)
![](https://image.cha138.com/20210607/09c2fdf7676948ed81287cf2368b9932.jpg)
![](https://image.cha138.com/20210607/7f7b81f10d5e4e668617b357c6c4d028.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
通过损失函数的负梯度来拟合,我们找到了一种通用的拟合损失误差的办法,这样无轮是分类问题还是回归问题,我们通过其损失函数的负梯度的拟合,就可以用GBDT来解决我们的分类回归问题。区别仅仅在于损失函数不同导致的负梯度不同而已。
3. GBDT回归算法
好了,有了上面的思路,下面我们总结下GBDT的回归算法。为什么没有加上分类算法一起?那是因为分类算法的输出是不连续的类别值,需要一些处理才能使用负梯度,我们在下一节讲。
输入是训练集样本T={(x,y1),(x2,y2),...(xm,ym)}, 最大迭代次数T, 损失函数L。
输出是强学习器f(x)
1) 初始化弱学习器
![](https://image.cha138.com/20210607/6ee978f200b24da19b2b65b399bba393.jpg)
![](https://image.cha138.com/20210607/0ff3cb338cdc46ed88dda2630aac54a3.jpg)
![](https://image.cha138.com/20210607/d622ceb8a72f41b08a05664756c1ff36.jpg)
![](https://image.cha138.com/20210607/5d1628ce16d64824bcc381e0dc136ea5.jpg)
![](https://image.cha138.com/20210607/14eee327e0d54491ae2335cda44802d3.jpg)
![](https://image.cha138.com/20210607/04a6dc25b86542b8a17d47c4863c97ad.jpg)
![](https://image.cha138.com/20210607/ddd6ec1c8830432e8cf35f99bcaa06ee.jpg)