ML | XGBoost系统原理&论文要点整理

本文中【】内的内容是自己的理解,可能有问题;
论文中还有一些未解决的问题,以后明白了再补上。

笔记比较粗略,详细内容参考原论文——XGBoost: A Scalable Tree Boosting System


1. 从损失函数到分裂评价准则

1.1 Boosting Tree的数学表达式

在这里插入图片描述意思是很多颗树(函数)顺序生成,构成总的函数;


1.2 总函数的损失函数

在这里插入图片描述这里的正则项,是论文的一个创新点,借鉴了RGF但是更简单的正则项【原论文2.1节】;

1.3 怎样计算一棵树——怎样进行节点分裂

损失函数:
在这里插入图片描述多项式近似:
在这里插入图片描述去掉常数项:
在这里插入图片描述下标按照叶子节点,损失函数的形式重写为:
在这里插入图片描述上式可以看做叶子权重 w[j]的一元二次多项式,可以得到:

最优时的叶子权重:
在这里插入图片描述最优时的损失函数值:

在这里插入图片描述
可以得到,一个节点分裂为两个节点时候,损失函数的减少值(1个节点损失函数值减去分裂为2个节点的损失函数值):

在这里插入图片描述
这个值可以用来选取分裂方式(分裂节点)——选取使这个值最大的那种分裂方式。


2. 防止过拟合:Shrinkage & Column Subsampling

除了防止过拟合的正则项,还用了两种方法防止过拟合

2.1 Shrinkage

所谓shrinkage就是,每一棵新的树乘以一个系数 η 。我理解的就是在1.3的损失函数中的 f_t(x)前面乘以一个η。

2.2 Column Subsampling

这个好理解,跟随机森林一样,随机选取一部分feature来构造新树。

选取部分列除了防止过拟合,还会提高训练速度。


3. 树的生成算法(分裂算法)

3.1 Basic Exact Greedy Algorithm

简言之,就是挨个尝试所有的分裂方式,选取得分最高(损失函数减少最多)的那种:

在这里插入图片描述

3.2 Approximate Algorithm

近似算法用 ‘分位数分成的小组’ 来代替 ‘所有的feature的遍历’,从而减少计算时间;近似算法的框架如下【之所以叫框架,是因为其中的 Proposal可以有很多种】:

在这里插入图片描述

说明1】只要分位数数目选的得当,准确率可以和穷举算法相近;
说明2】所有版本的xgboost都支持高效的近似算法;单机版的xgboost支持高效的穷举算法(原文3.2最后一段,言外之意是——分布式的xgboost不高效支持穷举算法?)

3.3 Weighted Quantile Sketch

3.3.1 此技术的动机

【3.2的算法中有一个问题,就是 分位数的选取问题。如果数据量小的话,很容易就可以得到分位数;如果数据量太大的话,如果对原数据进行排序,然后再选择分位数,这是开销很大的,所以需要一种更高效的选取分位数的方法】

3.3.2 Weighted Quantile的含义

前面的几个地方已经提到了,近似算法需要用到feature的分位数{S[1],S[2],…,S[k]},根据分位数需要对所有样本的某个feature进行遍历。 这里的每个样本的还有不同的权重。来自于对损失函数的变换,损失函数(前述公式 3 )可以写成如下形式:


这个损失函数形式上可以看成是 “加权的平方损失”: f(x[i])的标签为 g[i]/h[i],权重为h[i]。【上述图片中标红的“-”,我推导了一下感觉应该是“+”号吧,不过这符号不影响理解】

所以现在问题就变成:每个样本(feature)都有一个不同的权重,在这个带有各自权重的feature中寻找分位数的问题。

3.3.3 实现细节

论文中说:如果权重都是一样的,已经有现成的方案了;如果权重不同,论文提出了一种全新的方案,在附录中【还挺复杂,我没细看,以后看明白了,再在这笔记中补充上】

3.4 feature缺失的处理

对特征缺失的样本,Xgboost在分裂时给它一个default的分裂方向(左或右);这个default的方向也是通过数据学到的。算法如下:
在这里插入图片描述
问题1】上述算法中用了 “enumerate”,是“枚举”的意思。那么算法是把有缺失值的样本,挨个放到左边(或右边),选出最好的?还是把所有的 有缺失值的样本,放到左边(或右边)?
分析结果??】从上下文和算法中的步骤来看,应该是:把所有的有缺失值的样本,放到左边然后放到右边,在这个过程中,选出最好的一个方向,以后的样本如果到了这里,会根据这个方向,进入那个分支。

问题2】算法中内层循环有两个,分别是对非空特征升序排列和降序排列,二者是否有区别?是否可以都用升序或者降序?
分析结果】二者必须顺序不同。如果把第二个循环中的desent改成ascent,那么两个循环就重复了。第二个循环是多余的,如下图所示:
在这里插入图片描述


4. 算法工程化的系统设计

4.1 Column Block for Parallel Learning

(1)是什么?
Block是一个 in-memory(内存中?)的存储单元;
每个Block中的数据,以compressed columns(CSC) 的格式保存;
Block中的column都是按照相应的feature排序之后的;
Block可能包含某些所有样本,也可能包含所有样本的某些行;

(2)有什么用?
Block的列是排好序的,可以按照算法中的方法实现快速计算;
一个数据集存为多个Block,这样可以提高并行性;

4.2 Cache-aware Access

(1)要解决什么问题?
the new algorithm requires indirect fetches of gradient statistics by row index,since these values are accessed in order of feature. This is a non-continuous memory access. This slows down split finding when the gradient statistics do not fit into CPU cache and cache miss occur.
(2)怎么解决的?
(2.1) For the exact greedy algorithm, we can alleviate the problem by a cache-aware prefetching algorithm. Specifically,we allocate an internal buffer in each thread, fetch the gradient statistics into it, and then perform accumulation in a mini-batch manner. This prefetching changes the direct read/write dependency to a longer dependency and helps to reduce the runtime overhead when number of rows is large.
(2.2) For approximate algorithms, we solve the problem by choosing a correct block size.

4.3 Blocks for Out-of-core Computation

(1)这种技术的目的是什么?
One goal of our system is to fully utilize a machine’s resources to achieve scalable learning. Besides processors and memory, it is important to utilize disk space to handle data that does not fit into main memory.
(2)实现的过程
To enable out-of-core computation, we divide the data into multiple blocks and store each block on disk. During computation, it is important to use an independent thread to pre-fetch the block into a main memory buffer, so computation can happen in concurrence with disk reading.
(2.1)Block Compression
The block is compressed by columns, and decompressed on the fly by an independent thread when loading into main memory. This helps to trade some of the computation in decompression with the disk reading cost.
(2.2)Block Sharding
The second technique is to shard the data onto multiple disks in an alternative manner.A pre-fetcher thread is assigned to each disk and fetches the data into an in-memory buffer. The training thread then alternatively reads the data from each buffer. This helps to increase the throughput of disk reading when multiple disks are available.


5. XGB的时间复杂度

原论文4.1 涉及到四个计算复杂度

在这里插入图片描述
表格左上方的公式解释

K:表示K棵树;

d:树的每一层可以并行计算,所以时间复杂度只和树的深度有关;

在这里插入图片描述
表格右上方的公式解释

在这里插入图片描述

【表格左下方的公式解释】

排序的时候,用分位数代替所有特征,所以把n换为q;

【表格右下方的公式解释】

B是block中的最大的行数;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值