if (is.null(params))
# Here, gmodel is a string (= its family),
# because a custom model must be given with its parameters.
if (is.null(params))
# Here, gmodel is a string (= its family),
# because a custom model must be given with its parameters.
- params <- as.list(private$getParams(gmodel, data, target))
+ params <- as.list(private$getParams(gmodel, data, target, task))
private$params <- params
if (is.character(gmodel))
gmodel <- private$getGmodel(gmodel, task)
private$params <- params
if (is.character(gmodel))
gmodel <- private$getGmodel(gmodel, task)
#' @param dataHO Matrix or data.frame
#' @param targetHO Vector of targets (generally numeric or factor)
#' @param index Index of the model in 1...nmodels
get = function(dataHO, targetHO, index) {
private$gmodel(dataHO, targetHO, private$params[[index]])
#' @param dataHO Matrix or data.frame
#' @param targetHO Vector of targets (generally numeric or factor)
#' @param index Index of the model in 1...nmodels
get = function(dataHO, targetHO, index) {
private$gmodel(dataHO, targetHO, private$params[[index]])
function(dataHO, targetHO, param) {
require(rpart)
method <- ifelse(task == "classification", "class", "anova")
function(dataHO, targetHO, param) {
require(rpart)
method <- ifelse(task == "classification", "class", "anova")
df <- data.frame(cbind(dataHO, target=targetHO))
model <- rpart::rpart(target ~ ., df, method=method, control=list(cp=param))
df <- data.frame(cbind(dataHO, target=targetHO))
model <- rpart::rpart(target ~ ., df, method=method, control=list(cp=param))
- function(X) predict(model, X)
+ if (task == "regression")
+ type <- "vector"
+ else {
+ if (is.null(dim(targetHO)))
+ type <- "class"
+ else
+ type <- "prob"
+ }
+ function(X) {
+ if (is.null(colnames(X)))
+ colnames(X) <- paste0("V", 1:ncol(X))
+ predict(model, as.data.frame(X), type=type)
+ }
if (family == "tree") {
# Run rpart once to obtain a CV grid for parameter cp
require(rpart)
df <- data.frame(cbind(data, target=target))
ctrl <- list(
if (family == "tree") {
# Run rpart once to obtain a CV grid for parameter cp
require(rpart)
df <- data.frame(cbind(data, target=target))
ctrl <- list(
- maxcompete = 0,
- maxsurrogate = 0,
- usesurrogate = 0,
- xval = 0,
- surrogatestyle = 0,
- maxdepth = 30)
- r <- rpart(target ~ ., df, method="class", control=ctrl)
+ xval = 0)
+ method <- ifelse(task == "classification", "class", "anova")
+ r <- rpart(target ~ ., df, method=method, control=ctrl)