Skip to main content

HyperSHAP is a post-hoc explanation method for hyperparameter optimization.

Project description

HyperSHAP HyperSHAP Logo

Release Build status Coverage Status Commit activity License

HyperSHAP – a game‑theoretic Python library for explaining Hyperparameter Optimization (HPO). It uses Shapley values and interaction indices to provide both local and global insights into how individual hyper‑parameters (and their interactions) affect a model’s performance.

Table of Contents


Features

  • Additive Shapley decomposition of any performance metric across hyper‑parameters.
  • Interaction analysis via the Faithful Shapley Interaction Index (FSII).
  • Ready‑made explanation tasks for Ablation, Tunability, and Optimizer Bias studies.
  • Integrated visualisation (SI‑graph) for interaction effects.
  • Works with any surrogate model that follows the ExplanationTask interface.

Installation

$ make install

Getting Started

Given an existing setup with a ConfigurationSpace from the ConfigSpace package and black-box function as follows:

from ConfigSpace import ConfigurationSpace, Configuration

# ConfigurationSpace describing the hyperparameter space
cs = ConfigurationSpace()
  ...

# A black-box function, evaluating ConfigSpace.Configuration objects
def blackbox_function(cfg: Configuration) -> float:
  ...

You can use HyperSHAP as follows:

from hypershap import ExplanationTask, HyperSHAP

# Instantiate HyperSHAP
hypershap = HyperSHAP(ExplanationTask.from_function(config_space=cs,function=blackbox_function))
# Conduct tunability analysis
hypershap.tunability(baseline_config=cs.get_default_configuration())
# Plot results as a Shapley Interaction graph
hypershap.plot_si_graph()

The example demonstrates how to:

  1. Wrap a black-box function in an explanation task.
  2. Use HyperSHAP to obtain interaction values for the tunability game.
  3. Plot the corresponding SI-graph.

API Overview

Method Purpose Key Arguments
HyperSHAP(explanation_task) Initialise the explainer with a generic ExplanationTask.
ablation(config_of_interest, baseline_config, index="FSII", order=2) Explain the contribution of each hyperparameter value (and interactions) when moving from a baseline to a specific configuration.
tunability(baseline_config=None, index="FSII", order=2, n_samples=10_000) Quantify how much performance can be gained by tuning subsets of hyper‑parameters.
optimizer_bias(optimizer_of_interest, optimizer_ensemble, index="FSII", order=2) Attribute performance differences to a particular optimizer vs. an ensemble of optimizers.
plot_si_graph(interaction_values=None, save_path=None) Plot the Shapley Interaction (SI) graph; uses the most recent interaction values if none are supplied.
ExplanationTask.get_hyperparameter_names() Helper to retrieve ordered hyper‑parameter names (used for visualisation).

All methods return an InteractionValues object (from shapiq) that can be inspected, saved, or passed to the visualisation routine.


Example Notebooks

Full Jupyter notebooks illustrating all three explanation tasks (ablation, tunability, optimizer bias) are included in the repository under examples/. The notebookts walk through:

  • Building a mockup environment
  • Creating the corresponding explanation task
  • Loading explanation tasks from different setups: data, black-box function, and existing surrogate model.
  • Computing interaction values with HyperSHAP
  • Visualizing results with plot_si_graph

Citation

If you use HyperSHAP in your research, please cite the original paper:

@article{wever-arxiv25,
  author       = {Marcel Wever and
                  Maximilian Muschalik and
                  Fabian Fumagalli and
                  Marius Lindauer},
  title        = {HyperSHAP: Shapley Values and Interactions for Hyperparameter Importance},
  journal      = {CoRR},
  volume       = {abs/2502.01276},
  year         = {2025},
  doi          = {10.48550/ARXIV.2502.01276},
}

The paper introduces the underlying game-theoretic framework and demonstrates its usefulness for HPO explainability.

Contributing

Contributions are welcome! Please follow these steps:

 Fork the repo and create a feature branch (git checkout -b feat/your-feature).
 Write tests (the project uses pytest).
 Ensure all tests pass (pytest).
 Update documentation if you add new functionality.
 Submit a Pull Request with a clear description of the changes.

See CONTRIBUTING.md for detailed guidelines.


License

HyperSHAP is released under the BSD 3-Clause License. See the LICENSE file for full terms.


Enjoy exploring your HPO pipelines with HyperSHAP! 🎉


Repository initiated with fpgmaas/cookiecutter-uv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypershap-0.0.2.tar.gz (296.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypershap-0.0.2-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file hypershap-0.0.2.tar.gz.

File metadata

  • Download URL: hypershap-0.0.2.tar.gz
  • Upload date:
  • Size: 296.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for hypershap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b58dd0399bad1e7359ea2f0e08f372b8602cb5a0013e0c280fd304a6494696bf
MD5 1fa471c1af0b8b3a1db228d8022f468b
BLAKE2b-256 cbe242aefb98343a585d50823a802ca0b414a5455162905141eb983f9698374b

See more details on using hashes here.

File details

Details for the file hypershap-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: hypershap-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for hypershap-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ff0e4d5be6c617ae4fbac948ac064683ae64961af6df0b89b839d28ce2cd956
MD5 17b916462bda6963866dfc663b2194d5
BLAKE2b-256 5bf9bd7b146531265f017bf14a99bc0dc37ff9aa32bf3de48e465cf26f59ea10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page