|
1 | | -# hypershap |
| 1 | +# HyperSHAP |
2 | 2 |
|
3 | 3 | [](https://img.shields.io/github/v/release/mwever/hypershap) |
4 | 4 | [](https://github.com/mwever/hypershap/actions/workflows/main.yml?query=branch%3Amain) |
5 | 5 | [](https://codecov.io/gh/mwever/hypershap) |
6 | 6 | [](https://img.shields.io/github/commit-activity/m/mwever/hypershap) |
7 | 7 | [](https://img.shields.io/github/license/mwever/hypershap) |
8 | 8 |
|
9 | | -HyperSHAP is a post-hoc explanation method for hyperparameter optimization. |
| 9 | +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. |
10 | 10 |
|
11 | | -- **Github repository**: <https://github.com/mwever/hypershap/> |
12 | | -- **Documentation** <https://mwever.github.io/hypershap/> |
| 11 | +- **Github repository**: <https://github.com/automl/hypershap/> |
| 12 | +- **Documentation** <https://automl.github.io/hypershap/> |
13 | 13 |
|
14 | | -## Getting started with your project |
15 | 14 |
|
16 | | -### 1. Create a New Repository |
| 15 | +## Table of Contents |
| 16 | +- [Features](#features) |
| 17 | +- [Installation](#installation) |
| 18 | +- [Getting Started](#getting-started) |
| 19 | +- [API Overview](#api-overview) |
| 20 | +- [Example Notebook](#example-notebook) |
| 21 | +- [Citation](#citation) |
| 22 | +- [Contributing](#contributing) |
| 23 | +- [License](#license) |
17 | 24 |
|
18 | | -First, create a repository on GitHub with the same name as this project, and then run the following commands: |
| 25 | +--- |
19 | 26 |
|
20 | | -```bash |
21 | | -git init -b main |
22 | | -git add . |
23 | | -git commit -m "init commit" |
24 | | -git remote add origin git@github.com:mwever/hypershap.git |
25 | | -git push -u origin main |
26 | | -``` |
| 27 | +## Features |
| 28 | +- **Additive Shapley decomposition** of any performance metric across hyper‑parameters. |
| 29 | +- **Interaction analysis** via the Faithful Shapley Interaction Index (FSII). |
| 30 | +- Ready‑made explanation tasks for **Ablation**, **Tunability**, and **Optimizer Bias** studies. |
| 31 | +- Integrated **visualisation** (SI‑graph) for interaction effects. |
| 32 | +- Works with any surrogate model that follows the `ExplanationTask` interface. |
27 | 33 |
|
28 | | -### 2. Set Up Your Development Environment |
| 34 | +--- |
29 | 35 |
|
30 | | -Then, install the environment and the pre-commit hooks with |
| 36 | +## Installation |
31 | 37 |
|
32 | | -```bash |
33 | | -make install |
| 38 | +```sh |
| 39 | +$ make install |
34 | 40 | ``` |
35 | 41 |
|
36 | | -This will also generate your `uv.lock` file |
| 42 | +## Getting Started |
| 43 | +Given an existing setup with a ConfigurationSpace from the [ConfigSpace package](https://github.com/automl/ConfigSpace) and black-box function as follows: |
| 44 | +```Python |
| 45 | +from ConfigSpace import ConfigurationSpace, Configuration |
37 | 46 |
|
38 | | -### 3. Run the pre-commit hooks |
| 47 | +# ConfigurationSpace describing the hyperparameter space |
| 48 | +cs = ConfigurationSpace() |
| 49 | + ... |
39 | 50 |
|
40 | | -Initially, the CI/CD pipeline might be failing due to formatting issues. To resolve those run: |
| 51 | +# A black-box function, evaluating ConfigSpace.Configuration objects |
| 52 | +def blackbox_function(cfg: Configuration) -> float: |
| 53 | + ... |
| 54 | +``` |
| 55 | + |
| 56 | +You can use HyperSHAP as follows: |
| 57 | +```Python |
| 58 | +from hypershap import ExplanationTask, HyperSHAP |
41 | 59 |
|
42 | | -```bash |
43 | | -uv run pre-commit run -a |
| 60 | +# Instantiate HyperSHAP |
| 61 | +hypershap = HyperSHAP(ExplanationTask.from_function(config_space=cs,function=blackbox_function)) |
| 62 | +# Conduct tunability analysis |
| 63 | +hypershap.tunability(baseline_config=cs.get_default_configuration()) |
| 64 | +# Plot results as a Shapley Interaction graph |
| 65 | +hypershap.plot_si_graph() |
44 | 66 | ``` |
45 | 67 |
|
46 | | -### 4. Commit the changes |
| 68 | +The example demonstrates how to: |
| 69 | +1. Wrap a black-box function in an explanation task. |
| 70 | +2. Use `HyperSHAP` to obtain interaction values for the **tunability** game. |
| 71 | +3. Plot the corresponding SI-graph. |
47 | 72 |
|
48 | | -Lastly, commit the changes made by the two steps above to your repository. |
| 73 | +--- |
| 74 | + |
| 75 | +## API Overview |
| 76 | + |
| 77 | +| Method | Purpose | Key Arguments | |
| 78 | +|--------|---------|---------------| |
| 79 | +| `HyperSHAP(explanation_task)` | Initialise the explainer with a generic `ExplanationTask`. | |
| 80 | +| `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. | |
| 81 | +| `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. | |
| 82 | +| `optimizer_bias(optimizer_of_interest, optimizer_ensemble, index="FSII", order=2)` | Attribute performance differences to a particular optimizer vs. an ensemble of optimizers. | |
| 83 | +| `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. | |
| 84 | +| `ExplanationTask.get_hyperparameter_names()` | Helper to retrieve ordered hyper‑parameter names (used for visualisation). | |
| 85 | + |
| 86 | +All methods return an `InteractionValues` object (from **shapiq**) that can be inspected, saved, or passed to the visualisation routine. |
| 87 | + |
| 88 | +--- |
49 | 89 |
|
50 | | -```bash |
51 | | -git add . |
52 | | -git commit -m 'Fix formatting issues' |
53 | | -git push origin main |
| 90 | +## Example Notebooks |
| 91 | +Full Jupyter notebooks illustrating all three explanation tasks (ablation, tunability, optimizer bias) are included in the repository under `examples/`. The notebookts walk through: |
| 92 | + |
| 93 | +- Building a mockup environment |
| 94 | +- Creating the corresponding explanation task |
| 95 | +- Loading explanation tasks from different setups: data, black-box function, and existing surrogate model. |
| 96 | +- Computing interaction values with HyperSHAP |
| 97 | +- Visualizing results with `plot_si_graph` |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Citation |
| 102 | +If you use HyperSHAP in your research, please cite the original paper: |
| 103 | + |
| 104 | +```bibtex |
| 105 | +@article{wever-arxiv25, |
| 106 | + author = {Marcel Wever and |
| 107 | + Maximilian Muschalik and |
| 108 | + Fabian Fumagalli and |
| 109 | + Marius Lindauer}, |
| 110 | + title = {HyperSHAP: Shapley Values and Interactions for Hyperparameter Importance}, |
| 111 | + journal = {CoRR}, |
| 112 | + volume = {abs/2502.01276}, |
| 113 | + year = {2025}, |
| 114 | + doi = {10.48550/ARXIV.2502.01276}, |
| 115 | +} |
54 | 116 | ``` |
55 | 117 |
|
56 | | -You are now ready to start development on your project! |
57 | | -The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release. |
| 118 | +The paper introduces the underlying game-theoretic framework and demonstrates its usefulness for HPO explainability. |
| 119 | + |
| 120 | +## Contributing |
58 | 121 |
|
59 | | -To finalize the set-up for publishing to PyPI, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/publishing/#set-up-for-pypi). |
60 | | -For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/mkdocs/#enabling-the-documentation-on-github). |
61 | | -To enable the code coverage reports, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/codecov/). |
| 122 | +Contributions are welcome! Please follow these steps: |
62 | 123 |
|
63 | | -## Releasing a new version |
| 124 | + Fork the repo and create a feature branch (git checkout -b feat/your-feature). |
| 125 | + Write tests (the project uses pytest). |
| 126 | + Ensure all tests pass (pytest). |
| 127 | + Update documentation if you add new functionality. |
| 128 | + Submit a Pull Request with a clear description of the changes. |
64 | 129 |
|
65 | | -- Create an API Token on [PyPI](https://pypi.org/). |
66 | | -- Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting [this page](https://github.com/mwever/hypershap/settings/secrets/actions/new). |
67 | | -- Create a [new release](https://github.com/mwever/hypershap/releases/new) on Github. |
68 | | -- Create a new tag in the form `*.*.*`. |
69 | 130 |
|
70 | | -For more details, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/cicd/#how-to-trigger-a-release). |
| 131 | +See CONTRIBUTING.md for detailed guidelines. |
71 | 132 |
|
72 | 133 | --- |
73 | 134 |
|
| 135 | +## License |
| 136 | +HyperSHAP is released under the BSD 3-Clause License. See the `LICENSE` file for full terms. |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +**Enjoy exploring your HPO pipelines with HyperSHAP!** 🎉 |
| 141 | + |
| 142 | +--- |
74 | 143 | Repository initiated with [fpgmaas/cookiecutter-uv](https://github.com/fpgmaas/cookiecutter-uv). |
0 commit comments