繁体   English   中英

无法使用手电筒 package 与 R 中的虹膜数据计算交互?

[英]Cant calculate interactions using flashlight package with iris data in R?

所以我试图将flashlight package 与虹膜数据一起使用。 flashlight提供的功能之一是计算称为light_interaction的变量之间的交互。 如果我使用lm model,我可以让light_interaction工作,但如果我使用mlr3创建我的 model,我就无法让它工作 [旁注:如果我使用mlr3创建回归 model,它与手电筒交互 function 完美配合......我只是无法让它用于分类......我需要手电筒才能与 mlr3 一起用于我的包裹]。 在下面的代码中,我展示了一个使用lm model 的示例……以及一个不使用mlr3的示例……我做错了什么吗?

lm model 有效的示例:

library(flashlight)

fit <- lm(Sepal.Length ~ ., data = iris)
x <- flashlight(model = fit, label = " ", data = iris, y = "Species")
light_interaction(x, pairwise = TRUE, type = "H", grid_size = 5,
                         normalize = F)

mlr3 model 不起作用:

library(mlr3)
library(mlr3learners)
# mlr3 TASK
bc_T = TaskClassif$new(id = "dat", backend = iris, target = "Species")
# learner
lrn = lrn("classif.ranger")
# model
bc_M <- lrn$train(bc_T)

x <- flashlight(model = bc_M, label = " ", data = iris, y = "Species")
light_interaction(x, pairwise = TRUE) # this line creates an error

这会返回一条错误消息:

rowsum.default(xx * ww, gg) 中的错误:'x' 必须是数字此外:警告消息:在 Ops.factor(xx, ww) 中:'*' 对因子没有意义

mlr3 使用 R6 并且拟合的 model 存储在$model槽中。 我不知道flashlight::light_interaction()做了什么,但就你的错误而言,它很简单

library(mlr3)
library(mlr3learners)
library(flashlight)
bc_T <- TaskClassif$new(id = "dat", backend = iris, target = "Species")
lrn <- lrn("classif.ranger")
bc_M <- lrn$train(bc_T)

x <- flashlight(model = bc_M$model, label = " ", data = iris, y = "Species")
print(x)
#> 
#> Flashlight   
#> 
#> Model:            Yes
#> y:            Species
#> w:            No
#> by:           No
#> data dim:         150 5
#> predict_fct default:  TRUE
#> linkinv default:  TRUE
#> metrics:      rmse
#> SHAP:             No

reprex package (v0.3.0) 创建于 2020-11-12

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM