您的位置:首页 > 其它

SVM模型预测

2014-09-02 22:48 127 查看
library(e1071)
source <- c(10930,10318,10595,10972,7706,6756,9092,10551,9722,10913,11151,8186,6422,
6337,11649,11652,10310,12043,7937,6476,9662,9570,9981,9331,9449,6773,6304,9355,10477,
10148,10395,11261,8713,7299,10424,10795,11069,11602,11427,9095,7707,10767,12136,12812,
12006,12528,10329,7818,11719,11683,12603,11495,13670,11337,10232,13261,13230,15535,
16837,19598,14823,11622,19391,18177,19994,14723,15694,13248,9543,12872,13101,15053,
12619,13749,10228,9725,14729,12518,14564,15085,14722,11999,9390,13481,14795,15845,
15271,14686,11054,10395,14775,14618,16029,15231,14246,12095,10473,15323,15381,14947)
srcLen<-length(source)
for(i in 1:10){
real <- source[srcLen-i+1]
xNum=(srcLen-i+1)%/%7
yNum=7
data<-array(1:(xNum*yNum),c(xNum,yNum))

pre=srcLen-i+1;
for(x in 1:xNum){
for(y in 1:yNum){
data[x,y]=source[pre]
pre=pre-1;
}
if(pre<7){
break;
}
}
ascData<-array(1:(xNum*yNum),c(xNum,yNum))
for(x in 1:xNum){
for(y in 1:yNum){
ascData[x,y]=data[xNum-x+1,y]
}
}
colnames(ascData) <- c("a","b","c","d","e","f","g")

trainData<-data.frame(ascData)

nn<-svm(a~b+c+d+e+f+g,data=trainData[1:(xNum-1),])

predict<-predict(nn,trainData[xNum,])

percent <- (predict-real)*100/real

res <- paste("预测值:",predict,"实际值:",real,"误差:",percent)
print(res)
}


预测结果:

[1] "预测值: 15903.4179393 实际值: 14947 误差: 6.3987284358066"
[1] "预测值: 14512.9521578654 实际值: 15381 误差: -5.64363722862387"
[1] "预测值: 14385.6991495925 实际值: 15323 误差: -6.1169539281307"
[1] "预测值: 10110.2340088228 实际值: 10473 误差: -3.46382117041125"
[1] "预测值: 11455.4950069718 实际值: 12095 误差: -5.28735008704629"
[1] "预测值: 15189.6013117541 实际值: 14246 误差: 6.62362285381251"
[1] "预测值: 15518.4039237089 实际值: 15231 误差: 1.88696686828751"
[1] "预测值: 15667.3146679094 实际值: 16029 误差: -2.25644352168343"
[1] "预测值: 14004.8493543968 实际值: 14618 误差: -4.19449066632385"
[1] "预测值: 14298.0106360029 实际值: 14775 误差: -3.22835440945558"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: