R: Error in nrow[w] * ncol[w] : non-numeric argument to binary operator, while using neuralnet package

后端 未结 4 1932
暖寄归人
暖寄归人 2020-12-16 06:26

I am using neuralnet package for training a classifier. The training data looks like this:

> head(train_data)
   mvar_12      mvar_40 v10       mvar_1            


        
4条回答
  •  不思量自难忘°
    2020-12-16 07:17

    I just came up against the very same problem. Checking the source code of the compute function we can see that it assumes one of the resulting attributes (i.e. weights) only defined when the network finishes the training flawless.

    > trace("compute",edit=TRUE)
    function (x, covariate, rep = 1) {
        nn <- x
        linear.output <- nn$linear.output
        weights <- nn$weights[[rep]]
        [...]
    }
    

    I think the real problem lies on the fact that neuralnet doesn't save the current network once reached the stepmax value, causing this error later in the compute code.

    Edit

    It seems you can avoid this reset by commenting lines 65 & 66 of the calculate.neuralnet function

    > fixInNamespace("calculate.neuralnet", pos="package:neuralnet")
    [...]
    #if (reached.threshold > threshold) 
    #    return(result = list(output.vector = NULL, weights = NULL))
    [...]
    

    Then everything works as a charm :)

提交回复
热议问题