0
我正在使用MASS包中的qda函数来练习瑞士银行券数据集,但是当我在拟合模型上预测()时出现错误,问题是,qda返回一个“列表”而不是“qda”类:R qda {MASS}返回一个不是qda类的列表类
`str(swiss)`
`'data.frame':200 obs. of 7 variables:
$ Status : Factor w/ 2 levels "counterfeit",..: 2 2 2 2 2 2 2 2 2 2 ...
$ Length : num 215 215 215 215 215 ...
$ Left : num 131 130 130 130 130 ...
$ Right : num 131 130 130 130 130 ...
$ Bottom : num 9 8.1 8.7 7.5 10.4 9 7.9 7.2 8.2 9.2 ...
$ Top : num 9.7 9.5 9.6 10.4 7.7 10.1 9.6 10.7 11 10 ...
$ Diagonal: num 141 142 142 142 142 ...`
`qda.fit <- qda(Status ~., data = swiss, prior = c(0.99, 0.01), CV = TRUE)
test <- data.frame(Length = 214.9, Left = 130.1, Right = 129.9, Bottom = 9, Top = 10.6, Diagonal = 140.5)
qda.pred <- predict(qda.fit, test)
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "list"
Class(qda.fit)
[1] "list"`
`sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1`
`locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252 `
`attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base `
`other attached packages:
[1] MASS_7.3-45`
`loaded via a namespace (and not attached):
[1] tools_3.3.2`
希望你能帮上忙。
谢谢,
XP的
谢谢你的提示答案。是的,我已经尝试过了,但是在SAS中'proc discriminm data = combine pool = test crossvalidate testdata = test testout = a;'它通过交叉验证并给出了后验概率:假冒:0.000002526,真正的1尽管它不会影响R案例中的分类,但仍是准确的。我想我的问题应该是:我想在这种情况下用qda()进行交叉验证,并希望得到与SAS输出中类似的结果。 –