gpt4 book ai didi

r - xgb.fi() 函数检测交互并使用 xgboost 返回异常

转载 作者:行者123 更新时间:2023-12-03 19:01:23 25 4
gpt4 key购买 nike

xgb.fi() 是一个与 xgboost 配合使用以检测变量之间的相互作用的新函数。

文档可在此处找到:https://rdrr.io/github/RSimran/RXGBfi/man/xgb.fi.html

这是一个重要的主题,我尝试测试该功能但遇到异常。

请参阅下面的可重现示例:

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>

enter image description here

enter image description here

enter image description here

最佳答案

当我测试你的代码时,我得到了和你一样的错误。所以我决定深入研究函数 xgb.fi(),我将源代码复制到这里:https://github.com/RSimran/RXGBfi/blob/master/R/xgbfi.R并逐行执行它以识别我们在 Shiny 的应用程序中看到的错误。

当我这样做时,它工作正常......所以我执行了整个函数以重写函数 xgb.fi() (它出现在我的 Rstudio 环境中),然后我再次运行代码。这一次, Shiny 效果完美。

[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)

这样,第一个表“3 Variable Feature”上只有一个错误,因为在您的示例中,模型没有创建与 3 个变量的交互。

enter image description here

关于r - xgb.fi() 函数检测交互并使用 xgboost 返回异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49686063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com