【问题标题】:How to use xgboost R tree dump to compute or do predictions?如何使用 xgboost R 树转储来计算或进行预测?
【发布时间】:2017-06-21 05:38:05
【问题描述】:

xgboost xgb.dump tree coefficient 问题中获取线索。

我特别想知道如果 eta = 0.1 或 0.01,概率计算与提供的答案有何不同?

我想使用树转储进行预测。

我的代码是

#Define train label and feature frames/matrix
y <- train_data$esc_ind
train_data = as.matrix(train_data)
trainX <- as.matrix(train_data[,-1])
param <- list("objective" = "binary:logistic",
              "eval_metric" = "logloss",
              "eta" = 0.5,
              "max_depth" = 2, 
              "colsample_bytree" = .8,
              "subsample" = 0.8, #0.75
              "alpha" = 1

)

#Train XGBoost
bst = xgboost(param=param, data = trainX, label = y, nrounds=2) 

trainX1 = data.frame(trainX)
mpg.fmap = genFMap(trainX1, "xgboost.fmap")
xgb.save(bst, "xgboost.model")
xgb.dump(bst, "xgboost.model_6.txt",with.stats = TRUE, fmap = "xgboost.fmap")

树看起来像:

booster[0]
0:[order.1<12.2496] yes=1,no=2,missing=2,gain=1359.61,cover=7215.25
    1:[access.1<0.196687] yes=3,no=4,missing=4,gain=3.19685,cover=103.25
        3:leaf=-0,cover=1
        4:leaf=0.898305,cover=102.25
    2:[team<6.46722] yes=5,no=6,missing=6,gain=753.317,cover=7112
        5:leaf=0.893333,cover=55.25
        6:leaf=-0.943396,cover=7056.75
booster[1]
0:[issu.1<6.4512] yes=1,no=2,missing=2,gain=794.308,cover=5836.81
    1:[team<3.23361] yes=3,no=4,missing=4,gain=18.6294,cover=67.9586
        3:leaf=0.609363,cover=21.4575
        4:leaf=1.28181,cover=46.5012
    2:[case<6.74709] yes=5,no=6,missing=6,gain=508.34,cover=5768.85
        5:leaf=1.15253,cover=39.2126
        6:leaf=-0.629773,cover=5729.64

当 eta 选择小于 1 时,xgboost 的所有树叶分数的系数是否为 1?

【问题讨论】:

标签: r tree logistic-regression xgboost


【解决方案1】:

其实这很实用,我之前已经监督过了。

使用上面的树形结构可以找到每个训练示例的概率。

参数列表是:

param <- list("objective" = "binary:logistic",
              "eval_metric" = "logloss",
              "eta" = 0.5,
              "max_depth" = 2, 
              "colsample_bytree" = .8,
              "subsample" = 0.8,
              "alpha" = 1)

对于leaf booster[0]中设置的实例,leaf: 0-3;概率为 exp(-0)/(1+exp(-0))。

对于 booster[0],叶子:0-3 + booster[1],叶子:0-3;概率为 exp(0+ 0.609363)/(1+exp(0 + 0.609363))。

随着迭代次数的增加,以此类推。

我将这些值与 R 的预测概率相匹配,它们相差 10^(-7),可能是由于叶子质量分数的浮点缩减。

当 R 的训练有素的提升树用于不同环境进行预测时,此答案可以提供生产级解决方案。

对此的任何评论将不胜感激。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-17
    • 2018-12-31
    • 2016-08-21
    • 2016-03-11
    • 2020-01-10
    • 2020-01-21
    • 2016-01-17
    • 1970-01-01
    相关资源
    最近更新 更多