You should use caret's "mlpML" method insted of "mlp". It do uses mlp function from RSNNS, but you are able to define the number of neurons per hidden layer separately. For instance, the following code should do the work. You define your customized grid with the definition of your layers, each layer (1
, 2
, and 3
) and how many neurons per layer.
mlp_grid = expand.grid(layer1 = 10,
layer2 = 10,
layer3 = 10)
mlp_fit = caret::train(x = train_x,
y = train_y,
method = "mlpML",
preProc = c('center', 'scale', 'knnImpute', 'pca'),
trControl = trainControl(method = "cv", verboseIter = TRUE, returnData = FALSE),
tuneGrid = mlp_grid)
Given the verboseIter=TRUE
it shows that the values were indeed applied
+ Fold01: layer1=10, layer2=10, layer3=10
+ Fold02: layer1=10, layer2=10, layer3=10
+ Fold03: layer1=10, layer2=10, layer3=10
...