File: getFunctionalFeatures.R

package info (click to toggle)
r-cran-mlr 2.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,264 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (35 lines) | stat: -rw-r--r-- 1,256 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
30
31
32
33
34
35
#' @title Get only functional features from a task or a data.frame.
#'
#' @description
#' The parameters \dQuote{subset}, \dQuote{features}, and \dQuote{recode.target}
#' are ignored for the data.frame method.
#' @inheritParams getTaskData
#' @param object ([Task]/[data.frame])\cr
#'   Object to check on.
#' @return Returns a `data.frame` containing only the functional features.
#' @export
getFunctionalFeatures = function(object, subset = NULL, features, recode.target = "no") {
  UseMethod("getFunctionalFeatures")
}

#' @export
#' @rdname getFunctionalFeatures
getFunctionalFeatures.Task = function(object, subset = NULL, features,
  recode.target = "no") {
  # Get data and pass on to data.frame method
  df = getTaskData(object, subset, features, target.extra = TRUE, recode.target,
    functionals.as = "matrix")
  getFunctionalFeatures.data.frame(df$data)
}

#' @export
#' @rdname getFunctionalFeatures
getFunctionalFeatures.data.frame = function(object, subset = NULL, features,
  recode.target = "no") {
  # Keep only columns with class matrix
  funct.cols = which(vcapply(object, function(x) class(x)[1L]) == "matrix")
  if (length(funct.cols) == 0L) {
    stop("No functional features in the data")
  }
  object[, funct.cols, drop = FALSE]
}