【问题标题】:Out-of-sample Neural Networks or One-Step Forecasting RNN样本外神经网络或一步预测 RNN
【发布时间】:2017-07-29 03:42:13
【问题描述】:

我一直在对机器学习模型的预测进行大量研究,特别是多输入神经网络。当 y+1 不存在时,如何在测试集中预测(或在这种情况下预测)y+1?下面,我有 1 月 1 日到 1 月 10 日。如何预测 1 月 11 日?

我已经尝试了预测包中的拟合函数,它只适用于时间序列对象。预测功能只给我 1 月 10 日的值,而不是 11 日。我可以将数据框转换为 STL 对象,但不确定它是否会在我的预测之上应用进一步的预测方法。

任何想法或帮助将不胜感激。

谢谢。

library(rnn)
library(zoo)

#Create random dataframe and date column, then merge
df <- data.frame(replicate(3,sample(0:5,10,rep=TRUE)))
Date = seq(from = as.Date("2017-01-01"), to = as.Date("2017-01-10"), by = 'day')
df <- cbind(df, Date)
colnames(df)[1] <- "y"
df

#Create TS dataframe
ts.df <- ts(df, start = c(2017, 01), end = c(2017, 10), frequency = 1)

# Create zoo object so it works well... has time index
df <- zoo(ts.df); rm(ts.df)

#Remove Date from zoo object, as it is already indexed
df$Date <- NULL

#Putting data in the appropriate rnn format
x1 <- as.matrix(df[,2]); x2 <- as.matrix(df[,3])
y <- as.matrix(df[,1])

#Split
n_train = 7
x1_train <- as.matrix(t(x1[1:n_train,])); x2_train <- as.matrix(t(x2[1:n_train,]))
y_train <- as.matrix(y[1:n_train])

#Using the trainr function with rnn / requires the data to be in a 3d array 
x_train <- array(c(x1_train, x2_train), dim = c(dim(x1_train), 2))

#RNN 
set.seed(2018)

#Build Model
model2 <- trainr(Y = t(y_train), X = x_train,
                 learningrate = 0.1,
                 hidden_dim = 3,
                 numepochs = 50,
                 network_type = 'rnn',
                 epoch_function = c(epoch_print,epoch_annealing),
                 sigmoid = 'logistic')

# Preparing the test data
x1_test <- as.matrix(t(x1[(n_train + 1):nrow(x1),])); x2_test <- as.matrix(t(x2[(n_train + 1):nrow(x2),]))
y_test <- as.matrix(y[(n_train + 1):nrow(x1),])

#Using the testr function with rnn / requires the data to be in a 3d array 
x_test <- array(c(x1_test, x2_test), dim = c(dim(x1_test), 2))

#Creating the predictions 
pred_test <- t(predictr(model2, x_test))
pred_test

pred_test <- ts(matrix(pred_test), end = c(2017, 10), frequency = 1)

#This doesn't work, only gives me Jan 10th's value, not 11ths or 20ths..
forecast(pred_test, 10)

【问题讨论】:

  • 你的问题解决了吗?
  • 不,我没有解决问题

标签: r neural-network forecasting recurrent-neural-network extrapolation


【解决方案1】:

您必须使用 vanilla RNN(循环网​​络)来理解这种更适合序列、序列分析的新型神经网络。 了解递归的概念(新状态取决于先前的状态等...)可以在 LSTM 之后选择... Vanilla RNN 足以满足您的情况。

【讨论】:

  • 你没有阅读脚本,这是一个“普通的 RNN”。为什么还要提出 LSTM?没有足够的数据量来证明使用 LSTM 是合理的。
  • 尝试一个循环,时间 t 的预测(输出)将是时间 t+1 等的输入...
  • 错误遗留
猜你喜欢
  • 2018-09-19
  • 2012-05-06
  • 2018-05-18
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 2019-10-12
  • 2017-12-02
相关资源
最近更新 更多