xgb.fi() 函数检测交互并使用 xgboost 返回异常 [英] xgb.fi() function detecting interactions and working with xgboost returns exception
问题描述
xgb.fi()
是一个与 xgboost 配合使用以检测变量之间交互作用的新函数.
文档可以在这里找到:
当我测试你的代码时,我得到了和你一样的错误.所以我决定深入研究xgb.fi()函数,我把源代码复制到这里:
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>
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.
这篇关于xgb.fi() 函数检测交互并使用 xgboost 返回异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!