An evaluation framework for eXplainable AI (XAI) methods applied to Time Series Classification (TSC).
Project description
XAI4TSC
An evaluation framework for eXplainable AI (XAI) methods applied to Time Series Classification (TSC), developed by the TimeXAI Research Group.
XAI4TSC has two independent use cases:
- Standalone experiment runner: Clone the repo, choose or adapt a YAML config, run experiments from the command line.
- Importable Python package:
pip install xai4tscand use the public API in your own code, notebooks, or scripts.
The documentation can be found here: https://timexaigroup.github.io/XAI4TSC/
Installation
Standalone (experiment runner)
We use Poetry for package management inside a Conda environment:
-
Clone the repository:
git clone https://github.com/TimeXAI-group/XAI4TSC.git cd XAI4TSC
-
Create a python environment (choose one of the following):
2.1. Using python:python -m venv .venv # Use python 3.12 or 3.13 source .venv/bin/activate
2.2. Using conda:
conda env create # picks up environment.yml conda activate xai4tsc
-
Install the dependencies (choose one of the following):
3.1. Using poetry:pip install poetry # only needed if the local python .venv is used poetry install
3.2. Using pip and PyPI:
pip install xai4tsc
3.3. Using pip and a local installation:
pip install -e .
Package only
pip install xai4tsc
Or, for a local/editable install from a clone:
pip install -e PATH/TO/REPOSITORY
Project layout
xai4tsc/
├── experiment_runner/ # Standalone CLI — owns all config and orchestration logic
│ ├── main.py # Entry point: python -m experiment_runner.main --conf ...
│ ├── config.py # Config loading, validation, defaults
│ ├── cache.py # Runner-level split caching helpers
│ ├── explain.py # Runner adapter for xai4tsc.xai
│ ├── evaluate.py # Runner adapter for xai4tsc.evaluation
│ ├── log_setup.py # Logging setup for the standalone runner
│ └── configs/
│ ├── master.yaml # Annotated reference — all available options and defaults
│ ├── example.yaml # Go-to demo: synthetic data, time-domain explainers + metrics
│ ├── example_frequency.yaml # Frequency / time-frequency showcase (FreqRISE, freq metrics)
│ ├── ucr_benchmark.yaml # Full UCR sweep (LeNet + Integrated Gradients + Complexity)
│ └── uea_benchmark.yaml # Full UEA sweep (skips OOM-risky datasets)
│
├── src/xai4tsc/ # Importable package
│ ├── data/
│ │ ├── datasets.py # UcrUeaDataset, LocalDataset, SyntheticDataset
│ │ └── ... # base classes, data loaders
│ ├── models/ # ModelBase, built-in models, registry
│ ├── xai/ # Explainer ABC, generate_explanation(), built-in explainers
│ ├── evaluation/ # evaluate(), Quantus metric registry
│ └── utils/ # Shared utilities (dict_to_args, merge_dicts, rescale_array, plot)
│
└── tests/
├── conftest.py # Session-scoped fixtures (GunPoint download, split, model)
├── fixtures/
│ └── test_config.yaml # Minimal runner config for integration tests
├── unit/ # Fast, no-I/O tests (@pytest.mark.unit)
└── integration/ # Full pipeline tests (@pytest.mark.integration)
Running an experiment
Run the runner as a module from the repository root:
python -m experiment_runner.main --conf experiment_runner/configs/example.yaml
python -m experiment_runner.main --conf experiment_runner/configs/example.yaml --debug
Four ready-to-run configs ship under experiment_runner/configs/:
example.yaml— the go-to demo (and the default when--confis omitted): the syntheticfreq_shapesdataset, two models, and time-domain explainers and metrics. Needs no download.example_frequency.yaml— the same dataset explained with FreqRISE in the frequency and time-frequency domains, scored with the frequency metrics.ucr_benchmark.yaml/uea_benchmark.yaml— full-archive sweeps with a minimal model/explainer/metric stack.
Edit or copy any of them to configure datasets, models, explainers, and metrics.
master.yaml contains annotated documentation for every available option.
Testing
The test suite uses two pytest markers to separate fast unit tests from slow integration tests that require a live dataset and a training run.
# Unit tests only — fast, no I/O, no training
pytest -m unit
# Integration tests only — downloads GunPoint on first run, trains a model
pytest -m integration
# Full suite
pytest
GunPoint is downloaded automatically on the first integration run and cached in
tests/cache/ (override with the XAI4TSC_TEST_CACHE environment variable).
Using xai4tsc as a package
import xai4tsc
from xai4tsc.data import load_dataset, LocalDataset
from xai4tsc.models.models import load_model
from xai4tsc.xai.explain import generate_explanation
from xai4tsc.evaluation.evaluate import evaluate
# ── Load data (UCR download or local numpy files) ─────────────────────────────
ds = load_dataset("GunPoint") # UcrUeaDataset — downloads on first use
# ds = LocalDataset("/path/to/data", name="MyDataset") # local data.npy + labels.json
splits, encoder = ds.split(
train_split=0.8, val_split=0.1, random_state=42, encode="label"
)
train_data, train_labels, _ = splits[0]
test_data, test_labels, _ = splits[1]
# ── Train a model ─────────────────────────────────────────────────────────────
model = load_model(
{"model": "FCN", "init_params": {"in_channels": 1, "num_classes": 2}},
device="cpu",
)
model.train_model(
train_data, train_labels,
hyperparams={"epochs": 50, "batchsize": 32, "loss_func": "CrossEntropy",
"optimizer": "adam", "learn_rate": 0.001, "patience": 10},
save_path="results", # best checkpoint + training plots land here
)
# ── Generate explanations ─────────────────────────────────────────────────────
exp = generate_explanation(
method="integrated_gradients",
model=model,
data=test_data,
labels=test_labels,
encoder=encoder,
indices=[0, 1, 2],
device="cpu",
)
# exp.exp_values — numpy array, same shape as test_data[[0, 1, 2]]
# ── Evaluate ──────────────────────────────────────────────────────────────────
score = evaluate(
model=model,
metric="Complexity",
explanation=exp,
data=test_data[exp.indices],
labels=test_labels[exp.indices],
metric_class_params={"normalise": True, "abs": True, "disable_warnings": True},
device="cpu",
)
# ── Register a custom explainer ───────────────────────────────────────────────
from captum.attr import Saliency
from xai4tsc import GradientExplainer, register_explainer
class SaliencyExplainer(GradientExplainer):
def _get_captum_attribution(self, model):
return Saliency(model)
register_explainer("saliency", SaliencyExplainer)
exp2 = generate_explanation(
"saliency", model=model, data=test_data,
labels=test_labels, encoder=encoder, indices=[0], device="cpu",
)
Built on
- Computational backends: PyTorch, scikit-learn
- Explanation backend: Captum
- Evaluation backend: Quantus
Contributing
Contributions are welcome. See CONTRIBUTING.md for the
development setup, code style and quality gate, testing conventions, and the
pattern for adding a new model, explainer, or metric. By participating you agree
to the Code of Conduct. The project is released under the
MIT License.
Disclaimer
XAI4TSC bundles clean-room re-implementations of models, explainers, and metrics from the research literature, alongside thin wrappers around third-party libraries (Captum, Quantus). These implementations have not been verified by the original authors and may differ from the source papers or reference code in ways that affect results.
Evaluation scores are an empirical, sometimes contested, proxy for explanation quality — treat them as guidance, not ground truth. When using XAI4TSC for research, cite the original papers, state which implementation you used, and, where possible, validate against a reference implementation. See the full disclaimer in the documentation for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xai4tsc-1.1.0.tar.gz.
File metadata
- Download URL: xai4tsc-1.1.0.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e644df3b33b97089799e50aef406e6788ef63e82c8711009a0e7ba5acb601b79
|
|
| MD5 |
ad6e0d17bdbc1dfb7b639148ea91dfb8
|
|
| BLAKE2b-256 |
07d44e30787dff4cf174f275d00b9c4d93e55de1302171c7795c0fe5cad5d057
|
Provenance
The following attestation bundles were made for xai4tsc-1.1.0.tar.gz:
Publisher:
publish.yml on TimeXAIgroup/XAI4TSC
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xai4tsc-1.1.0.tar.gz -
Subject digest:
e644df3b33b97089799e50aef406e6788ef63e82c8711009a0e7ba5acb601b79 - Sigstore transparency entry: 2057152043
- Sigstore integration time:
-
Permalink:
TimeXAIgroup/XAI4TSC@2579747b5cd42479b9cac9453c63d47455900335 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/TimeXAIgroup
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2579747b5cd42479b9cac9453c63d47455900335 -
Trigger Event:
release
-
Statement type:
File details
Details for the file xai4tsc-1.1.0-py3-none-any.whl.
File metadata
- Download URL: xai4tsc-1.1.0-py3-none-any.whl
- Upload date:
- Size: 100.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
484ef50e4545a467600ff091d3b7880928949e7f3676c415c00e3d08ba35db5b
|
|
| MD5 |
92dc8d3ecf60a26799388b11161569e9
|
|
| BLAKE2b-256 |
105c9f39fdc66c9bde9b81c026665963a1a5f26102c46387f1d075214b6f0baa
|
Provenance
The following attestation bundles were made for xai4tsc-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on TimeXAIgroup/XAI4TSC
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xai4tsc-1.1.0-py3-none-any.whl -
Subject digest:
484ef50e4545a467600ff091d3b7880928949e7f3676c415c00e3d08ba35db5b - Sigstore transparency entry: 2057152265
- Sigstore integration time:
-
Permalink:
TimeXAIgroup/XAI4TSC@2579747b5cd42479b9cac9453c63d47455900335 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/TimeXAIgroup
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2579747b5cd42479b9cac9453c63d47455900335 -
Trigger Event:
release
-
Statement type: