Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (63 sloc) 2.17 KB
#' @title Quadratic Discriminant Analysis Classification Learner
#'
#' @usage NULL
#' @name mlr_learners_classif.qda
#' @format [R6::R6Class()] inheriting from [mlr3::LearnerClassif].
#'
#' @section Construction:
#' ```
#' LearnerClassifQDA$new()
#' mlr3::mlr_learners$get("classif.qda")
#' mlr3::lrn("classif.qda")
#' ```
#'
#' @description
#' Quadratic discriminant analysis.
#' Calls [MASS::qda()] from package \CRANpkg{MASS}.
#'
#' @references
#' \cite{mlr3learners}{venables_2002}
#'
#' @export
#' @template seealso_learner
#' @templateVar learner_name classif.qda
#' @template example
LearnerClassifQDA = R6Class("LearnerClassifQDA", inherit = LearnerClassif,
public = list(
initialize = function() {
ps = ParamSet$new(list(
ParamUty$new("prior", tags = "train"),
ParamFct$new("method", default = "moment", levels = c("moment", "mle", "mve", "t"), tags = "train"),
ParamInt$new("nu", tags = "train"),
ParamFct$new("predict.method", default = "plug-in", levels = c("plug-in", "predictive", "debiased", "looCV"), tags = "predict")
))
ps$add_dep("nu", "method", CondEqual$new("t"))
super$initialize(
id = "classif.qda",
param_set = ps,
predict_types = c("response", "prob"),
feature_types = c("logical", "integer", "numeric", "factor", "ordered"),
properties = c("weights", "twoclass", "multiclass"),
packages = "MASS",
man = "mlr3learners::mlr_learners_classif.qda"
)
},
train_internal = function(task) {
invoke(MASS::qda, task$formula(), data = task$data(), .args = self$param_set$get_values(tags = "train"))
},
predict_internal = function(task) {
pars = self$param_set$get_values(tags = "predict")
if (!is.null(pars$predict.method)) {
pars$method = pars$predict.method
pars$predict.method = NULL
}
newdata = task$data(cols = task$feature_names)
p = invoke(predict, self$model, newdata = newdata, .args = pars)
if (self$predict_type == "response") {
PredictionClassif$new(task = task, response = p$class)
} else {
PredictionClassif$new(task = task, prob = p$posterior)
}
}
)
)
You can’t perform that action at this time.