Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R e1071中的线性SVM中执行LOOCV并创建列联表_R - Fatal编程技术网

如何在R e1071中的线性SVM中执行LOOCV并创建列联表

如何在R e1071中的线性SVM中执行LOOCV并创建列联表,r,R,我有一个数据框testdata X95 X96 X97 X98 X99 X100 status 1 0.0096 0.0697 0.0021 0.0286 0.0088 0.0195 1 2 0.0133 0.0658 0.0022 0.0215 0.0114 0.0186 1 3 0.0091 0.0671 0.0027 0.0240 0.0101 0.0171 1 4 0.0095 0.0656 0.0011 0.0363 0.00

我有一个数据框testdata

 X95    X96    X97    X98    X99   X100 status
1 0.0096 0.0697 0.0021 0.0286 0.0088 0.0195      1
2 0.0133 0.0658 0.0022 0.0215 0.0114 0.0186      1
3 0.0091 0.0671 0.0027 0.0240 0.0101 0.0171      1
4 0.0095 0.0656 0.0011 0.0363 0.0092 0.0130      0
5 0.0081 0.0726 0.0018 0.0243 0.0095 0.0187      0
6 0.0088 0.0720 0.0015 0.0253 0.0094 0.0194      0

dput(testdata)
structure(list(X95 = c(0.0096, 0.0133, 0.0091, 0.0095, 0.0081, 
0.0088), X96 = c(0.0697, 0.0658, 0.0671, 0.0656, 0.0726, 0.072
), X97 = c(0.0021, 0.0022, 0.0027, 0.0011, 0.0018, 0.0015), X98 = c(0.0286, 
0.0215, 0.024, 0.0363, 0.0243, 0.0253), X99 = c(0.0088, 0.0114, 
0.0101, 0.0092, 0.0095, 0.0094), X100 = c(0.0195, 0.0186, 0.0171, 
0.013, 0.0187, 0.0194), status = c(1, 1, 1, 0, 0, 0)), .Names = c("X95", 
"X96", "X97", "X98", "X99", "X100", "status"), class = "data.frame", row.names = c(NA, 
6L))
我想创建一个线性支持向量机,它可以准确地将状态分类为0或1,并且可以使用省略一项的方法预测未来的观察结果

这就是我现在拥有的

y.svm <- rep(NA, nrow(testdata))
for (i in 1:nrow(testdata)) {
  testset <- testdata[i,]
  trainset <- testdata[-i,]
  model.svm <-
    svm(
      testdata[-i, 6] ~ .,
      data = trainset,
      type = "C-classification",
      kernel = "linear"
    )
  y.svm[i] <- as.character(predict(model.svm, testset))
}

y.svm您可以使用此解决方案:

library(gmodels)
actual <- testdata[,7]
predicted <- y.svm

#basic R solution
table(predicted,actual)

#Output similar to what users of SPSS or SAS expects
CrossTable(predicted,actual)
库(gmodels)
实际的