Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated mincriterion should give identical results to one mincriterion #276

Open
JensWahl opened this issue Sep 8, 2021 · 0 comments
Open
Labels
bug Something isn't working

Comments

@JensWahl
Copy link
Contributor

JensWahl commented Sep 8, 2021

Repeating the same value for mincriterion gives different results when approach = "ctree"

#remotes::install_github("NorskRegnesentral/shapr")
library(shapr)
library(xgboost)
library(data.table)

data("Boston", package = "MASS")

x_var <- c("lstat", "rm", "dis", "indus")
y_var <- "medv"

x_train <- as.matrix(Boston[-1:-6, x_var])
y_train <- Boston[-1:-6, y_var]
x_test <- as.matrix(Boston[1:6, x_var])

# Fitting a basic xgboost model to the training data
model <- xgboost(
  data = x_train,
  label = y_train,
  nround = 20,
  verbose = FALSE
)
explainer <- shapr(x_train, model,n_combinations = 100)

p = mean(y_train)
ctree = explain(x_test, explainer, "ctree", mincriterion = 0.95, prediction_zero = p, n_samples = 10000, seed = 123)
ctree2 = explain(x_test, explainer, "ctree", mincriterion = rep(0.95, 4) , prediction_zero = p, n_samples = 10000, seed = 123)

ctree$dt
#>      none       lstat         rm        dis     indus
#> 1: 22.446  5.27101195 -2.2623617  0.7167850 5.1300151
#> 2: 22.446 -0.01718546 -0.7017281  0.6321774 0.8926739
#> 3: 22.446  6.24540411  4.0077874 -0.3611664 0.7774418
#> 4: 22.446  8.55715410 -0.4802524  0.4757659 2.4314768
#> 5: 22.446  1.14282068  4.9039389  0.6773156 2.5597634
#> 6: 22.446  2.40798688 -4.9300163  1.1378937 3.7881587
ctree2$dt
#>      none      lstat         rm        dis     indus
#> 1: 22.446 5.44940813 -2.2008549  0.5946036 5.0122935
#> 2: 22.446 0.00713506 -0.6693527  0.5442665 0.9238889
#> 3: 22.446 6.28454770  4.1246398 -0.5241423 0.7844218
#> 4: 22.446 8.42424493 -0.3048220  0.4379691 2.4267524
#> 5: 22.446 1.10024545  4.8669534  0.6718916 2.6447482
#> 6: 22.446 2.29351315 -4.9580286  1.2324759 3.8360624
@martinju martinju added the bug Something isn't working label Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants