Skip to content

Commit

Permalink
Merge pull request #765 from mlr-org/rename_fu_in_ppl
Browse files Browse the repository at this point in the history
rename featureunion in ppls
  • Loading branch information
mb706 authored Mar 26, 2024
2 parents 5dc84f6 + 47e3ee5 commit 7d18533
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# mlr3pipelines 0.5.0-9000

* Changed the ID of `PipeOpFeatureUnion` used in `ppl("robustify")` and `ppl("stacking")`.
* `pipeline_bagging()` gets the `replace` argument (old behaviour `FALSE` by default).
* Feature: The `$add_pipeop()` method got an argument `clone` (old behaviour `TRUE` by default).
* Bugfix: `PipeOpFeatureUnion` in some rare cases dropped variables called `"x"`.
Expand Down
2 changes: 1 addition & 1 deletion R/pipeline_robustify.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pipeline_robustify = function(task = NULL, learner = NULL,
imputing,
po("missind", affect_columns = selector_type(c("numeric", "integer", "logical")), type = if (missind_numeric) "numeric" else "factor")
)),
if (has_numbers || has_logicals) po("featureunion"),
if (has_numbers || has_logicals) po("featureunion", id = "featureunion_robustify"),
if (has_factorials) po("imputeoor")
)

Expand Down
2 changes: 1 addition & 1 deletion R/pipeline_stacking.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pipeline_stacking = function(base_learners, super_learner, method = "cv", folds
if (use_features) base_learners_cv = c(base_learners_cv, po("nop"))

gunion(base_learners_cv, in_place = TRUE) %>>!%
po("featureunion") %>>!%
po("featureunion", id = "featureunion_stacking") %>>!%
super_learner
}

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_mlr_graphs_stacking.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("Stacking Pipeline", {
# default
graph_stack = pipeline_stacking(base_learners, super_learner)
expect_graph(graph_stack)
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "nop", "featureunion", "super.rpart"))
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "nop", "featureunion_stacking", "super.rpart"))
graph_learner = as_learner(graph_stack)
graph_learner$train(tsk("iris"))
expect_class(graph_learner$model$super.rpart$model, "rpart")
Expand All @@ -19,7 +19,7 @@ test_that("Stacking Pipeline", {
# no nop
graph_stack = pipeline_stacking(base_learners, super_learner, use_features = FALSE)
expect_graph(graph_stack)
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "featureunion", "super.rpart"))
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "featureunion_stacking", "super.rpart"))
graph_learner = as_learner(graph_stack)
graph_learner$train(tsk("iris"))
expect_class(graph_learner$model$super.rpart$model, "rpart")
Expand All @@ -28,7 +28,7 @@ test_that("Stacking Pipeline", {
# folds
graph_stack = pipeline_stacking(base_learners, super_learner, folds = 5)
expect_graph(graph_stack)
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "nop", "featureunion", "super.rpart"))
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "nop", "featureunion_stacking", "super.rpart"))
graph_learner = as_learner(graph_stack)
graph_learner$train(tsk("iris"))
expect_equal(graph_learner$graph$pipeops$base.rpart$param_set$values$resampling.folds, 5)
Expand All @@ -38,7 +38,7 @@ test_that("Stacking Pipeline", {
# insample
graph_stack = pipeline_stacking(base_learners, super_learner, method = "insample")
expect_graph(graph_stack)
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "nop", "featureunion", "super.rpart"))
expect_names(graph_stack$ids(), identical.to = c("base.rpart", "nop", "featureunion_stacking", "super.rpart"))
graph_learner = as_learner(graph_stack)
graph_learner$train(tsk("iris"))
expect_equal(graph_learner$graph$pipeops$base.rpart$param_set$values$resampling.method, "insample")
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test_ppl.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ test_that("mlr_pipeops multi-access works", {
expect_equal(ppls(), mlr_graphs)

})

test_that("mlr3book authors don't sleepwalk through life", {

tasks = tsks(c("breast_cancer", "sonar"))

glrn_stack = as_learner(ppl("robustify") %>>% ppl("stacking",
lrns(c("classif.rpart", "classif.debug")),
lrn("classif.rpart", id = "classif.rpart2")
))
glrn_stack$id = "Stack"

learners = c(glrn_stack)
bmr = benchmark(benchmark_grid(tasks, learners, rsmp("cv", folds = 2)))

})

0 comments on commit 7d18533

Please sign in to comment.