An open API service indexing awesome lists of open source software.

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)

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

[![R-CMD-check](https://github.com/NorskRegnesentral/mcceR/actions/workflows/R-CMD-check.yaml/badge.svg)](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
```