+
Skip to content

task$levels with cols argument returns incorrect output #1323

Open
@advieser

Description

@advieser

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载