Format time-series data for short term forecasting using Recurrent Neural networks

穿精又带淫゛_ 提交于 2019-12-06 05:37:14

A few points:

  1. You need to have same # of samples in the input X and output Y in the training data to start with, in the above implementation you are having 1872 samples for X and 144 samples for Y. Moreover, your training array tx contains same column replicated 144 times, which does not make much sense.

  2. We can think of training a RNN or LSTM model in a few following ways: In the figure below Model1 tries to capture recurring patterns across the 10 minute time intervals where Model2 tries to capture the recurring pattern across the (previous) days.

# Model1
window <- 144
train <- df[1:(13*window),]$power
tx <- t(sapply(1:13, function(x) train[((x-1)*window+1):(x*window)]))
ty <- tx[2:13,]
tx <- tx[-nrow(tx),]
tx <-  array(tx,dim=c(NROW(tx),NCOL(tx),1))
ty <-  array(trainY,dim=c(NROW(ty),NCOL(ty),1))
model <- trainr(X=tx,Y=ty,learningrate = 0.01, hidden_dim = 10, numepochs = 100)
test <- sapply(2:13, function(x) train[((x-1)*window+1):(x*window)])
pred  <- predictr(model,X=array(test,dim=c(NROW(test),NCOL(test),1)))

# Model2
window <- 144
train <- df[1:(13*window),]$power
tx <- sapply(1:12, function(x) train[((x-1)*window+1):(x*window)])
ty <- train[(12*window+1):(13*window)]
tx <-  array(tx,dim=c(NROW(tx),NCOL(tx),1))
ty <-  array(trainY,dim=c(NROW(ty),1,1))
model <- trainr(X=tx,Y=ty,learningrate = 0.01, hidden_dim = 10, numepochs = 100, seq_to_seq_unsync=TRUE)
test <- sapply(2:13, function(x) train[((x-1)*window+1):(x*window)])
pred  <- predictr(model,X=array(test,dim=c(NROW(test),NCOL(test),1)))
  1. Your data is too small to train an RNN or a LSTM, compared to the feature size. That's why both the models trained are very very poor and unusable. You can try to collect more data and learn the models and then use them for prediction.

it suffices to change "seq-to-seq-unsync=TRUE" Hope useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!