对于分类问题,当然要转成OHE了,然后对于每个out_dims
进行拟合
1
2
G
L
2
H
L
+
λ
+
1
2
G
R
2
H
R
+
λ
−
1
2
(
G
L
+
G
R
)
2
H
L
+
H
R
+
λ
−
γ
\frac{1}{2} \frac{G_{L}^{2}}{H_{L}+\lambda}+\frac{1}{2} \frac{G_{R}^{2}}{H_{R}+\lambda}-\frac{1}{2} \frac{\left(G_{L}+G_{R}\right)^{2}}{H_{L}+H_{R}+\lambda}-\gamma
21HL+λGL2+21HR+λGR2−21HL+HR+λ(GL+GR)2−γ
XGBoostRegressionTree
继承了DecisionTree
,好家伙,不重写函数,用这么苟的方式,我楞了几分钟才看懂,可能作者为了通过函数名让我们理解吧
class SquareLoss(Loss):
def __init__(self):
pass
def loss(self, y, y_pred):
pass
def grad(self, y, y_pred):
return -(y - y_pred)
def hess(self, y, y_pred):
return 1
class CrossEntropyLoss(Loss):
def __init__(self):
pass
def loss(self, y, y_pred):
pass
def grad(self, y, y_pred):
return - (y - y_pred)
def hess(self, y, y_pred):
return y_pred * (1-y_pred)