【问题标题】:Error in Y * 0: non numeric argument to binary operator - RNNY * 0 中的错误:二元运算符的非数字参数 - RNN
【发布时间】:2018-05-04 17:35:36
【问题描述】:

早安,

我目前正在尝试运行用于回归的递归神经网络,在数据集上使用包“rnn”,称为数值波士顿房屋;具体来说,这是结构:

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])

每当我尝试运行代码时,它都会给我标题中报告的错误。

基本上,考虑到当前库存的产品数量(Giacenza_In),我想预测“Quantità”(意思是订购的数量)

最好的问候,亚历山德罗

【问题讨论】:

    标签: r rnn


    【解决方案1】:

    似乎 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
    

    然后你必须再次将二进制值转换为整数

    【讨论】:

    • 简单来说,我将每个输入标准化,然后分成训练集和测试集;因为我试图预测一个数量。为什么当我尝试运行 predictr(model, int2bin...) 时它只显示 8 个值?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    相关资源
    最近更新 更多