다음 코드를 사용하여 leave-one-out 교차 유효성 검사를 수행하려고합니다.SVM 교차 유효성 검사 항상 동일
library(e1071)
library(plyr)
trainingdata<-read.table('data.txt', sep=",", header=TRUE)
f0 <- function(x) any(x!=1) & any(x!=0) & is.numeric(x)
trainingdata<-cbind(colwise(identity, f0)(trainingdata))
C <- 0
M <- 0
count <- nrow(trainingdata)
for(i in 1:count)
{
actual <- trainingdata[i,]$label
trainingtemp <- trainingdata[-c(i), ]
model <- svm(factor(label)~., data=trainingtemp, method="C-classification",
kernel="sigmoid", C=0.1, gamma=0.01, cross=10)
testdata <- trainingdata[i, ]
prediction <- predict(model, testdata)
prediction <- paste(prediction)
if(actual==prediction)
C <- C+1
else
M <- M+1
}
write.csv(data.frame(C,M))
내가 이해하지 못하는 문제는 항상 C (정확하게 분류 됨) 및 M (잘못 분류 됨)에 대해 동일한 값을 얻는다는 것입니다. 그 결과를 다음 조건으로 동일하다 :
1 - I 비용 및 감마 (도 시도 best.svm() 함수)
2 값이 다른 시도 -도 분류 + 다른 커널의 다른 방법을 시도 .
3 - 데이터 세트에는 약 50 개의 기능이 있습니다. 심지어 모델을 빌드하는 동안 하나의 기능 (예 : svm (label ~ x1 ...) 또는 svm (label ~ x2 ...))을 사용하더라도 결과는 아무런 영향을 미치지 않습니다.
? 코드 데이터는 여기에 게시 할 매우 큰
죄송합니다. 사실, 그것은 실수입니다. 나는 실제로 trainingtemp를 전달하고있다. 그것이 제가 실수로 시도한 마지막 변화였습니다. – Shahzad