File: RLearner_regr_pcr.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 (33 lines) | stat: -rw-r--r-- 1,165 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
26
27
28
29
30
31
32
33
#' @export
makeRLearner.regr.pcr = function() {
  makeRLearnerRegr(
    cl = "regr.pcr",
    package = "pls",
    par.set = makeParamSet(
      makeIntegerLearnerParam(id = "ncomp", lower = 1L),
      makeDiscreteLearnerParam(id = "method", default = "cppls",
        values = c("kernelpls", "widekernelpls", "simpls", "oscorespls", "cppls", "svdpc")),
      makeLogicalLearnerParam(id = "scale", default = FALSE),
      makeLogicalLearnerParam(id = "model", default = TRUE, tunable = FALSE),
      makeLogicalLearnerParam(id = "x", default = FALSE, tunable = FALSE),
      makeLogicalLearnerParam(id = "y", default = FALSE, tunable = FALSE)
    ),
    par.vals = list(model = FALSE),
    properties = c("numerics", "factors"),
    name = "Principal Component Regression",
    short.name = "pcr",
    callees = "pcr"
  )
}

#' @export
trainLearner.regr.pcr = function(.learner, .task, .subset, .weights = NULL, ...) {
  f = getTaskFormula(.task)
  pls::pcr(f, data = getTaskData(.task, .subset), ...)
}

#' @export
predictLearner.regr.pcr = function(.learner, .model, .newdata, ...) {
  p = predict(.model$learner.model, newdata = .newdata)
  p[, 1L, dim(p)[3L]]
}