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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
cat("FilterWrapper")
test_that("FilterWrapper", {
lrn1 = makeLearner("classif.lda")
lrn2 = makeFilterWrapper(lrn1, fw.method = "FSelectorRcpp_information.gain",
fw.perc = 1)
m = train(lrn2, binaryclass.task)
expect_true(!inherits(m, "FailureModel"))
expect_equal(m$features, getTaskFeatureNames(binaryclass.task))
lrn2 = makeFilterWrapper(lrn1, fw.method = "FSelectorRcpp_information.gain",
fw.abs = 0L)
m = train(lrn2, binaryclass.task)
expect_equal(getLeafModel(m)$features, character(0))
expect_true(inherits(getLeafModel(m)$learner.model, "NoFeaturesModel"))
lrn2 = makeFilterWrapper(lrn1, fw.method = "FSelectorRcpp_information.gain",
fw.perc = 0.1)
res = makeResampleDesc("CV", iters = 2)
r = resample(lrn2, binaryclass.task, res)
expect_true(!any(is.na(r$aggr)))
expect_subset(r$extract[[1]][[1]], getTaskFeatureNames(binaryclass.task))
})
test_that("FilterWrapper univariate (issue #516)", {
lrn1 = makeLearner("classif.rpart")
lrn2 = makeFilterWrapper(lrn1, fw.method = "univariate.model.score",
fw.perc = 1)
m = train(lrn2, binaryclass.task)
expect_true(!inherits(m, "FailureModel"))
expect_equal(m$features, getTaskFeatureNames(binaryclass.task))
})
test_that("Filterwrapper permutation.importance (issue #814)", {
lrn1 = makeLearner("classif.rpart")
lrn2 = makeFilterWrapper(lrn1, fw.method = "permutation.importance",
imp.learner = "classif.rpart", fw.perc = 1L, nmc = 1L)
m = train(lrn2, binaryclass.task)
res = makeResampleDesc("CV", iters = 2)
r = resample(lrn2, binaryclass.task, res)
expect_true(!any(is.na(r$aggr)))
expect_subset(r$extract[[1]][[1]], getTaskFeatureNames(binaryclass.task))
})
test_that("FilterWrapper with ensemble function in a train call", {
# FSelector not avail
skip_on_os("windows")
lrn = makeLearner("classif.lda")
# no base.method as ensemble method if fw.base.methods !is.null
expect_error(makeFilterWrapper(lrn, fw.method = "FSelectorRcpp_gain.ratio",
fw.base.methods = c("FSelectorRcpp_gain.ratio",
"FSelectorRcpp_information.gain")))
# no ensemble methods in base.methods
expect_error(makeFilterWrapper(lrn, fw.method = "E-min",
fw.base.methods = c("E-min", "information.gain")))
# multiple fw.methods are not allowed when creating a filter.wrapper ->
# multiple inputs need to be specified in the par.set
expect_error(makeFilterWrapper(lrn, fw.method = c("FSelector_chi.squared",
"FSelectorRcpp_information.gain")))
lrn2 = makeFilterWrapper(lrn, fw.method = "E-min",
fw.base.methods = c("FSelector_chi.squared",
"FSelectorRcpp_information.gain"),
fw.perc = 0.43)
# this must also work -> base.methods can be given in the par.set
expect_silent(makeFilterWrapper(lrn, fw.method = "E-min", fw.perc = 0.43))
m = train(lrn2, binaryclass.task)
expect_class(m, c("FilterModel", "BaseWrapperModel", "WrappedModel"))
})
|