tsproto


Nametsproto JSON
Version 0.1.3 PyPI version JSON
download
home_page
SummaryPost-host prototype-based explanations with rules for time-series classifiers
upload_time2024-03-05 07:24:21
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT 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.
            # 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 note is constructed from the visual prototype
  * Integrated with SHAP explainer, as a backbone for extraction of interpretable components (However, SHAP can be replaces with any other feature-importance method)

## Install
LUX 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]()
  * Example of extracting sine wave as a prototype end explaining class by difference in frequency of a prototype [Jupyter Notebook]()

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": "",
    "name": "tsproto",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "xai,time-series,explainability,model-agnostic,rule-based",
    "author": "",
    "author_email": "Szymon Bobek <szymon.bobek@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/df/ca/4f54df8b497b75df5b981994d8946eb5d17193dd20bf3daf83de22e42c7c/tsproto-0.1.3.tar.gz",
    "platform": null,
    "description": "# 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 note is constructed from the visual prototype\n  * Integrated with SHAP explainer, as a backbone for extraction of interpretable components (However, SHAP can be replaces with any other feature-importance method)\n\n## Install\nLUX 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]()\n  * Example of extracting sine wave as a prototype end explaining class by difference in frequency of a prototype [Jupyter Notebook]()\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.1.3",
    "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": "fcaf227a7549490b36531247cd6b0e1c1894a37a5bb202e9d7be438e31319acb",
                "md5": "da38a34ea0191eb858c6201d39486699",
                "sha256": "4363fe4a00568da0608f404b717109be1a4a29fe75a5ac696d8c59c151e4d0df"
            },
            "downloads": -1,
            "filename": "tsproto-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "da38a34ea0191eb858c6201d39486699",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20256,
            "upload_time": "2024-03-05T07:24:19",
            "upload_time_iso_8601": "2024-03-05T07:24:19.028665Z",
            "url": "https://files.pythonhosted.org/packages/fc/af/227a7549490b36531247cd6b0e1c1894a37a5bb202e9d7be438e31319acb/tsproto-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dfca4f54df8b497b75df5b981994d8946eb5d17193dd20bf3daf83de22e42c7c",
                "md5": "17758867724d8a78b1ef69cf9e4d77ae",
                "sha256": "add5cfcbae48cc43537e0d1096a68c57db2f141eaa26aeb3293e9b77992e7b94"
            },
            "downloads": -1,
            "filename": "tsproto-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "17758867724d8a78b1ef69cf9e4d77ae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 20871,
            "upload_time": "2024-03-05T07:24:21",
            "upload_time_iso_8601": "2024-03-05T07:24:21.218653Z",
            "url": "https://files.pythonhosted.org/packages/df/ca/4f54df8b497b75df5b981994d8946eb5d17193dd20bf3daf83de22e42c7c/tsproto-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-05 07:24:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sbobek",
    "github_project": "tsproto",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "tsproto"
}
        
Elapsed time: 0.21957s