我正在尝试通过以矢量形式保存参数来优化我的代码,并将其传递给lda()
进行建模。以下方法适用于lm,但不适用于qda或lda。我收到的错误信息以黄色突出显示。
intvars <- c("x*y","y*t","z*w")
intfm <- paste("clickthrough", "~", paste(intvars, collapse = " + "))
lda_model_int <- lda(intfm, data = s_train)
lda.default中的错误(intfm,data = s_train):'x'不是矩阵
答案 0 :(得分:1)
您必须将字符串更改为formula
,或者reformulate
intvars <- c("x*y","y*t","z*w")
intfm <- reformulate(intvars,"clickthrough")
lda_model_int <- lda(intfm, data = s_train)
如果你想按自己的方式去做,
intvars <- c("x*y","y*t","z*w")
intfm <- as. formula(paste("clickthrough", "~", paste(intvars, collapse = " + ")))
lda_model_int <- lda(intfm, data = s_train)