xgb.fi() function detecting interactions and working with xgboost returns exception

£可爱£侵袭症+ 提交于 2019-12-13 14:08:11

问题


xgb.fi() is a new function that works with xgboost to detect interactions between variables.

The documentation can be found here: https://rdrr.io/github/RSimran/RXGBfi/man/xgb.fi.html

This is an important subject and I tried to test the function but I run into an exception.

See below for a reproducible example:

library(data.table)
library(xgboost)
library(RXGBfi)


data(mtcars)

X = as.matrix(mtcars[, -9])
Y = mtcars$am

dtrain = xgb.DMatrix(data = X, label = Y)

model = xgb.train(data = dtrain, 

                  eval = "auc",

                  verbose =0,  maximize = TRUE, 

                  params = list(objective = "binary:logistic",

                                eta = 0.1,

                                max_depth = 6,

                                subsample = 0.8,

                                lambda = 0.1 ), 

                  nrounds = 10)



features = names(mtcars)[-9]


xgb.fi(model = model, features = features)


Listening on http://127.0.0.1:7333
Warning: Error in :=: Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
Stack trace (innermost first):
    95: :=
    94: [.data.frame
    93: [.data.table
    92: [
    91: tableVars1
    90: base::rownames
    89: datatable
    88: eval
    87: eval
    86: %>%
    85: exprFunc
    84: widgetFunc
    83: func
    82: origRenderFunc
    81: renderFunc
    80: origRenderFunc
    79: output$tableVars1
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: <Promise>  

Your advice will be appreciated.


回答1:


When I tested your code, I obtained the same error as you. So I decided to go deeper in the function xgb.fi(), I copy the source code here:https://github.com/RSimran/RXGBfi/blob/master/R/xgbfi.R and executed it line by line in order to identify the error we saw in the shiny app.

When I did this, it worked corretly ... So I executed the whole function in order to rewrite the function xgb.fi() (it appears in my Rstudio environment) and I run again the code. This time, the shiny works perfectly.

[your code, with the xgboost model]

xgb.fi <- function(model, xgbfi.loc = "C:/xgbfi", features = NULL, max.interaction.depth = 2, 
                   max.deepening = -1, max.trees = -1, top.k = 100, max.histograms = 10) {

  library(xgboost)
  xgbfi_exe <- paste0(xgbfi.loc, "/", "bin", "/", "XgbFeatureInteractions.exe")

  featureVector <- c()
  [...]
}

xgb.fi(model = model, features = features)

This way, there is only an error on the first table "3 Variable Feature" because in your example the model didn't create interaction with 3 variables.



来源:https://stackoverflow.com/questions/49686063/xgb-fi-function-detecting-interactions-and-working-with-xgboost-returns-except

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!