https://github.com/norskregnesentral/mccer
R-package for the paper: MCCE: Monte Carlo sampling of valid and realistic counterfactual explanations for tabular data (https://arxiv.org/pdf/2111.09790)
https://github.com/norskregnesentral/mccer
Last synced: 2 months ago
JSON representation
R-package for the paper: MCCE: Monte Carlo sampling of valid and realistic counterfactual explanations for tabular data (https://arxiv.org/pdf/2111.09790)
- Host: GitHub
- URL: https://github.com/norskregnesentral/mccer
- Owner: NorskRegnesentral
- License: other
- Created: 2022-10-04T07:53:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T14:32:49.000Z (12 months ago)
- Last Synced: 2025-08-19T11:51:53.627Z (2 months ago)
- Language: R
- Homepage:
- Size: 138 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mcceR
[](https://github.com/NorskRegnesentral/mcceR/actions/workflows/R-CMD-check.yaml)
The goal of mcceR is to generate counterfactual explanations
## Installation
You can install mcceR from GitHub with:
``` r
remotes::install_github("NorskRegnesentral/mcceR")
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
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
```