【发布时间】:2016-10-03 17:02:13
【问题描述】:
我想在 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
【问题讨论】:
-
你已经有什么代码了?
-
这是他的代码。我使用 48 个值训练模型,但我希望模型只预测 24 个值
-
我建议您不要使用当前用于输入数据的方法。设置两个
data.frames,它们是你的训练和测试/验证集,最初只提供训练集,当你调用predict时,然后使用第二个data.frame。您当前的方法在您的环境中有冗余信息。
标签: r machine-learning forecasting