Using neuralnet with caret train and adjusting the parameters

后端 未结 2 2104
情深已故
情深已故 2021-01-06 12:15

So I\'ve read a paper that had used neural networks to model out a dataset which is similar to a dataset I\'m currently using. I have 160 descriptor variables that I want to

2条回答
  •  长发绾君心
    2021-01-06 12:59

    I think for beginners it's not obvious at all that the layer specification cannot be passed directly into the train function.

    One must read the documentation very carefully to understand the following passage for ...: Errors will occur if values for tuning parameters are passed here.

    So first, you must realize that the hidden parameter of the neuralnet::neuralnet is defined as a tuning parameter and therefore may not be passed directly to the train function (by ...). You find the tuning parameter definitions by:

    getModelInfo("neuralnet")$neuralnet$parameters
      parameter   class                    label
    1    layer1 numeric #Hidden Units in Layer 1
    2    layer2 numeric #Hidden Units in Layer 2
    3    layer3 numeric #Hidden Units in Layer 3
    

    Instead, you must pass the hidden layer definition by the tuneGrid parameter - not obvious at all because that is normally reserved for tuning the parameters, not passing them.

    So you can define the hidden layers as follows:

    tune.grid.neuralnet <- expand.grid(
      layer1 = 10,
      layer2 = 10,
      layer3 = 10
    )
    

    and then pass that to the caret::train function call as:

      model.neuralnet.caret <- caret::train(
        formula.nps,
        data = training.set,
        method = "neuralnet",
        linear.output = TRUE, 
        tuneGrid = tune.grid.neuralnet, # cannot pass parameter hidden directly!!
        metric = "RMSE",
        trControl = trainControl(method = "none", seeds = seed)
    

提交回复
热议问题