我想用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