我试图预测SVM返回的迹象,但在某处有错误,因为结果很差。
x <- sign(dataset)
trainindex1= x[1:5792,1]
trainindex2 = x[1:5792,-1]
testindex = x[5792:7030,-1]
trainindex1 <- as.factor(trainindex1)
trainindex2 <- as.vector(trainindex2)
testindex <- as.vector(testindex)
svmFit = svm (y=trainindex1, x=trainindex2,
type="C",
kernel= "radial",
gamma=5,
cost=30)
predsvm = predict(svmFit, testindex)
table(predsvm, testindex)
结果
testindex
predsvm -1 0 1
-1 0 0 0
0 0 0 0
1 2819 5 3371
拜托,能帮帮我解释一下我该怎么办?
答案 0 :(得分:0)
我不确定哪些变量应该是类和哪些数字。我认为TARGET是一个因素,其余的都是数字。在这种情况下,您可以尝试以下代码:
library(dplyr)
x <- sign(dataset)%>%as.data.frame
x$TARGET<-as.factor(as.character(x$TARGET))
trainindex= x[1:5792,]
testindex = x[5793:7030,]
svmFit = svm (TARGET~.,data=trainindex,type="C",kernel= "radial",gamma=5,cost=30)
predsvm = predict(svmFit, newdata=testindex)
confusionMatrix(predsvm, testindex$TARGET)