【问题标题】:R: extracting initialized predictions in xgboostR:在 xgboost 中提取初始化预测
【发布时间】:2020-04-08 03:24:32
【问题描述】:
library(xgboost)
data(agaricus.train, package='xgboost')
# Initialize baseline predictions to be 0
baseline_predictions <- rep(1.5, nrow(agaricus.train$data))
# base_margin is the base prediction Xgboost will boost from ;
dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label, base_margin = baseline_predictions)
param <- list(max_depth = 2, eta = 1, verbose = 0, nthread = 2,
              objective = "binary:logistic", eval_metric = "auc")
bst <- xgb.train(param, dtrain, nrounds = 2)
> xgb.dump(bst, with_stats = T)
 [1] "booster[0]"                                                                    
 [2] "0:[f28<-9.53674316e-07] yes=1,no=2,missing=1,gain=6691.7876,cover=971.39093"   
 [3] "1:[f55<-9.53674316e-07] yes=3,no=4,missing=3,gain=1923.16174,cover=551.54364"  
 [4] "3:leaf=0.742681563,cover=484.427734"                                           
 [5] "4:leaf=-4.93142509,cover=67.1159134"                                           
 [6] "2:[f108<-9.53674316e-07] yes=5,no=6,missing=5,gain=336.239258,cover=419.847321"
 [7] "5:leaf=-5.37396955,cover=411.942535"                                           
 [8] "6:leaf=1.08577335,cover=7.90476274"                                            
 [9] "booster[1]"                                                                    
[10] "0:[f59<-9.53674316e-07] yes=1,no=2,missing=1,gain=1517.97913,cover=354.008148" 
[11] "1:[f66<-9.53674316e-07] yes=3,no=4,missing=3,gain=1250.927,cover=340.298492"   
[12] "3:leaf=0.488599688,cover=338.470062"                                           
[13] "4:leaf=21.6099014,cover=1.82844138"                                            
[14] "2:leaf=-9.71027374,cover=13.709651"

在上面的代码中,我通过指定 base_margin = baseline_predictions 将训练数据中所有观察值的预测值初始化为 1.5。

使用xgb.dump, 我可以看到结果树是合适的。我的问题是,是否也可以提取初始预测?也就是说,给定一个 XGBoost 模型bst,我可以提取基线预测(即所有观察值均为 1.5)?

【问题讨论】:

  • @jpmam1 感谢您的链接。我不认为该文档提供了一种从 bst 中提取基线预测的方法
  • xgboost::getinfo(object = dtrain, name = "base_margin") 可以解决您的问题吗?
  • 谢谢,太好了。您想将其添加为答案吗?
  • 很高兴它为你工作:)

标签: r machine-learning xgboost


【解决方案1】:

解决这个问题的方法是使用xgboost::getinfo(object = dtrain, name = "base_margin") 来获取baseline_predictions。无论它们是预先设置在(例如本例中的“1.5”)还是从初步训练运行计算baseline_predictions(例如https://github.com/dmlc/xgboost/blob/master/R-package/demo/boost_from_prediction.R),这都是有用的

【讨论】:

    猜你喜欢
    • 2018-11-05
    • 2019-04-29
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 2016-05-25
    • 1970-01-01
    相关资源
    最近更新 更多