BestModel <- neuralnet(formula = f,
data = train_df, # available in one of the links above
hidden = c(3,2,4) # random neurons per layer
learningrate = 0.01,
threshold = 0.01,
stepmax = 50000
)
Using train() (caret)
This is the code (all the parameters are available in this question):
model <- train(f, data = predict(pre_mdl_df, train_df),
method = "neuralnet",
tuneGrid = tune.grid.neuralnet,
metric = "RMSE",
stepmax = 100000,
learningrate = 0.01,
threshold = 0.01,
act.fct = softplus,
trControl = caret::trainControl (
method = "repeatedcv",
number = 2, # Number of folds of the cv
repeats = 1, # Number of cv repetitions
verboseIter = TRUE,
savePredictions = TRUE,
allowParallel = TRUE))
Here, we store as finalModel the final and best model obtained in the training:
finalModel <- model$finalModel
Comparison of the outputs from neuralnet() and train()
Different structures
neuralnet(): str(BestModel) is a List of 14.
train(): str(FinalModel) is a List of 19
Different responses:
As you can see, the response from neuralnet() is having chr [1:3] "DC1" "DC2" "DC3", whereas from train() has chr ".outcome". I guess this will impact the results later, because the prediction will return different quantity of results.
This is something very tricky and is related with other questions I did in StackOverflow (1, 2, 3). The data to use is in 1.
Basically, I am comparing two neural network trainings:
neuralnet()
from theneuralnet
package.train()
from thecaret
package, and includingmethod = "neuralnet"
.The same formula in both models
In both cases, in the arguments to introduce the formula:
f <- as.formula(paste("DC1 + DC2 + DC3 ~", paste(n[!n %in% c("DC1","DC2","DC3")], collapse = " + ")))
If we see its structure, you can see that there are three DEPENDENT VARIABLES (
DC1
,DC2
,DC3
)Using
neuralnet()
(neuralnet)This is the code
Using
train()
(caret)This is the code (all the parameters are available in this question):
Here, we store as
finalModel
the final and best model obtained in the training:Comparison of the outputs from
neuralnet()
andtrain()
Different structures
neuralnet()
:str(BestModel)
is a List of 14.train()
:str(FinalModel)
is a List of 19Different responses:
As you can see, the response from
neuralnet()
is havingchr [1:3] "DC1" "DC2" "DC3"
, whereas fromtrain()
haschr ".outcome"
. I guess this will impact the results later, because the prediction will return different quantity of results.Different model lists
Different plots
neuralnet()
: as expected, with three outputs representing the three dependent variables (DC1
,DC2
,DC3
).train()
: only one output,.outcome
.Different prediction variables
I expect to predict the three variables simultaneously, as it happens with
neuralnet()
but not withtrain()
, that returns only one.Key questions
After comparing both models, which were supposed to behave similarly, several questions come to my mind:
train()
to work similarly asneuralnet()
? This includes the plots and predictions.train()
?train()
?.outcome
to have the three dependent variables?Please, I need help!