R: extracting initialized predictions in xgboost

Viewed 65
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"

In the above code, I initialized the predictions at 1.5 for all the observations in my training data by specifying base_margin = baseline_predictions.

Using xgb.dump, I am able to see the resulting trees that were fit. My question is, is it possible to also extract the initial predictions? That is, given a XGBoost model bst, that I can extract the baseline predictions (i.e. 1.5 for all observations)?

1 Answers
Related