Skip to content

R-package for the paper: MCCE: Monte Carlo sampling of valid and realistic counterfactual explanations for tabular data (https://arxiv.org/pdf/2111.09790)

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

NorskRegnesentral/mcceR

Repository files navigation

mcceR

R-CMD-check

The goal of mcceR is to generate counterfactual explanations

Installation

You can install mcceR from GitHub with:

remotes::install_github("NorskRegnesentral/mcceR")

Example

This is a basic example which shows you how to solve a common problem:

library(mcceR)
library(xgboost)
## basic example code

data("airquality")
airquality <- airquality[complete.cases(airquality), ]

x_var <- c("Solar.R", "Wind", "Temp", "Month")
y_var <- "Ozone"

ind_x_explain <- 1:6
x_train <- as.matrix(airquality[-ind_x_explain, x_var])
y_train <- airquality[-ind_x_explain, y_var]
x_explain <- as.matrix(airquality[ind_x_explain, x_var])

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

#predict(model,x_train) 

explained <- explain_mcce(model = model,
                          x_explain = x_explain,
                          x_train = x_train,
                          c_int = c(-Inf,15),
                          predict_model=NULL,
                          fixed_features = "Wind",
                          fit.seed = 123,
                          generate.seed = 123)

explained
#>    id_explain counterfactual_rank  pred Solar.R Wind Temp Month
#> 1:          1                   1 14.23      49  7.4   76     6
#> 2:          2                   1 14.90      49  8.0   70     9
#> 3:          3                   1 14.36     191 12.6   73     7
#> 4:          4                   1 14.59     334 11.5   64     7
#> 5:          5                   1 14.47      49  8.6   76     7
#> 6:          6                   1 14.39      78 13.8   64     7

About

R-package for the paper: MCCE: Monte Carlo sampling of valid and realistic counterfactual explanations for tabular data (https://arxiv.org/pdf/2111.09790)

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published