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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: xplainfi
Title: Feature Importance Methods for Global Explanations
Version: 1.1.0
Version: 1.1.0.9000
Authors@R:
person("Lukas", "Burk", , "cran@lukasburk.de", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-7528-3795"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# xplainfi 1.1.0.9000 (development version)

- Fix `$obs_loss()` being erroneously called without `measure` in `PerturbationImportance`, resulting in an error when `measures` was not the task-default.

# xplainfi 1.1.0

## New features
Expand Down
2 changes: 1 addition & 1 deletion R/PerturbationImportance.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ PerturbationImportance = R6Class(
pred <- prediction[[1]]

# Get only vector of obs losses, Prediction$obs_loss() returns full table
obs_loss_vals <- pred$obs_loss()[[self$measure$id]]
obs_loss_vals <- pred$obs_loss(measures = self$measure)[[self$measure$id]]

list(
row_ids = pred$row_ids,
Expand Down
3 changes: 2 additions & 1 deletion man/FeatureImportanceMethod.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/sim_dgp_ewald.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/sim_dgp_scenarios.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions tests/testthat/test-PFI.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,35 @@ test_that("PFI scores and obs_losses agree", {

expect_equal(importance_scores, obs_agg, tolerance = sqrt(.Machine$double.eps))
})

test_that("PFI obs_loss uses specified measure, not default", {
# Regression test for bug where pred$obs_loss() was called without
# passing the measure, causing it to use the default measure (regr.mse)
# instead of the user-specified one. With a non-default measure like
# regr.mae, this caused obs_loss values to be NULL/wrong.
task = mlr3::tsk("mtcars")

pfi = PFI$new(
task = task,
learner = lrn("regr.rpart"),
measure = msr("regr.mae"),
n_repeats = 1L
)

pfi$compute()

obs_losses = pfi$obs_loss()
expect_obs_loss_dt(obs_losses, features = task$feature_names)

# obs_loss values should be absolute errors (MAE), not squared errors (MSE).
# Verify by checking that aggregating obs losses matches the score-level
# importance (which correctly uses the specified measure).
scores = pfi$scores()[, .(iter_rsmp, feature, importance)][order(iter_rsmp, feature)]

obs_agg = obs_losses[,
list(importance = mean(obs_importance)),
by = c("iter_rsmp", "feature")
][order(iter_rsmp, feature)]

expect_equal(scores, obs_agg, tolerance = sqrt(.Machine$double.eps))
})
Loading