holub008 / xrf

eXtreme RuleFit (sparse linear models on XGBoost ensembles)
Other
43 stars 13 forks source link

Error: Can't combine `..1$feature` <character> and `..61$feature` <logical> #18

Closed ruiruimufeng closed 2 years ago

ruiruimufeng commented 2 years ago

I have checked all my column type, they're all numeric. After working around, following seems solved the problem.

trace(xrf:::extract_xgb_rules, edit = T)

Replace code with:

function(m) { rules <- xgb.model.dt.tree(model = m) %>% group_by(.data$Tree) %>% arrange(.data$Node) %>% # put the root at the top of each tree group do(harvested_rules = rule_traverse(.data[1, ], .data) %>% filter(!is.na(.data$feature))) %>% pull(.data$harvested_rules) %>% map_df( ~ .x %>% mutate(feature = as.character(feature)))

rules } Hope this can help someone who encounterd same problem.

Q: Is there anyway to get the importance ranking?

holub008 commented 2 years ago

Hi @ruiruimufeng thanks for reporting - could you share a minimal code & data example to reproduce?

holub008 commented 2 years ago

RE importance ranking, it depends on what you want. The xrf function returns the XGBoost & glmnet models, which you can use the respective xgboost and glmnet APIs of to compute importance, regularization dropout, etc.

simonpcouch commented 2 years ago

Hey @holub008, thanks for the great package! I've been coming across errors like this occasionally while working on wrappers for your package in tidymodels/rules, and thought I'd share an example to reproduce with:

data("ames", package = "modeldata")
ames$Sale_Price <- log10(ames$Sale_Price)

xrf::xrf(
  Sale_Price ~ Neighborhood + Longitude + Latitude +
    Gr_Liv_Area + Central_Air,
  data = ames,
  family = "gaussian",
  xgb_control = list(nrounds = 5, colsample_bynode = 1, 
                     colsample_bytree = 1/5),
  verbose = 0
)
#> Error in `bind_rows()`:
#> ! Can't combine `..1$feature` <character> and `..2$feature` <logical>.

Created on 2022-06-03 by the reprex package (v2.0.1)

Thanks again for your work.

holub008 commented 2 years ago

Thanks @simonpcouch! I'll try to take a look at this inside a week.