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
22 changes: 20 additions & 2 deletions R/PipeOpFixFactors.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,30 @@
#' @section Methods:
#' Only methods inherited from [`PipeOpTaskPreprocSimple`]/[`PipeOpTaskPreproc`]/[`PipeOp`].
#'
#' @examples
#' library("mlr3")
#'
#' # Reduced task with no entries for the installment_rate < 20 is defined
#' task = tsk("german_credit")
#' rows = task$row_ids[task$data()[, installment_rate != "< 20"]]
#' reduced_task = task$clone(deep = TRUE)$filter(rows)
#' levels(reduced_task$data()$installment_rate)
#'
#' # PipeOp is trained on the reduced task
#' po = po("fixfactors")
#' processed_task = preproc(reduced_task, po)
#' levels(processed_task$data()$installment_rate)
#' summary(processed_task$data()$installment_rate)
#'
#' predicted_task = preproc(task, po, predict = TRUE)
#'
#' # Predictions are made on the task without any missing data
#' levels(predicted_task$data()$installment_rate)
#' summary(predicted_task$data()$installment_rate)
#' @family PipeOps
#' @template seealso_pipeopslist
#' @include PipeOpTaskPreproc.R
#' @export
#' @examples
#' library("mlr3")
PipeOpFixFactors = R6Class("PipeOpFixFactors",
inherit = PipeOpTaskPreprocSimple,
public = list(
Expand Down
31 changes: 31 additions & 0 deletions R/PipeOpTrafo.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,37 @@ PipeOpTargetTrafo = R6Class("PipeOpTargetTrafo",
#' @section Methods:
#' Only methods inherited from [`PipeOp`].
#'
#' @examplesIf requireNamespace("rpart")
#' library(mlr3)
#' task = tsk("boston_housing")
#' po = PipeOpTargetMutate$new("logtrafo", param_vals = list(
#' trafo = function(x) log(x, base = 2),
#' inverter = function(x) list(response = 2 ^ x$response))
#' )
#' # Note that this example is ill-equipped to work with
#' # `predict_type == "se"` predictions.
#'
#' po$train(list(task))
#' po$predict(list(task))
#'
#' g = Graph$new()
#' g$add_pipeop(po)
#' g$add_pipeop(LearnerRegrRpart$new())
#' g$add_pipeop(PipeOpTargetInvert$new())
#' g$add_edge(src_id = "logtrafo", dst_id = "targetinvert",
#' src_channel = 1, dst_channel = 1)
#' g$add_edge(src_id = "logtrafo", dst_id = "regr.rpart",
#' src_channel = 2, dst_channel = 1)
#' g$add_edge(src_id = "regr.rpart", dst_id = "targetinvert",
#' src_channel = 1, dst_channel = 2)
#'
#' g$train(task)
#' g$predict(task)
#'
#' #syntactic sugar using ppl():
#' tt = ppl("targettrafo", graph = PipeOpLearner$new(LearnerRegrRpart$new()))
#' tt$param_set$values$targetmutate.trafo = function(x) log(x, base = 2)
#' tt$param_set$values$targetmutate.inverter = function(x) list(response = 2 ^ x$response)
#' @family PipeOps
#' @template seealso_pipeopslist
#' @include PipeOp.R
Expand Down