使用e1071库进行SVM预测

时间:2014-05-15 15:35:35

标签: r

我无法生成svm预测输出。我的预测输出是

pred 

   1    2    3    4    5    6    7    8    9 &lt;NA> &lt;NA> &lt;NA> &lt;NA> &lt;NA> &lt;NA> &lt;NA> <br>
   1    1    1    1    1    1    1    1    1    0    0    0    0    0    0    0 

我见过this post,它使用data.frame解释了预测数据与训练数据的形式相同。

我的R脚本就像:

library(e1071)
remove('dataset','predictdataset')
dataset <- read.csv("train.svm.toy", header=TRUE, sep = ",")
domain <- factor(dataset$domain)
sin <- c(dataset$SIN)
sout <- c(dataset$SOUT)
tin <- c(dataset$TIN)
tout <- c(dataset$TOUT)
sdiff <- c(dataset$SDIFF)
tdiff <- c(dataset$TDIFF)
d <- data.frame(domain=domain, sin=sin, sout=sout, tin=tin, tout=tout, sdiff=sdiff,     tdiff=tdiff)
model <- svm(domain~., data = d)
summary(model)
plot(model, d, sdiff ~ tdiff)
predictdataset <- read.csv("predict.svm.toy", header=TRUE, sep = ",")
predictsin <- c(predictdataset$SIN)
predictsout <- c(predictdataset$SOUT)
predicttin <- c(predictdataset$TIN)
predicttout <- c(predictdataset$TOUT)
predictsdiff <- c(predictdataset$SDIFF)
predicttdiff <- c(predictdataset$TDIFF)
pd <- data.frame(predictsin=predictsin, predictsout=predictsout, predicttin=predicttin,    predicttout=predicttout, predictsdiff=predictsdiff, predicttdiff=predicttdiff)
pred <- predict(model, newdata = pd)
pred

我曾尝试为预测功能创建data.frame。我错过了什么吗?谢谢!!

train.svm.toy的一些例子

domain,SIN,SOUT,TIN,TOUT,SDIFF,TDIFF
1,-31.4911,-47.4828,-31.7342,-42.9413,15.9917,11.2071
1,-105.581,-159.625,-88.5278,-150.69,54.044,62.1622
1,-37.4974,-56.6514,-43.2143,-52.7235,19.154,9.5092
1,-28.8387,-42.8393,-30.5978,-41.0784,14.0006,10.4806
1,-68.8666,-106.493,-54.4614,-86.6813,37.6264,32.2199
1,-21.0252,-29.703,-20.5301,-28.2409,8.6778,7.7108
1,-13.4333,-32.1238,-12.4648,-22.1103,18.6905,9.6455
1,-22.352,-26.9923,-21.44,-32.0919,4.6403,10.6519
1,-29.1356,-49.6736,-33.7753,-45.9696,20.538,12.1943
0,-29.8119,-15.5169,-20.7282,-17.9644,-14.295,-2.7638
0,-34.1132,-17.6743,-86.862,-66.6868,-16.4389,-20.1752
0,-35.2737,-20.2432,-39.3511,-33.178,-15.0305,-6.17310000000001
0,-98.3206,-68.21,-95.6716,-72.9148,-30.1106,-22.7568
0,-63.9441,-31.0307,-104.095,-74.7338,-32.9134,-29.3612
0,-136.94,-71.1113,-124.173,-70.414,-65.8287,-53.759
0,-42.574,-25.222,-25.7445,-15.7581,-17.352,-9.9864
0,-121.553,-85.1123,-91.9655,-69.4457,-36.4407,-22.5198
0,-48.8836,-36.1291,-39.6271,-28.0703,-12.7545,-11.5568
0,-71.6173,-51.2642,-49.7612,-32.7842,-20.3531,-16.977

和predict.svm.toy的一些例子

SIN,SOUT,TIN,TOUT,SDIFF,TDIFF
-3.78448,-4.2665,-6.93687,-6.92776,0.48202,-0.00910999999999973
-3.78448,-4.2665,-3.63614,-3.86814,0.48202,0.232
-6.02556,-4.80424,-6.38996,-4.73813,-1.22132,-1.65183
-2.93217,-3.36024,-2.76268,-3.41638,0.42807,0.6537
-4.52705,-5.51546,-2.76268,-3.41638,0.98841,0.6537
-106.789,-73.5714,-128.035,-21.916,-33.2176,-106.119
-53.1614,-50.3327,-42.5921,-33.0569,-2.8287,-9.5352
-52.0939,-61.5176,-47.491,-53.1075,9.4237,5.6165
-88.4115,-86.5202,-94.8392,-78.2452,-1.8913,-16.594

感谢您的时间。问题已经解决:见下文。

1 个答案:

答案 0 :(得分:1)

感谢您的时间。问题已经通过改变

解决了
data.frame(predictsin=predictsin, predictsout=predictsout, predicttin=predicttin,    predicttout=predicttout, predictsdiff=predictsdiff, predicttdiff=predicttdiff)

data.frame(sin=predictsin, sout=predictsout, tin=predicttin,    tout=predicttout, sdiff=predictsdiff, tdiff=predicttdiff)

这是由于&#34;这些参数是表单值或tag = value。组件名称是根据标签(如果存在)或去除的参数本身创建的。&#34;。 [参考文献] [2]。