tests/testthat/test_mlr_learners_clust_dbscan_fpc.R

skip_if_not_installed("fpc")

test_that("autotest", {
  learner = lrn("clust.dbscan_fpc", eps = 25)
  expect_learner(learner)
  result = run_autotest(learner)
  expect_true(result, info = result$error)
})

test_that("Learner properties are respected", {
  task = tsk("usarrests")
  learner = lrn("clust.dbscan_fpc", eps = 25)
  expect_learner(learner, task)

  # test on multiple paramsets
  parset_list = list(
    list(eps = 25),
    list(eps = 25, MinPts = 10),
    list(eps = 25, method = "hybrid")
  )

  for (i in seq_along(parset_list)) {
    parset = parset_list[[i]]
    learner$param_set$values = parset

    p = learner$train(task)$predict(task)
    expect_prediction_clust(p)

    if ("complete" %chin% learner$properties) {
      expect_prediction_complete(p, learner$predict_type)
    }
    if ("exclusive" %chin% learner$properties) {
      expect_prediction_exclusive(p, learner$predict_type)
    }
  }
})
mlr-org/mlr3cluster documentation built on Dec. 24, 2024, 3:19 a.m.