【问题标题】:Prediction the sign of returns in R by svm通过 svm 预测 R 中的回报符号
【发布时间】:2018-07-15 11:09:08
【问题描述】:

我试图通过 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

请你帮我解释一下我该如何解决它?

【问题讨论】:

  • 您的训练数据是什么样的? predsvm 返回什么?你的训练数据有多平衡?您的测试样品是否具有代表性?您是如何选择超参数和内核的?
  • 训练数据只是 1990 年到 2013 年财务回报的迹象。我有 2013 年到 2017 年的真实迹象,想比较一下。我尝试了不同的内核和参数,但没有任何变化。我想在我更改参数和内核之前应该先解决一些问题。

标签: r svm prediction


【解决方案1】:

好吧,我不确定您的哪些变量应该是类以及哪些数字。我认为目标是一个因素,其余的都是数字。在这种情况下,您可以尝试以下代码:

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)

【讨论】:

  • 非常感谢。现在我可以进一步调整模型,并且可以避免零符号。
猜你喜欢
  • 2018-11-01
  • 2012-03-03
  • 2019-02-15
  • 2018-10-29
  • 2017-07-09
  • 2011-12-08
  • 2016-02-21
  • 1970-01-01
  • 2016-05-13
相关资源
最近更新 更多