title: Setting hidden layers and neurons in neuralnet and caret (R)
body: <p>I would like to cross-validate a neural network using the package <code>neuralnet</code> and <code>caret</code>.</p>
  
  <p>The data <code>df</code> can be copied from <a href="https://stackoverflow.com/questions/62120412/neural-network-problems-when-more-than-one-dependent-variables-in-r-neuralnet">this post</a>. </p>
  
  <p>When running the <code>neuralnet()</code> function, there is an argument called <code>hidden</code> where you can set the hidden layers and neurons in each. Let's say I want 2 hidden layers with 3 and 2 neurons respectively. It would be written as <code>hidden = c(3, 2)</code>.</p>
  
  <p>However, as I want to cross-validate it, I decided to use the fantastic <code>caret</code> package. But when using the function <code>train()</code>, I do not know how to set the number of layers and neurons.</p>
  
  <p>Does anyone know where can I add these numbers?</p>
  
  <p>This is the code I ran:</p>
  
  <pre><code>nn &lt;- caret::train(DC1 ~ ., data=df, 
                     method = "neuralnet", 
                     #tuneGrid = tune.grid.neuralnet,
                     metric = "RMSE",
                     trControl = trainControl (
                       method = "cv", number = 10,
                       verboseIter = TRUE
  ))
  </code></pre>
  
  <p>By the way, I am getting some warnings with the previous code:</p>
  
  <pre><code>predictions failed for Fold01: layer1=3, layer2=0, layer3=0 Error in cbind(1, pred) %*% weights[[num_hidden_layers + 1]] : 
    requires numeric/complex matrix/vector arguments
  </code></pre>
  
  <p>Ideas on how to solve it?</p>