File: learner.R

package info (click to toggle)
r-cran-stablelearner 0.1-5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 380 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (3)
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
## -----------------------------------------------------------------------------
## Learner
## -----------------------------------------------------------------------------

## The function stability uses update() which uses getCall() to get x$call 
## to refit the model with new data sets. Therefore, only learners that 
## store the call in their resulting object will work. Otherwise, a function 
## getCall must be provided for the that class. For details, see ?update.
# 
getLearner <- function(x) {
  LearnerList <- get("LearnerList", envir = .GlobalEnv)
  if(inherits(x, names(LearnerList))) {
    pos <- inherits(x, names(LearnerList), which = TRUE)
    pos[pos==0L] <- NA
    LearnerList[[which.min(pos[pos>0L])]]
  } else {
    stop("Learner of class: ", class(x), " not in LearnerList. See ?LearnerList for help.")
  }
}

addLearner <- function(x) {
  eval.parent(substitute(LearnerList <- c(list(x), LearnerList)))
  eval.parent(substitute(names(LearnerList)[1] <- x$class))
  #eval.parent(LearnerList <- (names(LearnerList)[1] <- x$class))
}