Skip to content

Commit

Permalink
190 add a tutorial notebook for data valuation (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Advueu963 authored Oct 25, 2024
1 parent 859d526 commit b9baa1e
Show file tree
Hide file tree
Showing 3 changed files with 878 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Contents
:maxdepth: 1
:caption: TUTORIALS

notebooks/sv_calculation
notebooks/shapiq_scikit_learn
notebooks/treeshapiq_lightgbm
notebooks/visualizing_shapley_interactions
Expand All @@ -38,6 +39,7 @@ Contents
notebooks/conditional_imputer
notebooks/parallel_computation
notebooks/benchmark_approximators
notebooks/data_valuation
notebooks/core

.. toctree::
Expand Down
792 changes: 792 additions & 0 deletions docs/source/notebooks/data_valuation.ipynb

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions docs/source/notebooks/sv_calculation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Shapley Value Calculation\n",
"A popular approach to tackle the problem of XAI is to use concepts from game theory in particular cooperative game theory.\n",
"The most popular method is to use the **Shapley Values** named after Lloyd Shapley, who introduced it in 1951 with his work *\"II: The Value of an n-Person Game\"*.\n",
"\n",
"## Cooperative Game Theory\n",
"Cooperative game theory deals with the study of games in which players/participants can form groups to achieve a collective payoff. More formally a cooperative game is defined as a tuple $(N,\\nu)$ where:\n",
"- $N$ is a finite set of players\n",
"- $\\nu$ is a characteristic function that maps every coalition of players to a real number, i.e. $\\nu:2^N \\rightarrow \\mathbb{R}$\n",
"\n",
"Of particular interest is to find a concept that distributes the payoff of $\\nu(N)$ among the players, as it is assumed that the *grand coalition* $N$ is formed.\n",
"The distribution of the payoff among the players is called a *solution concept*.\n",
"\n",
"## Shapley Values: A Unique Solution Concept\n",
"Given a cooperative game $(N,\\nu)$, the Shapley value is a payoff vector dividing the total payoff $\\nu(N)$ among the players. The Shapley value of player $i$ is denoted by $\\phi_i(\\nu)$ and is defined as:\n",
"$$\n",
"\\phi_i(\\nu) := \\sum_{S \\subseteq N \\setminus \\{i\\}} \\frac{|S|!(|N|-|S|-1)!}{|N|!} [\\nu(S \\cup \\{i\\}) - \\nu(S)]\n",
"$$\n",
"and can be interpreted as the average marginal contribution of player $i$ across all possible permutations of the players.\n",
"Its popularity arises from uniquely satisfies the following properties:\n",
"- **Efficiency**: The sum of the Shapley values equals the total payoff, i.e. $\\sum_{i \\in N} \\phi_i(\\nu) = \\nu(N)$\n",
"- **Symmetry**: If two players $i$ and $j$ are such that for all coalitions $S \\subseteq N \\setminus \\{i,j\\}$, $\\nu(S \\cup \\{i\\}) = \\nu(S \\cup \\{j\\})$, then $\\phi_i(\\nu) = \\phi_j(\\nu)$\n",
"- **Additivity**: For a game $(N,\\nu + \\mu)$ based on two games $(N,\\nu)$ and $(N,\\mu)$, the Shapley value of the sum of the games is the sum of the Shapley values, i.e. $\\phi_i(\\nu + \\mu) = \\phi_i(\\nu) + \\phi_i(\\mu)$\n",
"- **Dummy Player**: If for a player $i$ is holds for all coalitions $S \\subseteq N \\setminus \\{i\\}$, $\\nu(S \\cup \\{i\\}) - \\nu(S) = \\nu(\\{i\\})$ then $\\phi_i(\\nu) = \\nu(\\{i\\})$\n",
"\n",
"## Shapley Values: Cooking Game\n",
"To illustrate the concept of Shapley values, we consider a simple example of a cooking game.\n",
" The game consists of three players(cooks), Alice, Bob, and Charlie, who are cooking a meal together.\n",
" The characteristic function $\\nu$ maps each coalition of players to the quality of the meal."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit b9baa1e

Please sign in to comment.