Forecasting explanations for global forecasters, with support for skforecast and more.
Project description
xeries
Time Series eXplainability (XAI) for Forecasting
A comprehensive Python library for explainability and interpretability in multi-time series forecasting. xeries provides multiple explanation methods—including conditional permutation importance, SHAP, feature dropping, and causal analysis—with a unified API and interactive dashboard for understanding forecast decisions.
Why xeries?
Explaining and interpreting multi-time series forecasts is challenging:
-
Standard methods fail on series-dependent features: Permutation importance and SHAP can create invalid data by pairing a lag from one series with a target from another.
-
No unified explainability framework: Most libraries offer a single method (e.g., SHAP only) with limited support for time-series-specific analysis.
-
Lack of temporal and comparative insights: Understanding performance across time windows, detecting significance, and comparing methods are difficult without custom tools.
xeries addresses these gaps with:
- Conditional explanations that respect data structure
- A focused CPI workflow for current production use
- A roadmap for future explanation methods
- A simple API for current cs-PFI workflows
Features
📊 Current Capability
- Conditional Permutation Importance (cs-PFI): Permute features only within meaningful subgroups
- Auto-discover groups using decision trees
- Define custom groups based on domain knowledge
🛣️ Planned Roadmap
- Conditional SHAP: Planned for a future release
- SHAP-IQ: Planned for a future release
- Feature Dropping: Planned for a future release
- Causal Feature Importance: Planned for a future release
📡 Framework Adapters
- scikit-learn: Direct support for sklearn estimators
- skforecast: Seamless integration with multi-series forecasters (0.21+)
- Custom Models: Wrap any forecaster with the BaseAdapter
📈 Visualization
Ready-to-use plotting utilities for feature importance and temporal analysis.
- Publication-Ready Plots:
- Feature importance bar charts
- Heatmaps comparing multiple methods or conditions
Planned:
- Interactive Dashboard: Unified interface for all explainability components
- Method comparison visualizations
- Interaction plots
- HTML Report Generation: Auto-generate dashboards with Jinja2 templates
- Jupyter Integration: Works seamlessly in notebooks
Installation
pip install xeries
With UV:
uv add xeries
For skforecast integration:
pip install xeries[skforecast]
Supported Explanation Methods
| Method | Status | Use Case | Notes |
|---|---|---|---|
| Conditional Permutation Importance | Available | Default choice; fast & interpretable | Auto/manual grouping with tree-based or manual partitioning |
| Conditional SHAP | Planned | Local & global explanations | Future release |
| SHAP-IQ | Planned | Feature interactions | Future release |
| Feature Dropping | Planned | Complementary to importance | Future release |
| Causal Feature Importance | Planned | Treatment effects | Future release |
Quick Start
Conditional Permutation Importance (Default)
from sklearn.ensemble import RandomForestRegressor
from skforecast.recursive import ForecasterRecursiveMultiSeries
from xeries import ConditionalPermutationImportance
from xeries.adapters.skforecast import from_skforecast
# Train your multi-series forecaster (skforecast 0.21+)
forecaster = ForecasterRecursiveMultiSeries(
estimator=RandomForestRegressor(n_estimators=100, random_state=42),
lags=24,
)
forecaster.fit(series=your_data)
# Same `series` as fit() is required for create_train_X_y (pass here or to get_training_data)
adapter = from_skforecast(forecaster, series=your_data)
X, y = adapter.get_training_data()
# Compute conditional importance (automatic tree-based cs-PFI)
explainer = ConditionalPermutationImportance(
model=adapter,
metric='mse',
strategy='auto',
n_repeats=5,
random_state=42,
)
result = explainer.explain(X, y, features=['lag_1', 'lag_2', 'lag_3'])
print(result.to_dataframe())
Using Manual Groups
from xeries import ManualPartitioner, ConditionalPermutationImportance
# Domain groups: with skforecast 0.21+ wide data, series are ordinal-encoded in X.
# Map integers 0,1,... in the same order as forecaster.series_names_in_ (see adapter.forecaster).
mapping = {
0: 'urban',
1: 'suburban',
2: 'urban',
}
partitioner = ManualPartitioner(mapping, series_col=adapter.get_series_column())
explainer = ConditionalPermutationImportance(
model=adapter,
metric='mse',
strategy='manual',
partitioner=partitioner,
)
result = explainer.explain(X, y)
Visualization
from xeries.visualization import plot_importance_bar, plot_importance_heatmap
# Bar chart
fig, ax = plot_importance_bar(result, max_features=10)
# Heatmap comparing multiple cs-PFI configurations
results = {'Auto': result_auto, 'Manual': result_manual}
fig, ax = plot_importance_heatmap(results)
Planned Methods
The following methods are planned for future releases and are not part of the current release:
- Conditional SHAP
- SHAP-IQ
- Feature Dropping
- Causal Feature Importance
Documentation
Full documentation is available at https://thec0dewriter.github.io/xeries
Development
Clone the repository:
git clone https://github.com/thec0dewriter/xeries.git
cd xeries
Install with development dependencies:
uv sync --dev
Run tests:
uv run pytest
Run linting:
uv run ruff check src tests
uv run ruff format src tests
Type checking:
uv run ty check src
Build documentation:
uv sync --group docs
uv run mkdocs serve
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this library in your research, please cite:
@software{xeries,
title = {xeries: Time Series eXplainability for Forecasting},
author = {Kuti-Kreszács, Mátyás},
year = {2026},
doi = {10.5281/zenodo.19482748},
publisher = {Zenodo},
url = {https://github.com/thec0dewriter/xeries},
}
Related Publications
This project is informed by the following techniques and references:
- Conditional Subgroup Permutation Feature Importance (cs-PFI)
- SHAP (SHapley Additive exPlanations) — Lundberg & Lee, 2017
- SHAP Interaction Values — Janzing et al., 2020
- Controlled Feature Dropping — Model modification for importance estimation
- Causal Inference using DoWhy and EconML frameworks
- skforecast — Multi-series forecasting framework
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 xeries-0.2.0.tar.gz.
File metadata
- Download URL: xeries-0.2.0.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01e04c8ecb5b994323991b7fbef0cc7fb0924af51dfe105df1f2c1a06804f24c
|
|
| MD5 |
1f814cbcb07e0417031295e9966bb4dc
|
|
| BLAKE2b-256 |
5b0e70a373ba00dc93244cb9e91b4e144e847e07d25f3db0cf6d6a09947e9522
|
Provenance
The following attestation bundles were made for xeries-0.2.0.tar.gz:
Publisher:
release.yml on thec0dewriter/xeries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xeries-0.2.0.tar.gz -
Subject digest:
01e04c8ecb5b994323991b7fbef0cc7fb0924af51dfe105df1f2c1a06804f24c - Sigstore transparency entry: 1271040587
- Sigstore integration time:
-
Permalink:
thec0dewriter/xeries@8f9811f2004447b283ea4bd40c0086446d85e85a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/thec0dewriter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8f9811f2004447b283ea4bd40c0086446d85e85a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file xeries-0.2.0-py3-none-any.whl.
File metadata
- Download URL: xeries-0.2.0-py3-none-any.whl
- Upload date:
- Size: 28.4 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 |
de756499d0a1566f8a08983c2d687f005443b22000422706ec8d07e2bfe86e3a
|
|
| MD5 |
2403f490645ffe2f0f6d07c1f49a8327
|
|
| BLAKE2b-256 |
0bae47285bf056369a08838332f2dac0608f79ae1e14d210e110e4b569abe1c8
|
Provenance
The following attestation bundles were made for xeries-0.2.0-py3-none-any.whl:
Publisher:
release.yml on thec0dewriter/xeries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xeries-0.2.0-py3-none-any.whl -
Subject digest:
de756499d0a1566f8a08983c2d687f005443b22000422706ec8d07e2bfe86e3a - Sigstore transparency entry: 1271040609
- Sigstore integration time:
-
Permalink:
thec0dewriter/xeries@8f9811f2004447b283ea4bd40c0086446d85e85a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/thec0dewriter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8f9811f2004447b283ea4bd40c0086446d85e85a -
Trigger Event:
workflow_dispatch
-
Statement type: