Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/Graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,13 @@ Graph = R6Class("Graph",
extra_vertices = setdiff(ids, c(df$from, df$to))

all_names = unique(unlist(df))
df = data.table::setDT(mlr3misc::map(df, function(x) match(x, all_names)))
df = setDT(map(df, function(x) match(x, all_names)))
gr = paste0(map(seq_len(nrow(df)), function(x) {
paste0(df[x, ][[1L]], " -> ", df[x, ][[2L]])
}), collapse = ";\n")

all_names = gsub("\\.", "_", all_names)
labels = paste0(unlist(mlr3misc::map(unique(unlist(df)), function(x) {
labels = paste0(unlist(map(unique(unlist(df)), function(x) {
paste0(x, " [label=", '"', all_names[x], '"', ",fontsize=", fontsize, ']')
})), collapse = ";\n")
dot = paste0(gr, ";\n", labels)
Expand Down
2 changes: 1 addition & 1 deletion R/PipeOp.R
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ check_types = function(self, data, direction, operation) {
autoconverter = get_autoconverter(typereq)
msg = ""
if (!is.null(autoconverter)) {
mlr3misc::require_namespaces(autoconverter$packages,
require_namespaces(autoconverter$packages,
sprintf("The following packages are required to convert object of class %s to class %s: %%s.", class(data_element)[1], typereq))
msg = tryCatch({
data_element = autoconverter$fun(data_element)
Expand Down
12 changes: 6 additions & 6 deletions R/PipeOpNMF.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ PipeOpNMF = R6Class("PipeOpNMF",
names(.args)[match("pbackend", names(.args), nomatch = 0L)] = ".pbackend"
names(.args)[match("callback", names(.args), nomatch = 0L)] = ".callback"

nmf = mlr3misc::invoke(NMF::nmf,
nmf = invoke(NMF::nmf,
x = x,
rng = NULL,
model = NULL,
Expand All @@ -178,9 +178,9 @@ PipeOpNMF = R6Class("PipeOpNMF",
self$state = structure(list(nmf = nmf), class = "PipeOpNMFstate")

# here we have two options? return directly h or do what we do during prediction
#h = t(mlr3misc::invoke(NMF::coef, object = nmf))
w = mlr3misc::invoke(NMF::basis, object = nmf)
h_ = t(mlr3misc::invoke(MASS::ginv, X = w) %*% x)
#h = t(invoke(NMF::coef, object = nmf))
w = invoke(NMF::basis, object = nmf)
h_ = t(invoke(MASS::ginv, X = w) %*% x)
colnames(h_) = paste0("NMF", seq_len(self$param_set$values$rank))
h_
},
Expand All @@ -197,8 +197,8 @@ PipeOpNMF = R6Class("PipeOpNMF",
}

x = t(as.matrix(dt))
w = mlr3misc::invoke(NMF::basis, object = self$state$nmf)
h_ = t(mlr3misc::invoke(MASS::ginv, X = w) %*% x)
w = invoke(NMF::basis, object = self$state$nmf)
h_ = t(invoke(MASS::ginv, X = w) %*% x)
colnames(h_) = paste0("NMF", seq_len(self$param_set$values$rank))
h_
},
Expand Down
26 changes: 13 additions & 13 deletions R/PipeOpVtreat.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ PipeOpVtreat = R6Class("PipeOpVtreat",
initialize = function(id = "vtreat", param_vals = list()) {
ps = ps(
recommended = p_lgl(tags = c("train", "predict")),
cols_to_copy = p_uty(custom_check = checkmate::check_function, tags = c("train", "predict")),
cols_to_copy = p_uty(custom_check = check_function, tags = c("train", "predict")),
# tags stand for: regression vtreat::regression_parameters() / classification vtreat::classification_parameters() / multinomial vtreat::multinomial_parameters()
minFraction = p_dbl(lower = 0, upper = 1, default = 0.02, tags = c("train", "regression", "classification", "multinomial")),
smFactor = p_dbl(lower = 0, upper = Inf, default = 0, tags = c("train", "regression", "classification", "multinomial")),
Expand Down Expand Up @@ -207,40 +207,40 @@ PipeOpVtreat = R6Class("PipeOpVtreat",
}

if (length(self$param_set$values$imputation_map)) {
checkmate::assert_subset(names(self$param_set$values$imputation_map), choices = var_list, empty.ok = TRUE)
assert_subset(names(self$param_set$values$imputation_map), choices = var_list, empty.ok = TRUE)
}

# FIXME: Handle non-Regr / non-Classif Tasks that inherit from TaskSupervised, #913
task_type = task$task_type
transform_design = if (task_type == "regr") {
mlr3misc::invoke(vtreat::NumericOutcomeTreatment,
invoke(vtreat::NumericOutcomeTreatment,
var_list = var_list,
outcome_name = task$target_names,
cols_to_copy = self$param_set$values$cols_to_copy(task),
params = vtreat::regression_parameters(mlr3misc::insert_named(self$param_set$get_values(tags = "regression"), list(check_for_duplicate_frames = FALSE))),
params = vtreat::regression_parameters(insert_named(self$param_set$get_values(tags = "regression"), list(check_for_duplicate_frames = FALSE))),
imputation_map = self$param_set$values$imputation_map)
} else if (task_type == "classif") {
if (length(task$class_names) > 2L) {
mlr3misc::invoke(vtreat::MultinomialOutcomeTreatment,
invoke(vtreat::MultinomialOutcomeTreatment,
var_list = var_list,
outcome_name = task$target_names,
cols_to_copy = self$param_set$values$cols_to_copy(task),
params = vtreat::multinomial_parameters(mlr3misc::insert_named(self$param_set$get_values(tags = "multinomial"), list(check_for_duplicate_frames = FALSE))),
params = vtreat::multinomial_parameters(insert_named(self$param_set$get_values(tags = "multinomial"), list(check_for_duplicate_frames = FALSE))),
imputation_map = self$param_set$values$imputation_map)
} else {
mlr3misc::invoke(vtreat::BinomialOutcomeTreatment,
invoke(vtreat::BinomialOutcomeTreatment,
var_list = var_list,
outcome_name = task$target_names,
outcome_target = task$positive,
cols_to_copy = self$param_set$values$cols_to_copy(task),
params = vtreat::classification_parameters(mlr3misc::insert_named(self$param_set$get_values(tags = "classification"), list(check_for_duplicate_frames = FALSE))),
params = vtreat::classification_parameters(insert_named(self$param_set$get_values(tags = "classification"), list(check_for_duplicate_frames = FALSE))),
imputation_map = self$param_set$values$imputation_map)
}
}

# the following exception handling is necessary because vtreat sometimes fails with "no usable vars" if the data is already "clean" enough
vtreat_res = tryCatch(
mlr3misc::invoke(vtreat::fit_prepare,
invoke(vtreat::fit_prepare,
vps = transform_design,
dframe = task$data(),
weights = if ("weights_learner" %in% names(task)) task$weights_learner$weight else task$weights$weight,
Expand All @@ -261,11 +261,11 @@ PipeOpVtreat = R6Class("PipeOpVtreat",

self$state$treatment_plan = vtreat_res$treatments

d_prepared = data.table::setDT(vtreat_res$cross_frame)
d_prepared = setDT(vtreat_res$cross_frame)

feature_subset = self$state$treatment_plan$get_feature_names() # subset to vtreat features
if (self$param_set$values$recommended) {
score_frame = mlr3misc::invoke(vtreat::get_score_frame, vps = self$state$treatment_plan)
score_frame = invoke(vtreat::get_score_frame, vps = self$state$treatment_plan)
feature_subset = feature_subset[feature_subset %in% score_frame$varName[score_frame$recommended]] # subset to only recommended
}
feature_subset = c(feature_subset, self$param_set$values$cols_to_copy(task)) # respect cols_to_copy
Expand All @@ -283,7 +283,7 @@ PipeOpVtreat = R6Class("PipeOpVtreat",

# the following exception handling is necessary because vtreat sometimes fails with "no usable vars" if the data is already "clean" enough
d_prepared = tryCatch(
data.table::setDT(mlr3misc::invoke(vtreat::prepare,
setDT(invoke(vtreat::prepare,
treatmentplan = self$state$treatment_plan,
dframe = task$data())),
error = function(error_condition) {
Expand All @@ -297,7 +297,7 @@ PipeOpVtreat = R6Class("PipeOpVtreat",

feature_subset = self$state$treatment_plan$get_feature_names() # subset to vtreat features
if (self$param_set$values$recommended) {
score_frame = mlr3misc::invoke(vtreat::get_score_frame, vps = self$state$treatment_plan)
score_frame = invoke(vtreat::get_score_frame, vps = self$state$treatment_plan)
feature_subset = feature_subset[feature_subset %in% score_frame$varName[score_frame$recommended]] # subset to only recommended
}
feature_subset = c(feature_subset, self$param_set$values$cols_to_copy(task)) # respect cols_to_copy
Expand Down
4 changes: 2 additions & 2 deletions R/TaskRegr_boston_housing.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#' @name mlr_tasks_boston_housing
#' @format [`R6Class`][R6::R6Class] object inheriting from [`TaskRegr`][mlr3::TaskRegr].
#'
#' The [`BostonHousing2`][mlbench::BostonHousing2] dataset
#' The [`BostonHousing2`][mlbench::BostonHousing2] dataset
#' containing the corrected data from `r format_bib("freeman_1979")`
#' as provided by the `mlbench` package. See data description there.
#'
NULL

load_boston_housing = function(id = "boston_housing") {
bh = mlr3misc::load_dataset("BostonHousing2", "mlbench")
bh = load_dataset("BostonHousing2", "mlbench")
bh$medv = NULL
bht = as_task_regr(bh, target = "cmedv", id = id, label = "Boston Housing Prices")
bht$man = "mlr3pipelines::mlr_tasks_boston_housing"
Expand Down
2 changes: 1 addition & 1 deletion R/mlr_graphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#'
#' # all Graphs currently in the dictionary:
#' as.data.table(mlr_graphs)
mlr_graphs = R6Class("DictionaryGraph", inherit = mlr3misc::Dictionary,
mlr_graphs = R6Class("DictionaryGraph", inherit = Dictionary,
cloneable = FALSE,
public = list(
add = function(key, value) {
Expand Down
2 changes: 1 addition & 1 deletion R/mlr_pipeops.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#'
#' # all PipeOps currently in the dictionary:
#' as.data.table(mlr_pipeops)[, c("key", "input.num", "output.num", "packages")]
mlr_pipeops = R6Class("DictionaryPipeOp", inherit = mlr3misc::Dictionary,
mlr_pipeops = R6Class("DictionaryPipeOp", inherit = Dictionary,
cloneable = FALSE,
public = list(
metainf = new.env(parent = emptyenv()),
Expand Down