GBDT_Simple_Tutorial
GBDT_Simple_Tutorial copied to clipboard
BinomialDeviance损失函数中损失函数计算错误
你好,个人认为,BinomialDeviance损失函数中,计算loss的公式有问题,类似于sklearn包中的损失计算,此处的正确的公式应该是:-2.0(yf - log(1 + exp(f))),代码中是-2.0(yf - (1 + exp(f)))
上一条有问题,你好,个人认为,BinomialDeviance损失函数中,计算loss的公式有问题,类似于sklearn包中的损失计算,此处的正确的公式应该是:-2.0(yf - log(1 + exp(f))),代码中是-2.0(yf - exp(1+f))
"""Compute the deviance (= 2 * negative log-likelihood).
Parameters
----------
y : array, shape (n_samples,)
True labels
pred : array, shape (n_samples,)
Predicted labels
sample_weight : array-like, shape (n_samples,), optional
Sample weights.
"""
# logaddexp(0, v) == log(1.0 + exp(v))
pred = pred.ravel()
if sample_weight is None:
return -2.0 * np.mean((y * pred) - np.logaddexp(0.0, pred))
else:
return (-2.0 / sample_weight.sum() *
np.sum(sample_weight * ((y * pred) - np.logaddexp(0.0, pred))))
我也觉得BinomialDeviance损失函数有问题,sklearn中代码是这么写的。