Documentation | External Resources | Research Paper
Shapley is a Python library for evaluating binary classifiers in a machine learning ensemble.
The library consists of various methods to compute (approximate) the Shapley value of players (models) in weighted voting games (ensemble games) - a class of transferable utility cooperative games. We covered the exact enumeration based computation and various widely know approximation methods from economics and computer science research papers. There are also functionalities to identify the heterogeneity of the player pool based on the Shapley entropy. In addition, the framework comes with a detailed documentation, an intuitive tutorial, 100% test coverage and illustrative toy examples.
Citing
If you find Shapley useful in your research please consider adding the following citation:
@misc{rozemberczki2021shapley,
title = {{The Shapley Value of Classifiers in Ensemble Games}},
author = {Benedek Rozemberczki and Rik Sarkar},
year = {2021},
eprint = {2101.02153},
archivePrefix = {arXiv},
primaryClass = {cs.LG}
}
A simple example
Shapley makes solving voting games quite easy - see the accompanying tutorial. For example, this is all it takes to solve a weighted voting game with defined on the fly with permutation sampling:
import numpy as np
from shapley import PermutationSampler
W = np.random.uniform(0, 1, (1, 7))
W = W/W.sum()
q = 0.5
solver = PermutationSampler()
solver.solve_game(W, q)
shapley_values = solver.get_solution()
Methods Included
In detail, the following methods can be used.
-
Expected Marginal Contribution Approximation from Fatima et al.: A Linear Approximation Method for the Shapley Value
-
Multilinear Extension from Owen: Multilinear Extensions of Games
-
Monte Carlo Permutation Sampling from Maleki et al.: Bounding the Estimation Error of Sampling-based Shapley Value Approximation
-
Exact Enumeration from Shapley: A Value for N-Person Games
Head over to our documentation to find out more about installation, creation of datasets and a full list of implemented methods and available datasets. For a quick start, check out the examples in the examples/
directory.
If you notice anything unexpected, please open an issue. If you are missing a specific method, feel free to open a feature request.
Installation
$ pip install shapley
Running tests
$ python setup.py test
Running examples
$ cd examples
$ python permutation_sampler_example.py
License