I am trying to predict median value of owner-occupied homes, its a worked example which is giving a good result.
https://heuristically.wordpress.com/2011/11/17/using-neural-network-for-regression/
library(mlbench)
data(BostonHousing)
require(nnet)
# scale inputs: divide by 50 to get 0-1 range
nnet.fit <- nnet(medv/50 ~ ., data=BostonHousing, size=2)
# multiply 50 to restore original scale
nnet.predict <- predict(nnet.fit)*50
nnet.predict
[,1]
1 23.70904
2 23.70904
3 23.70904
4 23.70904
5 23.70904
6 23.70904
7 23.70904
8 23.70904
9 23.70904
10 23.70904
11 23.70904
12 23.70904
13 23.70904
14 23.70904
15 23.70904
I am getting 23.70904 same value for all the predict for all 506 observations ? Why is it so ? What is that I am doing wrong ?
My R version is 3.1.2.
It was due to the linout = TRUE
which need to use for continuous response variable.As I was using nnet for a regression (rather than a classification) problem I needed to set linout = TRUE
to tell nnet to use a linear output '
nnet.fit <- nnet(medv/50 ~ ., data=BostonHousing, size=10, linout=TRUE, skip=TRUE, MaxNWts=10000, trace=FALSE, maxit=100)
This worked well for me, hope it helps.