Skip to content

Commit

Permalink
fixed column naming + additional phash for PipeOpEncodePLTree
Browse files Browse the repository at this point in the history
  • Loading branch information
advieser committed Jan 23, 2025
1 parent f4d3242 commit c774e38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions R/PipeOpEncodePL.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#' The `$state` is a named `list` with the `$state` elements inherited from [`PipeOpTaskPreprocSimple`], as well as:
#' * `bins` :: named `list`\cr
#' Named list of numeric vectors. Each element corresponds to one of the affected feature columns and contains the
#' inner bin boundaries derived through the private method `.get_bins()`. The element vectors are named by the respective
#' bin boundaries derived through the private method `.get_bins()`. The element vectors are named by the respective
#' feature column.
#'
#' @section Parameters:
Expand Down Expand Up @@ -105,7 +105,7 @@ PipeOpEncodePL = R6Class("PipeOpEncodePL",
}

dt = task$data(cols = cols)
res = as.data.table(imap(dt, function(d, col) encode_piecewise_linear(d, col, bins[[col]])))
res = imap_dtc(dt, function(d, col) encode_piecewise_linear(d, bins[[col]]))

task$select(setdiff(task$feature_names, cols))$cbind(res)
}
Expand All @@ -114,13 +114,12 @@ PipeOpEncodePL = R6Class("PipeOpEncodePL",

# Helper function to implement piecewise linear encoding.
# * column: numeric vector
# * colname: name of `column`
# * bins as numeric vector of boundaries
encode_piecewise_linear = function(column, colname, bins) {
encode_piecewise_linear = function(column, bins) {
n_bins = length(bins) - 1

dt = data.table(matrix(0, length(column), n_bins))
setnames(dt, paste0(colname, ".bin", seq_len(n_bins)))
setnames(dt, paste0("bin", seq_len(n_bins)))

for (t in seq_len(n_bins)) {
lower = bins[[t]]
Expand Down Expand Up @@ -307,9 +306,11 @@ PipeOpEncodePLTree = R6Class("PipeOpEncodePLTree",
bins[[col]] = c(min(d), boundaries, max(d))
}
bins
}
},

.additional_phash_input = function() private$.tree_learner$phash
)
)

# Registering with "TaskClassif", however both "TaskRegr" and "TaskClassif" are acceptable, see issue ...
# Registering with "TaskClassif", however both "TaskRegr" and "TaskClassif" are acceptable, see #869.
mlr_pipeops$add("encodepltree", PipeOpEncodePLTree, list(task_type = "TaskClassif"))
2 changes: 1 addition & 1 deletion man/mlr_pipeops_encodepl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c774e38

Please sign in to comment.