【问题标题】:SVM plot not showingSVM 图未显示
【发布时间】:2015-04-27 05:33:45
【问题描述】:

为什么剧情没有出现?也没有错误。

usd28 = read.csv("~/ICICI_nse_train_head")
usd30= usd28[1:2000,]

index<-1:nrow(usd30)
testindex<-sample(index,trunc(length(index)/3))
testset<-usd30[testindex,]
trainset<-usd30[-testindex,]
svm.model<-svm(sprd_cross_dir~bid_sprd0+ask_sprd0,data=trainset,cost=5,gamma=1)
svm.pred<-predict(svm.model,testset)
summary(svm.model)
x<-table(pred=svm.pred,true=testset$sprd_cross_dir)
plot(x=svm.model,data=trainset,formula =sprd_cross_dir~bid_sprd0+ask_sprd0 ,fill=TRUE)

数据是

   ask_sprd0 bid_sprd0 sprd_cross_dir
           5         5              0
          65         5              0
          65         5              0
          10        15              0
          20         5              0
          20         5              1
          20        10              1
          20        10              1
          20        10              0
          20        10              0
          20         5              0
          10        15              0
          20         5              0
          20         5              1
          20        10              1
          20        10              1
          20        10              0
          20        10              0
          20         5              1
          20        10              1
          20        10              1
          25        10              0
          10        15             -1
          25        15              0
          25         5              0
          10        15             -1
          10        15             -1
          25        15              1

dput()版本:

structure(list(ask_sprd0 = c(5L, 65L, 65L, 10L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 10L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 25L, 10L, 25L, 25L, 10L, 10L, 25L), bid_sprd0 = c(5L, 5L, 
5L, 15L, 5L, 5L, 10L, 10L, 10L, 10L, 5L, 15L, 5L, 5L, 10L, 10L, 
10L, 10L, 5L, 10L, 10L, 10L, 15L, 15L, 5L, 15L, 15L, 15L), sprd_cross_dir = c(0, 
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 
-1, 0, 0, -1, -1, 1)), .Names = c("ask_sprd0", "bid_sprd0", "sprd_cross_dir"
), class = "data.frame", row.names = c(NA, -28L))

【问题讨论】:

    标签: r plot svm


    【解决方案1】:

    我认为响应变量sprd_cross_dir 应该是因素:

    require(e1071)
    
    #dummy data
    usd28  <- structure(list(ask_sprd0 = c(5L, 65L, 65L, 10L, 20L, 20L, 20L, 
                                 20L, 20L, 20L, 20L, 10L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
                                 20L, 25L, 10L, 25L, 25L, 10L, 10L, 25L), bid_sprd0 = c(5L, 5L, 
                                                                                        5L, 15L, 5L, 5L, 10L, 10L, 10L, 10L, 5L, 15L, 5L, 5L, 10L, 10L, 
                                                                                        10L, 10L, 5L, 10L, 10L, 10L, 15L, 15L, 5L, 15L, 15L, 15L), sprd_cross_dir = c(0, 
                                                                                                                                                                      0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 
                                                                                                                                                                      -1, 0, 0, -1, -1, 1)), .Names = c("ask_sprd0", "bid_sprd0", "sprd_cross_dir"
    usd30 = usd28
    #change response variable to factor
    usd30$sprd_cross_dir <- as.factor(usd30$sprd_cross_dir)
    
    index<-1:nrow(usd30)
    testindex<-sample(index,trunc(length(index)/3))
    testset<-usd30[testindex,]
    trainset<-usd30[-testindex,]
    
    svm.model<-svm(sprd_cross_dir~bid_sprd0+ask_sprd0,data=trainset,cost=5,gamma=1)
    plot(svm.model,data=trainset,fill=TRUE)
    

    【讨论】:

      猜你喜欢
      • 2016-02-13
      • 2018-07-27
      • 1970-01-01
      • 2017-11-14
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      相关资源
      最近更新 更多