簡體   English   中英

通過 svm 預測 R 中的回報符號

[英]Prediction the sign of returns in R by svm

我試圖通過 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

拜托,你能幫我解釋一下我該如何解決嗎?

好吧,我不確定您的哪些變量應該是類,哪些是數字。 我假設 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM