[英]Cant calculate interactions using flashlight package with iris data in R?
So Im trying to use the flashlight
package with the iris data.所以我试图将
flashlight
package 与虹膜数据一起使用。 One of the functions flashlight
provides is to calculate the interactions between variables called light_interaction
. flashlight
提供的功能之一是计算称为light_interaction
的变量之间的交互。 I can get light_interaction
to work if I use an lm
model but I can not get it to work if I create my model using mlr3
[side note: if I create a regression model using mlr3
, it works perfectly with flashlights interaction function... I just can't get it to work for classification... and I need flashlight to work with mlr3 for my package].如果我使用
lm
model,我可以让light_interaction
工作,但如果我使用mlr3
创建我的 model,我就无法让它工作 [旁注:如果我使用mlr3
创建回归 model,它与手电筒交互 function 完美配合......我只是无法让它用于分类......我需要手电筒才能与 mlr3 一起用于我的包裹]。 In the code below I show an example of it working with an lm
model... and an example of it not working with mlr3
... am I doing something wrong?在下面的代码中,我展示了一个使用
lm
model 的示例……以及一个不使用mlr3
的示例……我做错了什么吗?
lm
model example that works: 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 that doesn't work: 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
This throws back an error saying:这会返回一条错误消息:
Error in rowsum.default(xx * ww, gg): 'x' must be numeric In addition: Warning message: In Ops.factor(xx, ww): '*' not meaningful for factors
rowsum.default(xx * ww, gg) 中的错误:'x' 必须是数字此外:警告消息:在 Ops.factor(xx, ww) 中:'*' 对因子没有意义
mlr3 uses R6 and the fitted model is stored in the $model
slot. mlr3 使用 R6 并且拟合的 model 存储在
$model
槽中。 I do not know what flashlight::light_interaction()
does but as far as your error is concerned, it is as simple as我不知道
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
Created on 2020-11-12 by the reprex package (v0.3.0)由reprex package (v0.3.0) 创建于 2020-11-12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.