I'm not sure what the outcome of xgboost -> predict(..., predleaf=T) is.
The docs state that:
When predleaf = TRUE, the output is a matrix object with the number of columns corresponding to the number of trees.
However, what do the numeric values in the columns stand for?
Minimal example:
library(ISLR)
library(xgboost)
auto = ISLR::Auto
auto$name<-NULL
auto$origin<-NULL
dtrain <- xgb.DMatrix(data=as.matrix(auto[,-1]),label=as.matrix(auto[,1]))
param <- list(booster = 'gbtree'
, objective = 'reg:squarederror'
, learning_rate = 0.1
, set.seed = 2020)
xgb <- xgb.train(params = param
, data = dtrain
, nrounds = 4)
xgb_leaf <- data.frame(predict(xgb, dtrain, predleaf = T))
head(xgb_leaf)
X1 X2 X3 X4
1 6 9 11 15
2 6 11 11 15
3 6 11 11 15
4 6 11 11 15
5 6 11 11 15
6 6 11 11 13
So for each tree there is a numerical value for each row/observation.
I suppose this is the "number" of the leaf in which a row/observation falls in a particular tree. Is this correct?