File: test_featsel_fselectorrcpp.R

package info (click to toggle)
r-cran-mlr 2.19.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,392 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (29 lines) | stat: -rwxr-xr-x 1,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

test_that("filterFeatures_fselectorrcpp", {
  a = c(1, 2, 5.3, 6, -2, 4, 8.3, 9.2, 10.1) # numeric vector
  b = c("one", "two", "three") # character vector
  c = c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE) # logical vector
  d = c(1L, 3L, 5L, 7L, 9L, 17L)
  f = rep(c("c1", "c2"), 9)
  df = data.frame(a = a, b = b, c = c, d = d, f = f)
  df = convertDataFrameCols(df, logicals.as.factor = TRUE, chars.as.factor = TRUE)
  task = makeClassifTask(data = df, target = "f")

  candidates = as.character(listFilterMethods()$id)
  candidates = candidates[startsWith(candidates, "FSelectorRcpp")]
  for (candidate in candidates) {
    fv = generateFilterValuesData(task, method = candidate, nselect = 2L)
    expect_class(fv, "FilterValues")
    expect_data_frame(fv$data, nrow = getTaskNFeats(task))
    expect_set_equal(fv$data$name, getTaskFeatureNames(task))
    expect_numeric(fv$data$value, any.missing = FALSE, finite = TRUE)
  }

  lrn = makeLearner("classif.rpart")
  lrn = makeFilterWrapper(learner = lrn,
    fw.method = "FSelectorRcpp_information.gain", fw.perc = 0.1)
  res = resample(learner = lrn, task = binaryclass.task, resampling = cv3,
    measures = list(mmce, timetrain), extract = getFilteredFeatures,
    show.info = FALSE)
  expect_length(res$extract[[1L]], 6)
})