Skip to main content

Explainable AI with counterfactual paths

Project description

Explainable AI with counterfactual paths

Usage

Install the Python package cpath via pip

pip install cpath

and import

import cpath

or from source

pip install ./cpath
import cpath

Other imports

from imodels.util.data_util import get_clean_dataset
import numpy as np
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import balanced_accuracy_score
from sklearn.metrics import roc_auc_score

import sys

Example data set

clf_datasets = [
    ("breast-cancer", "breast_cancer", "imodels")
]

# Read in data set
X, y, feature_names = get_clean_dataset('breast_cancer', data_source='imodels')

# train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)

Random Forest

# number of trees 
ntrees = 10

clf = RandomForestClassifier(n_estimators=ntrees) 
clf.fit(X_train, y_train)
pred = clf.predict(X_test)

Explain using cpath

P = cpath.cpaths(clf, X_test, y_test)

T = cpath.transition(P, X_test, y_test)

IMP = cpath.importance(T)

IMP["global"]

Citation

If you find cpath please cite

@misc{pfeifer2023explainable,
      title={Explainable AI with counterfactual paths}, 
      author={Bastian Pfeifer and Mateusz Krzyzinski and Hubert Baniecki and Anna Saranti and Andreas Holzinger and Przemyslaw Biecek},
      year={2023},
      eprint={2307.07764},
      archivePrefix={arXiv},
      primaryClass={cs.AI}
}

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

cpath-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

cpath-0.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file cpath-0.0.1.tar.gz.

File metadata

  • Download URL: cpath-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.6

File hashes

Hashes for cpath-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4aeb4618da86d962147502eaae794597c020e79bd9b24acee6e6689db618c32b
MD5 bdcc4e8d6850a34a445098503b9fa178
BLAKE2b-256 e81dadddb9aff44c31f38ba5b7cc63433d544b0bafed5260c05f65c60c1201ed

See more details on using hashes here.

File details

Details for the file cpath-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cpath-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.6

File hashes

Hashes for cpath-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c39c289f377a509829a75c0689bfd61c26d88e0748350b0b27faea155ee8bb40
MD5 7477436e27944573d56d38d42101dbb4
BLAKE2b-256 2bc86b0e9ef6ba941357886bfa66dd42f5bc74d771edd9b16a84617dbfa78d5b

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