<p align="center">
<img src="https://github.com/pievos101/cpath/blob/main/logo.png" width="400">
</p>
# Explainable AI with counterfactual paths
## Usage
Install the Python package cpath via pip
```python
pip install cpath
```
and import
```python
import cpath
```
or from source
```python
pip install ./cpath
import cpath
```
Other imports
```python
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
```python
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
```python
# number of trees
ntrees = 10
clf = RandomForestClassifier(n_estimators=ntrees)
clf.fit(X_train, y_train)
pred = clf.predict(X_test)
```
### Explain using cpath
```python
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}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/pievos101/cpath",
"name": "cpath",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "Explainable AI,counterfactuals",
"author": "Bastian Pfeifer",
"author_email": "bastian.pfeifer@medunigraz.at",
"download_url": "https://files.pythonhosted.org/packages/e8/1d/adddb9aff44c31f38ba5b7cc63433d544b0bafed5260c05f65c60c1201ed/cpath-0.0.1.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n<img src=\"https://github.com/pievos101/cpath/blob/main/logo.png\" width=\"400\">\n</p>\n\n# Explainable AI with counterfactual paths\n\n## Usage\n\nInstall the Python package cpath via pip\n\n```python\npip install cpath\n```\n\nand import \n\n```python\nimport cpath\n```\n\nor from source \n\n```python\npip install ./cpath\nimport cpath\n```\n\nOther imports\n\n```python\nfrom imodels.util.data_util import get_clean_dataset\nimport numpy as np\nfrom sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import balanced_accuracy_score\nfrom sklearn.metrics import roc_auc_score\n\nimport sys\n```\n\nExample data set \n\n```python\nclf_datasets = [\n (\"breast-cancer\", \"breast_cancer\", \"imodels\")\n]\n\n# Read in data set\nX, y, feature_names = get_clean_dataset('breast_cancer', data_source='imodels')\n\n# train-test split\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)\n\n```\n\n### Random Forest \n\n```python\n\n# number of trees \nntrees = 10\n\nclf = RandomForestClassifier(n_estimators=ntrees) \nclf.fit(X_train, y_train)\npred = clf.predict(X_test)\n\n```\n\n### Explain using cpath\n\n```python\n\nP = cpath.cpaths(clf, X_test, y_test)\n\nT = cpath.transition(P, X_test, y_test)\n\nIMP = cpath.importance(T)\n\nIMP[\"global\"]\n\n```\n\n## Citation\nIf you find cpath please cite\n\n```\n@misc{pfeifer2023explainable,\n title={Explainable AI with counterfactual paths}, \n author={Bastian Pfeifer and Mateusz Krzyzinski and Hubert Baniecki and Anna Saranti and Andreas Holzinger and Przemyslaw Biecek},\n year={2023},\n eprint={2307.07764},\n archivePrefix={arXiv},\n primaryClass={cs.AI}\n}\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Explainable AI with counterfactual paths",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/pievos101/cpath"
},
"split_keywords": [
"explainable ai",
"counterfactuals"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2bc86b0e9ef6ba941357886bfa66dd42f5bc74d771edd9b16a84617dbfa78d5b",
"md5": "7477436e27944573d56d38d42101dbb4",
"sha256": "c39c289f377a509829a75c0689bfd61c26d88e0748350b0b27faea155ee8bb40"
},
"downloads": -1,
"filename": "cpath-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7477436e27944573d56d38d42101dbb4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8463,
"upload_time": "2023-07-25T07:35:15",
"upload_time_iso_8601": "2023-07-25T07:35:15.676513Z",
"url": "https://files.pythonhosted.org/packages/2b/c8/6b0e9ef6ba941357886bfa66dd42f5bc74d771edd9b16a84617dbfa78d5b/cpath-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e81dadddb9aff44c31f38ba5b7cc63433d544b0bafed5260c05f65c60c1201ed",
"md5": "bdcc4e8d6850a34a445098503b9fa178",
"sha256": "4aeb4618da86d962147502eaae794597c020e79bd9b24acee6e6689db618c32b"
},
"downloads": -1,
"filename": "cpath-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "bdcc4e8d6850a34a445098503b9fa178",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5351,
"upload_time": "2023-07-25T07:35:17",
"upload_time_iso_8601": "2023-07-25T07:35:17.374303Z",
"url": "https://files.pythonhosted.org/packages/e8/1d/adddb9aff44c31f38ba5b7cc63433d544b0bafed5260c05f65c60c1201ed/cpath-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-25 07:35:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pievos101",
"github_project": "cpath",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "cpath"
}