Name | tsproto JSON |
Version |
0.3.0
JSON |
| download |
home_page | None |
Summary | Post-host prototype-based explanations with rules for time-series classifiers |
upload_time | 2024-09-11 11:58:25 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2024 Szymon Bobek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
xai
time-series
explainability
model-agnostic
rule-based
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![PyPI](https://img.shields.io/pypi/v/tsproto)](https://pypi.org/project/tsproto/) ![License](https://img.shields.io/github/license/sbobek/tsproto)
![PyPI - Downloads](https://img.shields.io/pypi/dm/tsproto) [![Documentation Status](https://readthedocs.org/projects/tsproto/badge/?version=latest)](https://tsproto.readthedocs.io/en/latest/?badge=latest)
![](https://raw.githubusercontent.com/sbobek/tsproto/main/pix/workflow.svg)
# TSProto
Post-host prototype-based explanations with rules for time-series classifiers.
Key features:
* Extracts interpretable prototype for any black-box model and creates a decision tree, where each node is constructed from the visual prototype
* Integrated with SHAP explainer, as a backbone for extraction of interpretable components (However, SHAP can be replaced with any other feature-importance method)
## Install
TSProto can be installed from either [PyPI](https://pypi.org/project/tsproto/) or directly from source code from this repository.
To install form PyPI:
```
pip install tsproto
````
To install from source code:
```
git clone https://github.com/sbobek/tsproto
cd tsproto
pip install .
```
## Usage
For full examples on two illustrative cases go to:
* Example of extracting sine wave prototype and explaining class with existence ora absence of a prototype: [Jupyter Notebook](https://github.com/sbobek/tsproto/blob/main/examples/illustrative-example-frequency.ipynb)
* Example of extracting sine wave as a prototype end explaining class by difference in frequency of a prototype [Jupyter Notebook](https://github.com/sbobek/tsproto/blob/main/examples/illustrative-example.ipynb)
The basic usage of the TSProto assuming you have your model trained is straightforward:
``` python
from tsproto.models import *
from tsproto.utils import *
#assuming that trainX, trainy and model are given
pe = PrototypeEncoder(clf, n_clusters=2, min_size=50, method='dtw',
descriptors=['existance'],
jump=1, pen=1,multiplier=2,n_jobs=-1,
verbose=1)
trainX, shapclass = getshap(model=model, X=trainX, y=trainy,shap_version='deep',
bg_size = 1000, absshap = True)
#The input needs to be a 3D vector: number of samples, lenght of time-series, number of dimensions (features)
trainXproto = train.reshape((trainX.shape[0], trainX.shape[1],1))
shapclassXproto = shapclass.reshape((shapclass.shape[0], shapclass.shape[1],1))
ohe_train, features, target_ohe,weights = pe.fit_transform(trainXproto,shapclassXproto)
im = InterpretableModel()
acc,prec,rec,f1,interpretable_model = im.fit_or_predict(ohe_train, features,
target_ohe,
intclf=None, # if intclf is given, the funciton behaves as predict,
verbose=0, max_depth=2, min_samples_leaf=0.05,
weights=None)
```
After the Interpretable model has been created it now can be visualised.
``` python
# Visualize model
from tsproto.plots import *
ds_final = ohe_train.copy()
dot = export_decision_tree_with_embedded_histograms(decision_tree=interpretable_model,
dataset=ds_final,
target_name='target',
feature_names=features,
filename='synthetic',
proto_encoder=pe, figsize=(6,3))
from IPython.display import SVG, Image
Image('synthetic.png')
```
![Prototype visualization](https://raw.githubusercontent.com/sbobek/tsproto/main/pix/illustrative-example.png "Title")
## Cite this work
More details on how the TSProto works and evaluation benchmarks can eb found in the following paper:
```Comming soon```
Raw data
{
"_id": null,
"home_page": null,
"name": "tsproto",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "xai, time-series, explainability, model-agnostic, rule-based",
"author": null,
"author_email": "Szymon Bobek <szymon.bobek@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ee/b6/4841ba486575aae106634e6ff7d5a95270541496a658d732ea5d4e3ad596/tsproto-0.3.0.tar.gz",
"platform": null,
"description": "[![PyPI](https://img.shields.io/pypi/v/tsproto)](https://pypi.org/project/tsproto/) ![License](https://img.shields.io/github/license/sbobek/tsproto)\n ![PyPI - Downloads](https://img.shields.io/pypi/dm/tsproto) [![Documentation Status](https://readthedocs.org/projects/tsproto/badge/?version=latest)](https://tsproto.readthedocs.io/en/latest/?badge=latest)\n \n![](https://raw.githubusercontent.com/sbobek/tsproto/main/pix/workflow.svg)\n# TSProto\nPost-host prototype-based explanations with rules for time-series classifiers.\n\nKey features:\n * Extracts interpretable prototype for any black-box model and creates a decision tree, where each node is constructed from the visual prototype\n * Integrated with SHAP explainer, as a backbone for extraction of interpretable components (However, SHAP can be replaced with any other feature-importance method)\n\n## Install\nTSProto can be installed from either [PyPI](https://pypi.org/project/tsproto/) or directly from source code from this repository.\n\nTo install form PyPI:\n\n```\npip install tsproto\n````\n\nTo install from source code:\n\n```\ngit clone https://github.com/sbobek/tsproto\ncd tsproto\npip install .\n```\n\n## Usage\nFor full examples on two illustrative cases go to:\n * Example of extracting sine wave prototype and explaining class with existence ora absence of a prototype: [Jupyter Notebook](https://github.com/sbobek/tsproto/blob/main/examples/illustrative-example-frequency.ipynb)\n * Example of extracting sine wave as a prototype end explaining class by difference in frequency of a prototype [Jupyter Notebook](https://github.com/sbobek/tsproto/blob/main/examples/illustrative-example.ipynb)\n\nThe basic usage of the TSProto assuming you have your model trained is straightforward:\n\n``` python\nfrom tsproto.models import *\nfrom tsproto.utils import *\n\n#assuming that trainX, trainy and model are given\n\npe = PrototypeEncoder(clf, n_clusters=2, min_size=50, method='dtw',\n descriptors=['existance'],\n jump=1, pen=1,multiplier=2,n_jobs=-1,\n verbose=1)\n\ntrainX, shapclass = getshap(model=model, X=trainX, y=trainy,shap_version='deep',\n bg_size = 1000, absshap = True)\n\n#The input needs to be a 3D vector: number of samples, lenght of time-series, number of dimensions (features)\ntrainXproto = train.reshape((trainX.shape[0], trainX.shape[1],1))\nshapclassXproto = shapclass.reshape((shapclass.shape[0], shapclass.shape[1],1))\n\nohe_train, features, target_ohe,weights = pe.fit_transform(trainXproto,shapclassXproto)\n\nim = InterpretableModel()\nacc,prec,rec,f1,interpretable_model = im.fit_or_predict(ohe_train, features,\n target_ohe,\n intclf=None, # if intclf is given, the funciton behaves as predict,\n verbose=0, max_depth=2, min_samples_leaf=0.05,\n weights=None)\n \n```\n\nAfter the Interpretable model has been created it now can be visualised.\n\n``` python\n \n# Visualize model\nfrom tsproto.plots import *\n\nds_final = ohe_train.copy()\ndot = export_decision_tree_with_embedded_histograms(decision_tree=interpretable_model, \n dataset=ds_final, \n target_name='target', \n feature_names=features, \n filename='synthetic', \n proto_encoder=pe, figsize=(6,3))\n\nfrom IPython.display import SVG, Image\nImage('synthetic.png')\n\n```\n\n![Prototype visualization](https://raw.githubusercontent.com/sbobek/tsproto/main/pix/illustrative-example.png \"Title\")\n\n\n## Cite this work\nMore details on how the TSProto works and evaluation benchmarks can eb found in the following paper:\n\n```Comming soon```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Szymon Bobek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Post-host prototype-based explanations with rules for time-series classifiers",
"version": "0.3.0",
"project_urls": {
"Documentation": "https://tsproto.readthedocs.org",
"Homepage": "https://github.com/sbobek/tsproto",
"Issues": "https://github.com/sbobek/tsproto/issues"
},
"split_keywords": [
"xai",
" time-series",
" explainability",
" model-agnostic",
" rule-based"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "22588f80e888cfbcd8439838bd39a0b93921b4853030dafd9edd6e4986ff0600",
"md5": "b0169eb238a6760ab75d8ee545d477ff",
"sha256": "629dac189813233cf949c4ca42619ba8c01deb44878205f75e4bd84be2e89f06"
},
"downloads": -1,
"filename": "tsproto-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b0169eb238a6760ab75d8ee545d477ff",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 23543,
"upload_time": "2024-09-11T11:58:23",
"upload_time_iso_8601": "2024-09-11T11:58:23.559508Z",
"url": "https://files.pythonhosted.org/packages/22/58/8f80e888cfbcd8439838bd39a0b93921b4853030dafd9edd6e4986ff0600/tsproto-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "eeb64841ba486575aae106634e6ff7d5a95270541496a658d732ea5d4e3ad596",
"md5": "04f1a199986bcc766781b5041a894f9c",
"sha256": "6d96839062861057c43e841c9bdada95bcb31c0345abcd0c361114cd64a50257"
},
"downloads": -1,
"filename": "tsproto-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "04f1a199986bcc766781b5041a894f9c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 24403,
"upload_time": "2024-09-11T11:58:25",
"upload_time_iso_8601": "2024-09-11T11:58:25.176313Z",
"url": "https://files.pythonhosted.org/packages/ee/b6/4841ba486575aae106634e6ff7d5a95270541496a658d732ea5d4e3ad596/tsproto-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-11 11:58:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sbobek",
"github_project": "tsproto",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tsproto"
}