XGBoost-XGBoost objective 参数部分选项解释

141 阅读2分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 2 月更文挑战」的第 11 天,点击查看活动详情

首先 objective 是目标函数的意思,也就是建模的时候,需要最小化的函数

binary:logistic: logistic regression for binary classification, output probability Binary:logistic:二分类逻辑回归,输出标签为 1 概率

binary:logitraw: logistic regression for binary classification, output score before logistic transformation Binary:logitraw:二分类逻辑回归,输出使用逻辑回归转化前(sigmoid 函数)的分数

这里要明确一个关系,通过最小化二分类交叉熵损失函数,得到 w\vec{w},此时对于新的样本直接使用 wxw \cdot x 得到的值,就是使用binary:logitraw得到的结果,也就是对数几率,如果在此基础上对 wxw \cdot x 使用 sigmoid 函数,对应着binary:logistic得到的结果

multi:softmax: set XGBoost to do multiclass classification using the softmax objective, you also need to set num_class (number of classes) Multi:softmax:让 XGBoost 使用 softmax 作为目标函数执行多分类,你需要这顶 num_classes(类别的数量)

multi:softprob: same as softmax, but output a vector of ndata * nclass, which can be further reshaped to ndata * nclass matrix. The result contains predicted probability of each data point belonging to each class. Multi:softprob:和 softmax 相同,但是输出一个样本数量 * 类别数量的向量,该向量会被 reshape 为样本数量 * 类别数量的矩阵。结果包含每一个样本点属于每一类的预测概率

弄懂二分类的情况后,多分类的情况比较好理解,

当现在的问题是 KK 分类、且每个类别为 [1,2,3...k][1,2,3...k] 时,我们则分别按照 y=1,y=2,...,y=ky = 1, y = 2,...,y = k 进行建模,总共建立 KK 棵树,每棵树输出的结果为:

H1(xi),H2(xi),...,Hk(xi)H^1(x_i), H^2(x_i),...,H^k(x_i)

总共 KK 个输出结果。然后,我们分别将 H1(xi)H^1(x_i)Hk(xi)H^k(x_i) 的结果输入 softmax,来计算出每个标签类别所对应的概率。具体地来说,softmax 函数的表达式为:

Softmax(Hk(x))=eHk(x)k=1KeHk(x)Softmax(H^k(x)) = \frac{e^{H^k(x)}}{\sum_{k=1}^Ke^{H^k(x)}}