File: RLearner_classif_plsdaCaret.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 (32 lines) | stat: -rw-r--r-- 1,223 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
#' @export
makeRLearner.classif.plsdaCaret = function() {
  makeRLearnerClassif(cl = "classif.plsdaCaret",
    package = c("caret", "pls"),
    par.set = makeParamSet(
      makeIntegerLearnerParam(id = "ncomp", default = 2, lower = 1),
      makeDiscreteLearnerParam(id = "probMethod", values = c("softmax", "Bayes"), default = "softmax"),
      makeDiscreteLearnerParam(id = "method", default = "kernelpls",
        values = c("kernelpls", "widekernelpls", "simpls", "oscorespls"))
    ),
    properties = c("numerics", "prob", "twoclass", "multiclass"),
    name = "Partial Least Squares (PLS) Discriminant Analysis",
    short.name = "plsdacaret",
    callees = c("plsda", "plsr")
  )
}

#' @export
trainLearner.classif.plsdaCaret = function(.learner, .task, .subset, .weights, ...) {
  d = getTaskData(.task, .subset, target.extra = TRUE)
  caret::plsda(d$data, d$target, ...)
}

#' @export
predictLearner.classif.plsdaCaret = function(.learner, .model, .newdata, ...) {
  type = ifelse(.learner$predict.type == "response", "class", "prob")
  p = predict(.model$learner.model, newdata = .newdata, type = type, ...)
  if (type == "prob") {
    p = array(c(p), dim(p)[-3], dimnames = dimnames(p)[1:2])
  }
  return(p)
}