9

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.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Sam
  • 191
  • 1
  • 12
  • 2
    I got it, It was due to the linout=TRUE which need to use for continuous response variable. 'nnet.fit <- nnet(medv/50 ~ ., data=BostonHousing, size=10, linout=TRUE, skip=TRUE, MaxNWts=10000, trace=FALSE, maxit=100) ' This line did the job. – Sam Apr 26 '15 at 22:28
  • 1
    Great -- good to see you solved your problem! I would encourage you to answer your own question with the "Post Your Answer" button below so others can easily see the answer easily when they visit Stack Overflow. – josliber Apr 26 '15 at 22:42
  • @josilber - Done, thanks for telling me, was new in this platform so didn't knew. – Sam Apr 26 '15 at 23:12

1 Answers1

10

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.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Sam
  • 191
  • 1
  • 12