[R] Issues with nnet.default for regression/classification

Georg Ruß research at georgruss.de
Mon Nov 29 19:37:29 CET 2010


On 29/11/10 11:57:31, Jude Ryan wrote:
>    Hi Georg,
>
>
>    The documentation (?nnet) says that y should be a matrix or data frame,
>    but in your case it is a vector. This is most likely the problem, if
>    you do not have other data issues going on. Convert y to a matrix (or
>    data frame) using ‘as.matrix’ and see if this solves your problem.
>    Library ‘nnet’ can do both classification and regression. I was able to
>    replicate your problem, using an example from Modern Applied Statistics
>    with S, Venables and Ripley, pages 246 and 247), by turning y into a
>    vector and verifying that all the predicted values are the same when y
>    is a vector. This is not the case when y is part of a data frame. You
>    can see this by running the code below. I tried about 4 neural network
>    packages in the past, including AMORE, but found ‘nnet’ to be the best
>    for my needs.

Hi Jude,

thanks for the hint. I lately experimented both with the nnet(x,y, ...)
and the nnet(formula, dataframe ...) interfaces to nnet and both yielded
the same results. So changing the format of y from a vector to a matrix or
a data frame didn't change anything at all. However, what _did_ change the
outcome is to introduce the "decay" parameter (which I didn't have at all
before). By default it is set to 0 which doesn't seem appropriate in my
case. Setting it to "decay=1e-3" magically turned my output into an
acceptable regression response instead of spitting out fixed values.

I really love the predict interface for regression in each of the models
I'm using. Clear code :-)

So, for the record, the call for nnet for the regression problem is as
follows:

net.fitted <- nnet(formula, data = sppdf at data[-testset,], decay=1e-3, size = 20, linout = TRUE)

(where sppdf at data is the data part of a SpatialPointsDataFrame. And yes,
in selecting the [-testset,] data points I'm taking into account the existing
spatial autocorrelation.)

>    # Neural Network model in Modern Applied Statistics with S, Venables
>    and Ripley, pages 246 and 247

Thanks for your help and the reference, I'm likely to order the book now
:-) Leaving out the "decay" parameter changes the fitted.values in the
"rock" example you mentioned as well, although not that much. Convergence
speed does change as expected, so the parameter is working. I guess my
problem is solved now, the rest is due to the specialties with my data
sets.

Georg.
-- 
Research Assistant
Otto-von-Guericke-Universität Magdeburg
research at georgruss.de
http://research.georgruss.de



More information about the R-help mailing list