我想用R.中的支持向量回归预测未来的能源消耗。我有这段代码,但我不确定天气是否正确。在R中使用支持向量回归进行预测
`#gathering the data
data<-read.csv("C:\\2003_smd_hourly.csv",header=TRUE) #these are the values which are used to train the given model#
data
#data1<-read.csv("C:\\pr.csv",header=TRUE)#this file/ddata is used for checking the accuracy of prediction#
#data1
#y1<-data1[,15]
#x0<-data1[,2]
y<-data[,15] #sysload
x1<-data[,2] #houroftheday
x2<-data[,13] #drybulb temp(actualtemp)
x3<-data[,14] #dewpnttemp
#train<-sample(744,447)
#train
library(e1071)
model<-svm(y~x1+x2+x3,data=data[1:48,],cost=2.52*10^11,epsilon=0.0150,gamma=1)
model
#pr<-data[-train,]
#pr
predict1<-predict(model,newdata=data[49:72,])
predict1
par(mfrow=c(2,2))
plot(x1,y,col="red",pch=4)
#par(new=TRUE)
plot(x1,predict1,col="blue",pch=5) #plotting the values that have been predicted
#par(new=TRUE)
plot(x0,y1,col="black",pch=1)
error=y1-predict1
error
mae <- function(error)
{
mean(abs(error))
}
mae(error)
error <- y1 - predict1
error
rmse <- function(error)
{
sqrt(mean(error^2))
}
svrPredictionRMSE <- rmse(error)
svrPredictionRMSE
max(error)
min(error)
mape <- function(y1,predict1)
mape
mean(abs((y1 - predict1)/y1))*100
mape
`如:数据可以在这里http://pastebin.com/MUfWFCPM
你有什么代码? – blacksite
这是他的代码。我使用48个值训练模型,但是我希望模型只预测24个值。 –
我会建议您使用当前输入数据的方法。当你调用'predict'然后使用第二个'data.frame'时,设置两个'data.frames',它们是你的训练和测试/验证集合,最初只提供训练集。您当前的方法在您的环境中有冗余信息。 – zacdav