早上好,
我目前正在尝试运行回归神经网络,使用数据集上的“rnn”包,名为BostonHousing的数值;具体来说,这是结构:
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1038 obs. of 3 variables:
$ date : Date, format: "2013-11-19" "2013-11-20" "2013-11-21" "2013-11-22" ...
$ Quantità : num 0.85 0.85 -0.653 -0.653 -0.653 ...
$ Giacenza_In: num 0.945 1.648 -0.694 -0.694 -0.694 ...
#Split into train and test
cutoff = round(0.8*nrow(BostonHousing))
train_x <- BostonHousing[1:cutoff,]
test_x <- BostonHousing[-(1:cutoff),]
str(train_x)
#I apply the model and remove the first column because it's made up of dates
require(rnn)
model <- trainr( Y = train_x[,2],
X = train_x[,3],
learningrate = 0.05,
hidden_dim = 4,
numepochs = 100)
pred <- predictr( model, test_x[,3])
每当我尝试运行代码时,它都会给出标题中报告的错误。
基本上,我想预测“Quantità”(这意味着订购的数量),给定当前库存的产品数量(Giacenza_In)
最诚挚的问候,亚历山德罗
答案 0 :(得分:0)
似乎包rnn中的trainr需要二进制格式的输入和输出值。因此,您必须使用“ int2bin ”
转换每列因此,首先必须将数值转换为整数值(使用舍入乘以10 ^ n)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1038 obs. of 3 variables:
$ date : Date, format: "2013-11-19" "2013-11-20" "2013-11-21" "2013-11-22" ...
$ Quantità : num 0.85 0.85 -0.653 -0.653 -0.653 ...
$ Giacenza_In: num 0.945 1.648 -0.694 -0.694 -0.694 ...
#Split into train and test
cutoff = round(0.8*nrow(BostonHousing))
train_x <- BostonHousing[1:cutoff,]
test_x <- BostonHousing[-(1:cutoff),]
str(train_x)
#I apply the model and remove the first column because it's made up of dates
n<-5 #Number of decimal values
require(rnn)
model <- trainr( Y = int2bin(round(train_x[,2])*10^n),
X = int2bin(round(train_x[,3])*10^n),
learningrate = 0.05,
hidden_dim = 4,
numepochs = 100)
pred <- predictr( model, int2bin(round(test_x[,3])-10^n))
pred[pred>=0.5]<-1
pred[pred<0.5]<-0
然后你必须再次将二进制值转换为整数