SVM 图未显示
SVM plot not showing
为什么剧情没有出现?也没有报错过来。
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))
我认为响应变量 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)
为什么剧情没有出现?也没有报错过来。
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))
我认为响应变量 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)