Skip to main content

A python package for generating counterfactual explanations for machine learning models

Project description

TuneableCounterfactuals

Introduction

A general purpose library for generating counterfactuals to explain the outputs of black-box Models

Installation

pip install -r requirements.txt

Vignette

A simple example that uses our methodology to generate counterfactual explanations for a black box model.

import sklearn

from sklearn.datasets import fetch_openml
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

data = fetch_openml('mnist_784', parser='auto')
train_x, test_x, train_y, test_y = train_test_split(
    data.data[data.target.isin(['0', '1'])],
    data.target[data.target.isin(['0', '1'])], 
    test_size=0.2
)

model = MLPClassifier(hidden_layer_sizes=(200,200),alpha=1, max_iter=1000, solver='adam', verbose=10,  random_state=21,tol=0.000000001)
model = make_pipeline(StandardScaler(), model)
model.fit(train_x, train_y)

explainer = Explainer(
    model,
    train_x,
    'target',
    regressor='linear',
    bounding_method='minmax',
    override_variable_bounds=(0, 255)
)

result = explainer.explain(training_data.iloc[id], additional_threshold=0.25)

Contact

Joshan Parmar

Soumya Banerjee (sb2333@cam.ac.uk)

Citation

Forthcoming

Graphical abstract

A graphical summary of our work is shown here

summary

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tuneable_counterfactuals_explainer-0.0.7.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file tuneable_counterfactuals_explainer-0.0.7.tar.gz.

File metadata

File hashes

Hashes for tuneable_counterfactuals_explainer-0.0.7.tar.gz
Algorithm Hash digest
SHA256 5181712538780f30c70c7376775fa98c7988da059edf93be24be7bc71462a9e1
MD5 3350de03a1ccddf4c1ace6c6a2609a99
BLAKE2b-256 45eb8a676fa192086f3867600a0d9321a6c8df1f41845e4a47f96d708e988970

See more details on using hashes here.

File details

Details for the file tuneable_counterfactuals_explainer-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for tuneable_counterfactuals_explainer-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 51b37b837770e2704424554c9e8c3493a240a7b85ab5a2421f6d31323dc14dc4
MD5 5cce942492d4c0190aff26c2824a3751
BLAKE2b-256 18231e53fe89ddb5321399829616ffe5333134f84928512c9100b3298d4775a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page