You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/08/01 18:35:54 UTC

[GitHub] thirdwing commented on issue #7127: How to use regularization for a feed forward neural network in R using mxnet?

thirdwing commented on issue #7127: How to use regularization for a feed forward neural network in R using mxnet? 
URL: https://github.com/apache/incubator-mxnet/issues/7127#issuecomment-319458466
 
 
   I think weight decay is what you are looking for.
   
   A small example is given below. You can just add `wd` in `mx.model.FeedForward.create`.
   
   ```r
   require(mlbench)
   require(mxnet)
   
   data(BostonHousing, package = "mlbench")
   
   train.ind <- seq(1, 506, 3)
   train.x <- data.matrix(BostonHousing[train.ind,-14])
   train.y <- BostonHousing[train.ind, 14]
   test.x <- data.matrix(BostonHousing[-train.ind,-14])
   test.y <- BostonHousing[-train.ind, 14]
   
   data <- mx.symbol.Variable("data")
   fc1 <- mx.symbol.FullyConnected(data, num_hidden = 1)
   lro <- mx.symbol.LinearRegressionOutput(fc1)
   
   mx.set.seed(0)
   model <- mx.model.FeedForward.create(lro,
                                        X = train.x,
                                        y = train.y,
                                        ctx = mx.cpu(),
                                        num.round = 50,
                                        array.batch.size = 20,
                                        optimizer = "sgd",
                                        learning.rate = 2e-6,
                                        momentum = 0.9,
                                        wd = 0.1,
                                        eval.metric = mx.metric.rmse)
   ```
   
   Sorry for the lack of document.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services