Open
Description
The cols
argument changes only the names of the selected list elements oft task$levels()
, but leaves the order of the selected elements the same, leading to the incorrect column-name to levels pairs. (The reprex explains it much better.)
library(mlr3)
task = TaskClassif$new(id = "example", target = "target", backend = data.table(
target = factor(c("a", "b", "c")),
x = ordered(c("A", "B", "C")),
y = factor(c("X", "Y", "Z"))
))
# This works
task$levels()
#> $target
#> [1] "a" "b" "c"
#>
#> $x
#> [1] "A" "B" "C"
#>
#> $y
#> [1] "X" "Y" "Z"
task$levels(cols = "y")
#> $y
#> [1] "X" "Y" "Z"
# This just changes the names, without changing the actual order
task$levels(cols = c("x", "y", "target"))
#> $x
#> [1] "a" "b" "c"
#>
#> $y
#> [1] "A" "B" "C"
#>
#> $target
#> [1] "X" "Y" "Z"
task$levels(cols = c("y", "x"))
#> $y
#> [1] "A" "B" "C"
#>
#> $x
#> [1] "X" "Y" "Z"
Created on 2025-06-21 with reprex v2.1.1
Metadata
Metadata
Assignees
Labels
No labels