File: RemoveConstantFeaturesWrapper.R

package info (click to toggle)
r-cran-mlr 2.18.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,088 kB
  • sloc: ansic: 65; sh: 13; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
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
#' @title Fuse learner with removal of constant features preprocessing.
#'
#' @description
#' Fuses a base learner with the preprocessing implemented in [removeConstantFeatures].
#'
#' @template arg_learner
#' @inheritParams removeConstantFeatures
#' @export
#' @family wrapper
#' @template ret_learner
makeRemoveConstantFeaturesWrapper = function(learner, perc = 0, dont.rm = character(0L), na.ignore = FALSE, tol = .Machine$double.eps^.5) {

  learner = checkLearner(learner)
  args = list(perc = perc, dont.rm = dont.rm, na.ignore = na.ignore, tol = tol)
  rm(list = names(args))

  trainfun = function(data, target, args) {
    args$dont.rm = union(args$dont.rm, target)
    tmp = do.call(removeConstantFeatures, c(list(obj = data), args))
    list(data = tmp, control = list(dropped.cols = setdiff(names(data), names(tmp))))
  }

  predictfun = function(data, target, args, control) {
    dropNamed(data, control$dropped.cols)
  }

  lrn = makePreprocWrapper(learner, trainfun, predictfun, par.vals = args)
  addClasses(lrn, "RemoveConstantFeaturesWrapper")
}