File: Learner_operators.R

package info (click to toggle)
r-cran-mlr 2.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,760 kB
  • sloc: ansic: 65; sh: 13; makefile: 2
file content (121 lines) | stat: -rw-r--r-- 3,053 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#' @title Get the type of the learner.
#'
#' @description Get the type of the learner.
#' @template arg_learner
#' @return (`character(1)`).
#' @export
#' @family learner
getLearnerType = function(learner) {
  learner = checkLearner(learner)
  return(learner$type)
}

#' @title Get the ID of the learner.
#'
#' @description Get the ID of the learner.
#' @template arg_learner
#' @return (`character(1)`).
#' @export
#' @family learner
getLearnerId = function(learner) {
  learner = checkLearner(learner)
  return(learner$id)
}

#' @title Get the predict type of the learner.
#'
#' @description Get the predict type of the learner.
#' @template arg_learner
#' @return (`character(1)`).
#' @export
#' @family learner
getLearnerPredictType = function(learner) {
  learner = checkLearner(learner)
  return(learner$predict.type)
}

#' @title Get the required R packages of the learner.
#'
#' @description Get the R packages the learner requires.
#' @template arg_learner
#' @return ([character]).
#' @export
#' @family learner
getLearnerPackages = function(learner) {
  learner = checkLearner(learner)
  return(learner$package)
}


#' @title Get the parameter set of the learner.
#'
#' @description
#' Alias for [getParamSet].
#'
#' @template arg_learner
#' @template ret_ps
#' @export
#' @family learner
getLearnerParamSet = function(learner) {
  getParamSet(learner)
}


#' @title Get the parameter values of the learner.
#'
#' @description
#' Alias for [getHyperPars].
#'
#' @template arg_learner
#' @inheritParams getHyperPars
#' @return ([list]). A named list of values.
#' @export
#' @family learner
getLearnerParVals = function(learner, for.fun = c("train", "predict", "both")) {
  learner = checkLearner(learner)
  getHyperPars(learner, for.fun)
}

#' @title Set the ID of a learner object.
#'
#' @description Set the ID of the learner.
#' @template arg_learner
#' @param id (`character(1)`)\cr
#'    New ID for learner.
#' @template ret_learner
#' @export
#' @family learner
setLearnerId = function(learner, id) {
  learner = checkLearner(learner)
  assertString(id)
  learner$id = id
  return(learner)
}

#' @title Get the short name of the learner.
#'
#' @description For an ordinary learner simply its short name is returned.
#'   For wrapped learners, the wrapper id is successively attached to the short
#'   name of the base learner. E.g: \dQuote{rf.bagged.imputed}
#' @template arg_learner
#' @return (`character(1)`).
#' @export
#' @family learner
getLearnerShortName = function(learner) {
  learner = checkLearner(learner)
  learner.short.name = learner$short.name

  if (is.null(learner.short.name)) {
    learner.id.split = unlist(strsplit(getLearnerId(learner), "[.]"))
    wrapper.ids = learner.id.split[3:length(learner.id.split)]
    base.learner.path = c(rep("next.learner", length(wrapper.ids)),
      "short.name")
    base.learner.short.name = extractSubList(list(learner),
      base.learner.path)
    learner.short.name = paste(c(base.learner.short.name, wrapper.ids),
      collapse = ".")
  }

  return(learner.short.name)
}