[英]Error in xj[i] : invalid subscript type 'list' when do LDA in R
mydat=structure(list(spent = c(73.5, 73.5, 73.5, 73.5, 73.5, 73.5,
73.5, 73.5, 73.5, 73.5, 73.5, 29.74, 29.74, 29.74, 29.74, 29.74,
29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 73.71, 73.71, 73.71,
73.71, 73.71, 73.71, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5,
73.5, 73.5, 73.5, 73.5, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74,
29.74, 29.74, 29.74, 29.74, 29.74, 73.71, 73.71, 73.71, 73.71,
73.71, 73.71), realpurchase_cash = c(501, 502, 503, 504, 505,
506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518,
519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 73.5, 73.5,
73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 29.74,
29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74,
29.74, 73.71, 73.71, 73.71, 73.71, 73.71, 73.71), id = c(123L,
123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L,
123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L,
123L, 123L, 123L, 123L, 123L, 124L, 124L, 124L, 124L, 124L, 124L,
124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L,
124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L
), flag = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("spent",
"realpurchase_cash", "id", "flag"), class = "data.frame", row.names = c(NA,
-56L))
i want perform Linear discriminant analysis. 我想进行线性判别分析。 (lda function comes from MASS library)
(lda函数来自MASS库)
here my code 我的代码
index <- sample(1:nrow(mydat),round(0.70*nrow(mydat)))
train <- mydat[index,]
test <- mydat[-index,]
library("MASS")
fit=lda(flag~spent+realpurchase_cash, mydat, subset = train)
library("caret")
str(mydat)
library(InformationValue)
predicted <- predict(fit,test,type='response')
optCutOff <- optimalCutoff(test$flag, predicted)[1]
confusionMatrix(test$flag, predicted, threshold = optCutOff)
but after this string 但是这个字符串之后
fit=lda(flag~spent+realpurchase_cash, mydat, subset = train)
i get the error 我收到了错误
Error in xj[i] : invalid subscript type 'list'
How to fix this error. 如何解决此错误。 What's wrong?
怎么了?
subset
wants a vector and you give him a data frame (ie a list). subset
想要一个向量,你给他一个数据框(即一个列表)。 Do 做
lda(flag ~ spent + realpurchase_cash, mydat, subset=index)
or, since train
is already your desired subset, just 或者,因为
train
已经是您想要的子集,只是
lda(flag ~ spent + realpurchase_cash, data=train)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.