Skip to content

Commit

Permalink
Merge pull request #815 from mlr-org/smote_cols_error
Browse files Browse the repository at this point in the history
Add error message in PipeOpSmote for Tasks with non-feature cols
  • Loading branch information
mb706 authored Sep 17, 2024
2 parents e9210c5 + 387eef8 commit f97409c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/PipeOpSmote.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ PipeOpSmote = R6Class("PipeOpSmote",

.train_task = function(task) {
assert_true(all(task$feature_types$type == "numeric"))
cols = private$.select_cols(task)
cols = task$feature_names

unsupported_cols = setdiff(unlist(task$col_roles), union(cols, task$target_names))
if (length(unsupported_cols)) {
stopf("SMOTE cannot generate synthetic data for the following columns since they are neither features nor targets: '%s'",
paste(unsupported_cols, collapse = "', '"))
}

if (!length(cols)) {
return(task)
Expand All @@ -102,7 +108,7 @@ PipeOpSmote = R6Class("PipeOpSmote",
# rename target column and fix character conversion
st[["class"]] = as_factor(st[["class"]], levels = task$class_names)
setnames(st, "class", task$target_names)

task$rbind(st)
}
)
Expand Down

0 comments on commit f97409c

Please sign in to comment.