Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tabnet variable importance output not compatible with autotest expectation #12

@jemus42

Description

@jemus42

Currently the importance() function merely extracts values from .$model$fit$importances.

Autotest expects the names of the importance scores to be the same as the input feature names, which is perfectly reasonable except for when tabnet gives separate logicalTRUE and logicalFALSE scores for a feature logical.

library(mlr3)
library(mlr3torch)

# Load test scaffolding without helper_debugging.R
lapply(list.files(system.file("testthat", package = "mlr3"), pattern = "^helper.*\\.[rR]$", full.names = TRUE)[-2], source)

learner <- lrn("classif.torch.tabnet")

# Extracted from run_experiment()
tasks <- generate_tasks(learner, N = 30L)
# Pick the test which fails
task <- tasks[["feat_all_binary"]]

lrn = lrn("classif.torch.tabnet", epochs = 1)
lrn$train(task)

# tabnet gives two importance scores per logical variable value
lrn$importance()
#>      integer      ordered      numeric  logicalTRUE logicalFALSE       factor 
#>  0.644666921  0.241514186  0.082143583  0.028178666  0.002125061  0.001371584
task$feature_names
#> [1] "factor"  "integer" "logical" "numeric" "ordered"

# Different learner result for reference ----------------------------------
library(mlr3learners)
lrnranger <- lrn("classif.ranger", importance = "impurity_corrected")
lrnranger$train(task)

lrnranger$importance()
#>       factor      logical      integer      ordered      numeric 
#> -0.004777695 -0.034839272 -0.123387319 -0.146356698 -0.974573206
task$feature_names
#> [1] "factor"  "integer" "logical" "numeric" "ordered"

Created on 2021-12-13 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions