-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rest
and intercept
column to glexobj$m
#25
base: master
Are you sure you want to change the base?
Conversation
I think we need to be careful here, as changing the structure of the glex object has ripple effects across every plotting and reshaping function and needs to be consistent across the 2 (or 3, counting rpf) supported learners. Some thoughts:
Example for remainder termlibrary(glex)
library(xgboost)
library(randomPlantedForest)
set.seed(234)
options(max.print = 10)
# this is completely arbitrary nonsense
xdat <- data.frame(
x1 = rnorm(100),
x2 = rpois(100, 2),
x3 = runif(100)
)
xdat <- within(xdat, y <- 3 * x1 + 0.5 * (x2 + x3) + 3 * abs(x1 * x3))
# rpf has remainder term
rpf_fit <- rpf(y ~ ., data = xdat, num.trees = 50, max_interaction = 3)
rpf_glex <- glex(rpf_fit, xdat, max_interaction = 2)
rpf_glex$remainder
#> [1] -0.0153642314 -0.0166246943 -0.0396781809 0.0453551935 -0.0003334053
#> [6] 0.0038383014 0.0034622827 0.0306458754 -0.0007525907 -0.0162234933
#> [ reached getOption("max.print") -- omitted 90 entries ]
# also, intercept is stored as scalar
rpf_glex$intercept
#> [1] 2.053044
# xgb not yet
xgb_fit <- xgboost(data = as.matrix(xdat[, 1:3]), label = xdat$y, max_depth = 3,
early_stopping_rounds = 50, nrounds = 1000, verbose = FALSE)
xgb_glex <- glex(xgb_fit, as.matrix(xdat[, 1:3]), max_interaction = 2)
xgb_glex$remainder
#> NULL
xgb_glex$intercept
#> [1] 2.141527
# Also, shap is stored but known to be wrong due to max_interaction limit
xgb_glex$shap
#> x1 x2 x3
#> <num> <num> <num>
#> 1: 1.98061587 0.056079863 0.12250051
#> 2: -3.80587144 -0.281592150 -0.33564143
#> [ reached getOption("max.print") -- omitted 99 rows ] Created on 2024-11-19 with reprex v2.1.1 |
To be merged after #24.
This PR adds an
intercept
column toglex_obj$m
for all supported tree-methods. Moreover, if the task is regression, arest
column will also be added which is equal topredictions - rowSums(glex_obj$m)