R/FilterWrapper.R
Fuses a base learner with a filter method. Creates a learner object, which can be used like any other learner object. Internally uses filterFeatures before every model fit.
makeFilterWrapper(learner, fw.method = "randomForestSRC_importance", fw.base.methods = NULL, fw.perc = NULL, fw.abs = NULL, fw.threshold = NULL, fw.mandatory.feat = NULL, cache = FALSE, ...)
| learner | (Learner | |
|---|---|
| fw.method | ( |
| fw.base.methods | ( |
| fw.perc | ( |
| fw.abs | ( |
| fw.threshold | ( |
| fw.mandatory.feat | (character) |
| cache | ( |
| ... | (any) |
If ensemble = TRUE, ensemble feature selection using all methods specified
in fw.method is performed. At least two methods need to be selected.
After training, the selected features can be retrieved with getFilteredFeatures.
Note that observation weights do not influence the filtering and are simply passed down to the next learner.
If cache = TRUE, the default mlr cache directory is used
to cache filter values. The directory is operating system dependent and can
be checked with getCacheDir(). Alternatively a custom directory can be
passed to store the cache. The cache can be cleared with
deleteCacheDir(). Caching is disabled by default. Care should be taken
when operating on large clusters due to possible write conflicts to disk if
multiple workers try to write the same cache at the same time.
Other filter: filterFeatures,
generateFilterValuesData,
getFilteredFeatures,
listFilterEnsembleMethods,
listFilterMethods,
makeFilterEnsemble,
makeFilter, plotFilterValues
Other wrapper: makeBaggingWrapper,
makeClassificationViaRegressionWrapper,
makeConstantClassWrapper,
makeCostSensClassifWrapper,
makeCostSensRegrWrapper,
makeDownsampleWrapper,
makeDummyFeaturesWrapper,
makeExtractFDAFeatsWrapper,
makeFeatSelWrapper,
makeImputeWrapper,
makeMulticlassWrapper,
makeMultilabelBinaryRelevanceWrapper,
makeMultilabelClassifierChainsWrapper,
makeMultilabelDBRWrapper,
makeMultilabelNestedStackingWrapper,
makeMultilabelStackingWrapper,
makeOverBaggingWrapper,
makePreprocWrapperCaret,
makePreprocWrapper,
makeRemoveConstantFeaturesWrapper,
makeSMOTEWrapper,
makeTuneWrapper,
makeUndersampleWrapper,
makeWeightedClassesWrapper
task = makeClassifTask(data = iris, target = "Species") lrn = makeLearner("classif.lda") inner = makeResampleDesc("Holdout") outer = makeResampleDesc("CV", iters = 2) lrn = makeFilterWrapper(lrn, fw.perc = 0.5) mod = train(lrn, task)#> Error: Please use column names for `x`#> Error in getFilteredFeatures(mod): object 'mod' not found# now nested resampling, where we extract the features that the filter method selected r = resample(lrn, task, outer, extract = function(model) { getFilteredFeatures(model) })#>#>#>#>#>#>#>#> [[1]] #> [1] "Petal.Length" "Petal.Width" #> #> [[2]] #> [1] "Petal.Length" "Petal.Width" #># usage of an ensemble filter lrn = makeLearner("classif.lda") lrn = makeFilterWrapper(lrn, fw.method = "E-Borda", fw.base.methods = c("FSelectorRcpp_gain.ratio", "FSelectorRcpp_information.gain"), fw.perc = 0.5) r = resample(lrn, task, outer, extract = function(model) { getFilteredFeatures(model) })#>#>#>#>#>#>#>#> [[1]] #> [1] "Petal.Length" "Petal.Width" #> #> [[2]] #> [1] "Petal.Length" "Petal.Width" #>