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
Becasue you never set startweights in the function neuralnet()
According to the documentation
neuralnet(formula, data, hidden = 1, threshold = 0.01,
stepmax = 1e+05, rep = 1, startweights = NULL,
learningrate.limit = NULL,
learningrate.factor = list(minus = 0.5, plus = 1.2),
learningrate=NULL, lifesign = "none",
lifesign.step = 1000, algorithm = "rprop+",
err.fct = "sse", act.fct = "logistic",
linear.output = TRUE, exclude = NULL,
constant.weights = NULL, likelihood = FALSE)
startweights a vector containing starting values for the weights. The weights will not be randomly initialized.
Note that the default value is NULL, and it will NOT be randomly initialized. Try to put something there and see if that works.
Try adjusting the threshold to a higher than 0.01 value or the stepmax to more than 1e06, or using a threshold of 0.1 and then decreasing it from there. You can also add in the lifesign = "full" argument to observe the model creation performance in increments of 1000 steps to really dial in the threshold. This "resolved" the non-binary error I had, but the accuracy of the model, the mean squared error, and other results were less than satisfying as a direct result.
Do a str(cv_data) and make sure they are all numeric.
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 :)