Skip to main content

Explainable AI with counterfactual paths

Project description

Explainable AI with counterfactual paths


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), 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)



If you find cpath please cite

      title={Explainable AI with counterfactual paths}, 
      author={Bastian Pfeifer and Mateusz Krzyzinski and Hubert Baniecki and Anna Saranti and Andreas Holzinger and Przemyslaw Biecek},

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 hashes)

Uploaded source

Built Distribution

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

Uploaded py3

Supported by

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