Post · 9 min read· pp. 429–433

Gradient Boosting Machine

Introduction

Many people, including me, have been using gradient boosting machine (GBM), one of the most popular and powerful machine learning algorithms, to solve machine learning problems without knowing exactly what is going on underneath.

In this article, I will elucidate all the mathematics behind without leaving anything ambiguous.

Problem Definition

Most of the machine learning problems, including classification and regression problems, could be modeled as

F∗=argmin⁡FE(x,y)∼P(x,y)[L(y,F(x))]=argmin⁡FEx∼P(x)[Ey∼P(y∣x)[L(y,F(x))]∣x]\begin{align} F^{\ast} &= \operatorname*{argmin}_{F} \mathbb{E}_{(\mathbf{x},y) \sim P(\mathbf{x},y)}[L(y,F(\mathbf{x}))] \\ &= \operatorname*{argmin}_{F} \mathbb{E}_{\mathbf{x} \sim P(\mathbf{x})} \big[ \mathbb{E}_{y \sim P(y | \mathbf{x})}[L(y,F(\mathbf{x}))] \rvert \mathbf{x} \big] \end{align}

where x\mathbf{x} and yy are features and label respectively, LL is the loss function, FF is a function which represents the model, and F∗F^{\ast} is the optimized function.

Gradient Descent

Parameter Space

Suppose FF is a parameterized model with parameters P\mathbf{P}, F(x;P)F(\mathbf{x};\mathbf{P}), our optimization goal becomes equivalent to

P∗=argmin⁡PΦ(P)\begin{align} \mathbf{P}^{\ast} = \operatorname*{argmin}_{\mathbf{P}} \Phi(\mathbf{P}) \end{align}

where

Φ(P)=E(x,y)∼P(x,y)[L(y,F(x;P))]\begin{align} \Phi(\mathbf{P}) = \mathbb{E}_{(\mathbf{x},y) \sim P(\mathbf{x},y)}[L(y,F(\mathbf{x};\mathbf{P}))] \end{align}

and the optimal model is

F∗(x)=F(x;P∗)\begin{align} F^{\ast}(\mathbf{x}) = F(\mathbf{x};\mathbf{P}^{\ast}) \end{align}

We apply gradient descent to optimize the parameters P\mathbf{P}. Suppose at time step t−1t-1, the value of the parameters are Pt−1\mathbf{P}_{t-1}. The gradient of the parameters, gt\mathbf{g}_t, is computed as follows.

gt={gjt}={[∂∂PjΦ(P)]∣P=Pt−1}\begin{align} \mathbf{g}_{t} &= \{g_{jt}\} \\ &= \Bigg\{ \bigg[ \frac{\partial}{\partial P_j} \Phi(\mathbf{P}) \bigg] \Biggr\rvert_{\mathbf{P} = \mathbf{P}_{t-1}} \Bigg\} \\ \end{align}

where jj is the index of the parameter in the model.

The updated parameters at time step tt will become

Pt=Pt−1+pt−1\begin{align} \mathbf{P}_{t} = \mathbf{P}_{t-1} + \mathbf{p}_{t-1} \end{align}

where

pt−1=−ρtgt\begin{align} \mathbf{p}_{t-1} = -{\rho}_{t}\mathbf{g}_{t} \end{align}

Here ρt{\rho}_{t} is a scalar. Usually in machine learning, ρt{\rho}_{t} is arbitrary and is not optimal. To reach good optimization performance, we do linear search for ρt{\rho}_{t}, i.e.,

ρt=argmin⁡ρΦ(Pt−1−ρgt)\begin{align} {\rho}_{t} &= \operatorname*{argmin}_{\rho} \Phi(\mathbf{P}_{t-1} - \rho \mathbf{g}_{t}) \end{align}

Because ρt{\rho}_{t} is a scalar, so it could not make all the parameters in P\mathbf{P} to reach optimal values in one step. To optimize the parameters, we would have to do multiple steps to update. If we unroll the time-series updates, we would have

Pt=P0+∑i=0t−1pi\begin{align} \mathbf{P}_{t} = \mathbf{P}_{0} + \sum_{i=0}^{t-1} \mathbf{p}_{i} \end{align}

where P0\mathbf{P}_{0} is the initialized parameters at time step $0$.

Function Space

In stead of doing optimization in parameter space, we could also do optimization in function space. We consider F(x)F(\mathbf{x}), i.e., the value of function FF evaluated at point x\mathbf{x}, as the parameter to optimize.

Our objective function is

Φ(F)=E(x,y)∼P(x,y)[L(y,F(x))]=Ex∼P(x)[Ey∼P(y∣x)[L(y,F(x))]∣x]=∫xp(x)[Ey∼P(y∣x)[L(y,F(x))]∣x]dx\begin{align} {\Phi}(F) &= \mathbb{E}_{(\mathbf{x},y) \sim P(\mathbf{x},y)}[L(y,F(\mathbf{x}))] \\ &= \mathbb{E}_{\mathbf{x} \sim P(\mathbf{x})} \big[ \mathbb{E}_{y \sim P(y | \mathbf{x})}[L(y,F(\mathbf{x}))] \rvert \mathbf{x} \big] \\ &= \int\limits_{\mathbf{x}} p(\mathbf{x}) \big[ \mathbb{E}_{y \sim P(y | \mathbf{x})}[L(y,F(\mathbf{x}))] \rvert \mathbf{x} \big] d\mathbf{x} \\ \end{align}

and we define

ϕ(F(x))=Ey∼P(y∣x)[L(y,F(x))]∣x\begin{align} {\phi}(F(\mathbf{x})) = \mathbb{E}_{y \sim P(y | \mathbf{x})}[L(y,F(\mathbf{x}))] \rvert \mathbf{x} \end{align}

We assume function FF has no constrains, i.e., for any x\mathbf{x}, F(x)F(\mathbf{x}) could be any value. Minimizing the above objective function is equivalent to minimizing ϕ(F(x)){\phi}(F(\mathbf{x})) for each x\mathbf{x} in the integral interval. Usually, there are infinite number of x\mathbf{x}, and it is impossible to minimize ϕ(F(x)){\phi}(F(\mathbf{x})) for all x\mathbf{x}. However, in practice, our training data is finite, so we could do this.

Suppose our training set consists of NN data points x,y1N{ \mathbf{x} ,y }_{1}^{N}, the function FF could be represented as a discrete function

F=F(x),x∈{xi}1N\begin{align} F = F(\mathbf{x}), x \in {\{\mathbf{x}_{i}\}}_{1}^{N} \end{align}

if x\mathbf{x} does not exist in the training data, F(x)F(\mathbf{x}) is undefined and it could be any value. Also note that FF does not have to be differentiable with respect to x\mathbf{x}.

For each x\mathbf{x} from the training set, We compute the derivative of ϕ(F(x)){\phi}(F(\mathbf{x})) with respect to F(x)F(\mathbf{x}),

g(x)=∂∂F(x)ϕ(F(x))=∂∂F(x)Ey∼P(y∣x)[L(y,F(x))]∣x\begin{align} {g}(\mathbf{x}) &= \frac{\partial}{\partial F(\mathbf{x})} {\phi}(F(\mathbf{x})) \\ &= \frac{\partial}{\partial F(\mathbf{x})} \mathbb{E}_{y \sim P(y | \mathbf{x})}[L(y,F(\mathbf{x}))] \rvert \mathbf{x} \end{align}

So similarly,

g=g(x),x∈{xi}1N\labeleq1\begin{align} g = {g}(\mathbf{x}), x \in {\{\mathbf{x}_{i}\}}_{1}^{N} \label{eq1} \end{align}

We apply gradient descent to optimize FF. Suppose at time step t−1t-1, the value of the parameters are Ft−1F_{t-1}. The gradient of the parameters, gtg_t, is computed as follows.

Ft−1=Ft−1(x),x∈{xi}1N\begin{align} F_{t-1} = {F}_{t-1}(\mathbf{x}), x \in {\{\mathbf{x}_{i}\}}_{1}^{N} \end{align}

gt=gt(x)=[∂∂F(x)ϕ(F(x))]F(x)=Ft−1(x)=[∂∂F(x)Ey∼P(y∣x)[L(y,F(x))]∣x]F(x)=Ft−1(x)\begin{align} g_{t} &= {g}_{t}(\mathbf{x}) \\ &= \bigg[ \frac{\partial}{\partial F(\mathbf{x})} {\phi}(F(\mathbf{x})) \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \\ &= \bigg[ \frac{\partial}{\partial F(\mathbf{x})} \mathbb{E}_{y \sim P(y | \mathbf{x})}[L(y,F(\mathbf{x}))] \rvert \mathbf{x} \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \end{align}

Ft(x)=Ft−1(x)+ft(x)\begin{align} F_{t}(\mathbf{x}) = F_{t-1}(\mathbf{x}) + f_{t}(\mathbf{x}) \end{align}

where

ft(x)=−ρtgt(x)\begin{align} f_{t}(\mathbf{x}) = -{\rho}_{t} g_{t}(\mathbf{x}) \end{align}

So the updated function FF becomes

Ft(x)=Ft−1(x)+ft(x)=Ft−1(x)−ρtgt(x)\begin{align} F_{t}(\mathbf{x}) &= F_{t-1}(\mathbf{x}) + f_{t}(\mathbf{x}) \\ &= F_{t-1}(\mathbf{x}) -{\rho}_{t} g_{t}(\mathbf{x}) \end{align}

Similarly, the value of ρt{\rho}_{t} is determined by linear search,

ρt=argmin⁡ρΦ(Ft−1−ρgt)=argmin⁡ρE(x,y)∼P(x,y)[L(y,Ft−1(x)−ρgt(x))]=argmin⁡ρ∑i=1NL(yi,Ft−1(xi)−ρgt(xi))\begin{align} {\rho}_{t} &= \operatorname*{argmin}_{\rho} \Phi(F_{t-1} -{\rho} g_{t}) \\ &= \operatorname*{argmin}_{\rho} \mathbb{E}_{(\mathbf{x},y) \sim P(\mathbf{x},y)}[L(y,F_{t-1}(\mathbf{x}) - \rho g_t(\mathbf{x}))] \\ &= \operatorname*{argmin}_{\rho} \sum_{i=1}^{N} L(y_i,F_{t-1}(\mathbf{x}_i) - \rho g_t(\mathbf{x}_i)) \end{align}

Note that because each data point xi\mathbf{x}_i in the dataset only has one label yiy_i, i.e., P(yi∣xi)=1P(y_i | \mathbf{x}_i) = 1,

gt(xi)=[∂∂F(xi)Ey∼P(y∣xi)[L(y,F(xi))]]F(x)=Ft−1(x)=[∂∂F(xi)L(yi,F(xi))]F(x)=Ft−1(x)\begin{align} g_t(\mathbf{x}_i) &= \bigg[ \frac{\partial}{\partial F(\mathbf{x}_i)} \mathbb{E}_{y \sim P(y | \mathbf{x}_i)}[L(y,F(\mathbf{x}_i))] \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \\ &= \bigg[ \frac{\partial}{\partial F(\mathbf{x}_i)} L(y_i,F(\mathbf{x}_i)) \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \end{align}

The most frequently used loss function for regression is L2 loss.

L(yi,F(xi))=12(yi−F(xi))2\begin{align} L(y_i,F(\mathbf{x}_i)) = \frac{1}{2}(y_i - F(\mathbf{x}_i))^2 \end{align}

The gt(xi)g_t(\mathbf{x}_i) expression for L2 loss becomes

gt(xi)=[∂∂F(xi)L(yi,F(xi))]F(x)=Ft−1(x)=[∂∂F(xi)12(yi−F(xi))2]F(x)=Ft−1(x)=[(yi−F(xi))(0−1)]F(x)=Ft−1(x)=[F(xi)−yi]F(x)=Ft−1(x)\begin{align} g_t(\mathbf{x}_i) &= \bigg[ \frac{\partial}{\partial F(\mathbf{x}_i)} L(y_i,F(\mathbf{x}_i)) \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \\ &= \bigg[ \frac{\partial}{\partial F(\mathbf{x}_i)} \frac{1}{2}(y_i - F(\mathbf{x}_i))^2 \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \\ &= \bigg[ (y_i - F(\mathbf{x}_i))(0-1) \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \\ &= \bigg[ F(\mathbf{x}_i) - y_i \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \\ \end{align}

Gradient Boosting Machine

Theory

As we have pointed out, the optimization in functional space directly tunes the value of F(x)F(\mathbf{x}), and the optimization for F(x)F(\mathbf{x}) does not dependent on the training data points other than x\mathbf{x}. So FF would be very likely not to generalize well to the data points that have not been shown in the training set.

If we could impose smoothness to FF by introducing nearby data points when tuning the value of F(x)F(\mathbf{x}), FF is likely to generalize better.

So instead of updating FF using discrete function gg which has no smoothness at all, we use another smooth function hh such that h(x)h(\mathbf{x}) is close to g(x)g(\mathbf{x}) for x∈{xi}1Nx \in {\{\mathbf{x}_{i}\}}_{1}^{N}. In order to make hh smooth, we need to use all the data points from training set {xi}1N{\{\mathbf{x}_{i}\}}_{1}^{N} to fit the parameters for hh.

Concretely, we create a new model h(x;at)h(\mathbf{x}; \mathbf{a}_t) at each time step tt. The update of function FF becomes

Ft(x)=Ft−1(x)+ρth(x;at)\begin{align} F_t(\mathbf{x}) = F_{t-1}(\mathbf{x}) + \rho_t h(\mathbf{x}; \mathbf{a}_t) \end{align}

Because h(x;at)h(\mathbf{x}; \mathbf{a}_t) is a smoothing version of −gt(x)-g_{t}(\mathbf{x}), therefore, we use (xi,gt(xi))(\mathbf{x}_i, g_{t}(\mathbf{x}_i)), x∈{xi}1Nx \in {\{\mathbf{x}_{i}\}}_{1}^{N}, as the train set to fit h(x;at)h(\mathbf{x}; \mathbf{a}_t) using L2 loss.

at=argmin⁡a,β∑i=1N[−gt(xi)−βh(xi;at)]2\begin{align} \mathbf{a}_t = \operatorname*{argmin}_{\mathbf{a}, \beta} \sum_{i=1}^{N} [-g_t(\mathbf{x}_i) - \beta h(\mathbf{x}_i; \mathbf{a}_t)]^2 \end{align}

Note that h(x;at)h(\mathbf{x}; \mathbf{a}_t) is parameterized and smoothed by fitting using all data points from the train set. Sometimes, −gt(xi)-g_t(\mathbf{x}_i) is also denoted as y~i\tilde{y}_i, and y~i\tilde{y}_i is called “pseudo-response”.

y~i=−gt(xi)=−[∂∂F(xi)L(yi,F(xi))]F(x)=Ft−1(x)\begin{align} \tilde{y}_i &= -g_t(\mathbf{x}_i) \\ &= - \bigg[ \frac{\partial}{\partial F(\mathbf{x}_i)} L(y_i,F(\mathbf{x}_i)) \bigg]_{F(\mathbf{x}) = F_{t-1}(\mathbf{x})} \end{align}

The constant ρt\rho_t could be computed using linear search.

ρt=argmin⁡ρ∑i=1NL(yi,Ft−1(xi)+ρh(xi;at))\begin{align} {\rho}_{t} &= \operatorname*{argmin}_{\rho} \sum_{i=1}^{N} L(y_i,F_{t-1}(\mathbf{x}_i) + \rho h(\mathbf{x}_i; \mathbf{a}_t)) \end{align}

Therefore, gradient boosting machine is nothing special but using a parametric smoothing function h(xi;at))h(\mathbf{x}_i; \mathbf{a}_t)) to replace the discrete non-parametric gradient function gt(x)g_t(\mathbf{x}) during the machine learning optimization in the function space. In each time step, we introduce a new model, which is called “boost”.

Algorithm

Gradient Boosting Machine Algorithm

References