tests/testthat/test_explain_and_shap.R

context("Tests functions explain and shap.")

test_that("functions explain and shap give previous results", {
  set.seed(42)
  airq.ens <- pre(Ozone ~ ., data=airquality, ntrees = 10)
  expl <- explain(airq.ens, newdata = airquality, deprecation.message = FALSE)
  # save_to_test(expl, "explain")
  expect_equal(expl, read_to_test("explain"))

  SHAP <- shap(airq.ens, newdata = airquality[1:10, ], reference_data = airquality)  
  # save_to_test(SHAP$marginal, "SHAP_marginal")
  expect_equal(SHAP$marginal, read_to_test("SHAP_marginal"))
  # save_to_test(SHAP$interactions, "SHAP_interact")
  expect_equal(SHAP$interactions, read_to_test("SHAP_interact"))
})

Try the pre package in your browser

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

pre documentation built on Sept. 1, 2026, 1:06 a.m.