2
$\begingroup$

I'm trying to understand some basics of neural nets and am trying to build one that can predict the function $y = 2*x$ in R:

library(caret)
library(nnet)

v1 <- 1:1000
v2 <- v1 * 2
df <- data.frame(v1, v2)

mod <- train(v2 ~ v1, data = df, method = "nnet")
predict(mod, df)

I end up getting all 1's for the answers. I'm able to predict other, more complex functions using a neural net, but, for some reason, I can't predict this function.

Does anyone happen to know why that might be?

Thank you!

Bill

$\endgroup$

closed as off-topic by whuber Jun 2 '16 at 1:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – whuber
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ The problem was that I was failing to specify the "linout" parameter as TRUE. Thanks to Alex R. for noticing this! $\endgroup$ – Bill Anderson Jun 1 '16 at 22:08
3
$\begingroup$

You need to specify "linout=TRUE" in the nnet, function as the default is logistic output. i.e.:

mod <- train(v2 ~ v1, data=df, method="nnet",linout=TRUE)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.