tests/testthat/test-history.R

context("history")


test_succeeds("as.data.frame works for history with early stopping", {

  early_stop <- callback_early_stopping(monitor = "loss", patience = 1)

  model <- keras_model_sequential() %>%
    layer_dense(1, input_shape = 1)

  model %>% compile(loss = "mse", optimizer = "adam")

  x = matrix(runif(100), ncol = 1)

  history <- model %>% fit(
    x = x,
    y = x[,1] + rnorm(100, 0.1),
    epochs = 500,
    validation_split = 0.2,
    verbose = 0,
    callbacks = list(early_stop)
  )

  expect_error(
    d <- as.data.frame(history),
    regexp = NA
  )

  expect_error(
    plot(history),
    regexp = NA
  )

})

Try the keras package in your browser

Any scripts or data that you put into this service are public.

keras documentation built on Aug. 21, 2021, 9:07 a.m.