nnet performing better than kerasR, what could be wrong in defining keras model

Hello everyone,

I am using a simple synthetic dataset to train neural network with one hidden layer and two neurons.

  1. But I am surprised to see that 'nnet' (in 'caret') performs better than 'kerasR'.
  2. I also used model agnostics such as pdp and ICE, which also suggest that nnet is able to recover the true data generation process better than keras.

Can someone please point out the mistake,

  1. Am I comparing 'apples' to 'oranges', using different epochs
  2. Am I using wrong optimization algorithm in kerasR

nnet code -

myControl <- caret::trainControl(## n-fold CV
method = "repeatedcv",
number = 5,
repeats = 1,
verboseIter = TRUE)

nnGrid <- expand.grid(size = 2,
decay = seq(0, 0.6, 0.1))

nnetFit <- caret::train(choice ~ .,
data = tbl,
method = "nnet",
tuneGrid = nnGrid,
trace = FALSE,
maxit = 1000,
trControl = myControl)

keras model -

model <- keras_model_sequential()

model %>%
layer_dense(units = 2, activation = "sigmoid", input_shape = ncol(train_x)) %>%
layer_dense(units = 1, activation = "sigmoid")

model %>% compile(
loss = "binary_crossentropy",
optimizer = "rmsprop",
metrics = c("accuracy")
)

model %>%
fit(train_x, train_y,
epochs = 400, batch_size = 64,
verbose = 0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.