Jj No
Jj No

Reputation: 61

Neuralnet library in R gives different output every time

I am trying to run a neural network in R using the neuralnet library and every time I run it, it gives me different results. Often it says 'the algorithm did not converge'. I have tried varying the amount of hidden layers, the threshold, the repetitions and nothing seems to work. My dataset is about 1100 rows, across 41 columns, and I am trying to use 40 of the columns to predict the 41st. Does anyone have any advice? Here is the code for the implementation I am currently using:-

n <- names(train1)
f <- as.formula(paste("RESULT ~", paste(n[!n %in% "RESULT"], collapse = " + "))) 
nn <- neuralnet(f, data=train1, hidden=4,linear.output=FALSE, threshold = 0.1, rep=3)

Whereby train1 is my data set. Any help would be greatly appreciated!

Upvotes: 0

Views: 1296

Answers (1)

cdeterman
cdeterman

Reputation: 19970

You get a different result because the weights are randomly generated each time. If you want the exact same results you need to set a seed (?set.seed) or provide a set of weights yourself (the 'startweights' argument).

Upvotes: 2

Related Questions