简体   繁体   English

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

[英]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.

相关问题 使用 R 中的“交互”package 探测 nlme 中的交互 - Probing interactions in nlme using the "interactions" package in R 是否有 R 函数或包来计算 GLMM 中斜率的 p 值与交互 - Is there a R function or package to calculate the p value of a slope in a GLMM with interactions 使用 R 中的插入符号 package 对 Iris 数据应用 KNN 时缺少准确度值 - Accuracy values are missing while applying KNN on Iris data using caret package in R R中的虹膜数据集 - Iris Data Set in R 在 R 中在 Iris 上使用示例 - Using sample on Iris in R 用列均值计算数据虹膜 - Calculate Data Iris with Mean of Column 我是Shiny的新手,我想使用Iris数据集(这是R中的一个包)将一个简单的应用程序放在一起: - I am new to shiny and I am trying to put a simple app together using the iris data set, which is a package in R: 从 linkcomm package 检索二进制交互作为 R 中的数据框 - Retrieving binary interactions from linkcomm package as a data frame in R 使用“交互”package 在 R 中创建多面图 2 向交互 - create faceted plots 2-way interaction in R using 'interactions' package 在 R 中,data.frame 名称`iris`,我怎么知道它来自哪个 package? - In R, the data.frame name `iris`, how can i know which package it come from?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM