tests/testthat/test-compute_fme.R

testthat::test_that("FME computation correct", {

  library(mlr3verse)
  library(rpart)

  n = 100
  x = runif(n, -5, 5)
  y = x^2
  df = data.frame(x, y)
  tree = lrn("regr.rpart")$train(as_task_regr(x = df, id = "df", target = "y"))

  step = 2
  df.forward = df
  df.forward$x = df.forward$x + step

  fme.manual = predict(tree, df.forward) - predict(tree, df)

  fme.results = fme(model = tree,
                    data = df,
                    features = list("x" = 2),
                    ep.method = "none")

  testthat::expect_equal(fme.results$results$fme, fme.manual)
})

Try the fmeffects package in your browser

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

fmeffects documentation built on June 22, 2024, 9:32 a.m.