R/helpers.R

Defines functions predictLearner.classif.constant trainLearner.classif.constant makeRLearner.classif.constant skip.expensive printList print.llama.model print.llama.data

Documented in makeRLearner.classif.constant predictLearner.classif.constant print.llama.data print.llama.model trainLearner.classif.constant

print.llama.data <-
function(x, ...) {
  if(is.null(x$algorithmFeatures)) {
    cat(
      nrow(x$data), " instances\n",
      length(x$performance), " algorithms\n",
      "ID columns: ", paste(x$ids, collapse=", "), "\n",
      "Instance Features: ", paste(x$features, collapse=", "), "\n",
      "Performances: ", paste(x$performance, collapse=", "), "\n",
      "Successes: ", paste(x$success, collapse=", "), "\n",
      "Cost groups: ", printList(x$costGroups), "\n",
      "Extra: ", paste(x$extra, collapse=", "), "\n",
      "Minimize: ", x$minimize, "\n",
      "Has splits: ", attr(x, "hasSplits"), "\n",
      sep = "")
  } else {
    cat(
      nrow(unique(x$data[x$ids])), " instances\n",
			length(x$algorithmNames), " algorithms\n",
      "ID columns: ", paste(x$ids, collapse=", "), "\n",
      "Algorithm columns: ", paste(x$algos, collapse=", "), "\n",
      "Instance Features: ", paste(x$features, collapse=", "), "\n",
      "Algorithm Features: ", paste(x$algorithmFeatures, collapse=", "), "\n",
      "Performances: ", paste(x$performance, collapse=", "), "\n",
      "Successes: ", paste(x$success, collapse=", "), "\n",
      "Cost groups: ", printList(x$costGroups), "\n",
      "Extra: ", paste(x$extra, collapse=", "), "\n",
      "Minimize: ", x$minimize, "\n",
      "Has splits: ", attr(x, "hasSplits"), "\n",
      sep = "")
  }
}

print.llama.model <-
function(x, ...) {
    cat(
      "Type: ", attr(x, "type"), "\n",
      "Has predictions: ", attr(x, "hasPredictions"), "\n",
      "Add costs: ", attr(x, "addCosts"), "\n",
      "Tuned: ", (length(x$parvals) > 0), "\n",
      sep = "")
}

printList <-
function(l) {
    paste(sapply(names(l), function(x) {
        paste(x, " = [", paste(l[[x]], collapse=", "), "]", sep="")
    }), collapse="")
}

skip.expensive <-
function() {
    cond = structure(list(message = "Skipping expensive run."), class = c("skip", "condition"))
    if(Sys.getenv("RUN_EXPENSIVE") != "true") stop(cond)
}

makeRLearner.classif.constant = function() {
    makeRLearnerClassif(cl = "classif.constant", package="llama",
        par.set=ParamHelpers::makeParamSet(), properties=c("numerics", "factors", "ordered", "weights", "oneclass", "multiclass", "missings"))
}
trainLearner.classif.constant = function(.learner, .task, .subset, .weights, ...) { }
predictLearner.classif.constant = function(.learner, .model, .newdata, ...) {
    return(factor(rep.int(.model$factor.levels$target, nrow(.newdata))))
}
registerS3method("makeRLearner", "classif.constant", makeRLearner.classif.constant)
registerS3method("trainLearner", "classif.constant", trainLearner.classif.constant)
registerS3method("predictLearner", "classif.constant", predictLearner.classif.constant)
constantClassifier = makeLearner("classif.constant")

Try the llama package in your browser

Any scripts or data that you put into this service are public.

llama documentation built on March 17, 2021, 1:06 a.m.