Search

Search papers and lessons

Shapley Value

Level 3 · 10 min read

The Shapley value splits a cooperative game's total by averaging each player's contribution over every order in which the players could join, which gives one fair answer.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Probability
  • Game theory
  • ReadReady to readNot yet

TL;DR

The Shapley value is one way to divide the total value of a Cooperative Game. For each player it averages the extra value that player adds when joining a group, taken over every order in which the players could arrive. The result is a single split that always adds up to the total, and that treats players symmetrically.

Builds on: Cooperative Game, Expected Value, Counting Principles · Leads to: feature-attribution methods such as SHAP Values, and the comparison of one-answer rules with the core

Where it's used

  • Sharing joint profit or cost. When firms pool resources, a single rule is needed to say what each firm gets. The Shapley value gives each firm its average contribution across all arrival orders, which is easy to explain and check.
  • Voting power. In a legislature that votes by coalition, a party's power can be measured by how often it is the one whose joining turns a losing coalition into a winning one. The Shapley value formalises this count across all orders of joining, and it is the basis of the Shapley-Shubik power index.
  • Explaining machine-learning predictions. Model-explanation tools treat each input feature as a player and the model's output as the game's value. The Shapley value then says how much each feature pushes a prediction up or down. The tool family is SHAP Values.
  • Valuing data. Researchers value each training example by its average marginal contribution to a model's accuracy, so that useful data gets more credit. The arithmetic is the same as for firms.

How it works

Use the three-firm game from the Cooperative Game lesson. Single firms are worth 0, the pairs AB and AC are worth 60, the pair BC is worth 40, and all three together are worth 90 (thousand dollars). The question is how much of the 90 each firm should get.

  1. Pick an order of arrival, for example A, then B, then C. Each firm, in turn, joins the group already formed, and its marginal contribution is the value of the group after it joins minus the value before.
  2. Work the order A, B, C. A joins an empty group: contribution 0. B joins {A}\{A\}: the group goes from 0 to 60, so B adds 60. C joins {A,B}\{A, B\}: the group goes from 60 to 90, so C adds 30. Check: 0 + 60 + 30 = 90, the total.
  3. Work the order C, B, A. C adds 0. B joins {C}\{C\}: the group goes from 0 to 40, so B adds 40. A joins {B,C}\{B, C\}: the group goes from 40 to 90, so A adds 50. Check: 0 + 40 + 50 = 90.
  4. Repeat for all six orders. Each order adds up to 90, because each order walks from nothing to the full group.
  5. For each firm, average its six contributions. Firm A's contributions in the six orders (the full table is in Worked example 2) are 0, 0, 60, 50, 60 and 50. Their sum is 220, and 220 / 6 ≈ 36.67 is A's Shapley value.

The idea is that the Shapley value averages over arrival orders. A firm that joins valuable groups earns more on average, and a firm that adds nothing anywhere earns nothing.

The math

Definition: Shapley value

For a cooperative game (N, v) with n players, the Shapley value of player i is

φi(v)=∑S⊆N∖{i}∣S∣! (n−∣S∣−1)!n! (v(S∪{i})−v(S))\varphi_i(v) = \sum_{S \subseteq N \setminus \{i\}} \frac{|S|!\,(n - |S| - 1)!}{n!}\,\big(v(S \cup \{i\}) - v(S)\big)

The sum runs over every coalition S that does not contain i. The bracket is i's marginal contribution to S, and the fraction is a weight.

Step 1 in symbols: the marginal contribution

For a coalition S not containing i, the marginal contribution of i is v(S∪{i})−v(S)v(S \cup \{i\}) - v(S). It is the value added when i joins S.

Step 2 in symbols: orders of arrival

There are n! orders in which n players can arrive, each equally likely. For a fixed order, a player's contribution is its marginal contribution to the set of players who arrived before it. The Shapley value is the expected contribution when the order is random.

Step 3 in symbols: the weights

Count how many orders produce the same pre-arrival set S for player i. The set S can be arranged in |S|! ways before i, and the remaining n − |S| − 1 players can be arranged after i in (n − |S| − 1)! ways. Dividing by n! turns the count into a probability. This is the weight in the definition. For three players the weights are 1/3 when |S| = 0, 1/6 when |S| = 1 and 1/3 when |S| = 2.

Step 4 in symbols: the split adds to the total

Summing the Shapley values over all players gives the grand coalition's value:

∑i∈Nφi(v)=v(N)\sum_{i \in N} \varphi_i(v) = v(N)

Each arrival order walks from the empty group to N, so its contributions add to v(N). Averaging over orders keeps that total. This is the efficiency property, and it is why the Shapley value is a valid split.

Worked examples

Example
1. Two players

Players 1 and 2 with v({1})=0v(\{1\}) = 0, v({2})=0v(\{2\}) = 0 and v({1,2})=10v(\{1, 2\}) = 10.

  1. Order 1, 2: player 1 adds 0, then player 2 adds 10 − 0 = 10.
  2. Order 2, 1: player 2 adds 0, then player 1 adds 10 − 0 = 10.
  3. Average for player 1: (0 + 10) / 2 = 5. Player 2 also gets (10 + 0) / 2 = 5.
  4. Check: 5 + 5 = 10, the total.

Interpretation: the two players are symmetric, so they split the value equally. The Shapley value agrees with intuition here.

Example
2. The three-firm game

The full table of six orders. Each row shows the contribution of A, B and C in that order.

  1. Order A, B, C: A adds 0, B adds 60, C adds 30.
  2. Order A, C, B: A adds 0, C adds 60, B adds 30.
  3. Order B, A, C: B adds 0, A adds 60, C adds 30.
  4. Order B, C, A: B adds 0, C adds 40, A adds 50.
  5. Order C, A, B: C adds 0, A adds 60, B adds 30.
  6. Order C, B, A: C adds 0, B adds 40, A adds 50.
  7. Totals: A gets 0 + 0 + 60 + 50 + 60 + 50 = 220. B gets 60 + 30 + 0 + 0 + 30 + 40 = 160. C gets 30 + 60 + 30 + 40 + 0 + 0 = 160.
  8. Average over six orders: A gets 220 / 6 = 110/3 ≈ 36.67, and B and C each get 160 / 6 = 80/3 ≈ 26.67.
  9. Check: 110/3 + 80/3 + 80/3 = 270/3 = 90, the total.

Interpretation: firm A earns the most because it is in both valuable pairs. The equal split of 30 each would ignore that A brings more to the table.

Example
3. The same answer from the weights

Compute A's value directly with the formula, to see the weights at work. Here n = 3.

  1. Coalitions not containing A: the empty set, {B}\{B\}, {C}\{C\}, and {B,C}\{B, C\}.
  2. Empty set, weight 1/3: contribution v({A})−v(∅)=0−0=0v(\{A\}) - v(\emptyset) = 0 - 0 = 0.
  3. Size 1, weight 1/6, two sets: contribution from {B}\{B\} is v({A,B})−v({B})=60−0=60v(\{A, B\}) - v(\{B\}) = 60 - 0 = 60, and from {C}\{C\} is v({A,C})−v({C})=60−0=60v(\{A, C\}) - v(\{C\}) = 60 - 0 = 60. Together 120, multiplied by 1/6 gives 20.
  4. Size 2, weight 1/3, the set {B, C}: contribution v({A,B,C})−v({B,C})=90−40=50v(\{A, B, C\}) - v(\{B, C\}) = 90 - 40 = 50, multiplied by 1/3 gives 50/3 ≈ 16.67.
  5. Add: 0 + 20 + 16.67 = 36.67, which matches 110/3 from the table.

Interpretation: the formula and the table agree. Writing it as weights shows that a coalition of size 1 counts for more per set than the empty set, and the largest coalition counts for a third.

Try it: compute firm C's Shapley value with the weights. The coalitions not containing C are the empty set, {A}\{A\}, {B}\{B\} and {A,B}\{A, B\}.

Answer: the empty set gives 0. Size 1 gives 16×[v({A,C})−v({A})+v({B,C})−v({B})]=16×(60+40)=1006≈16.67\tfrac{1}{6} \times [v(\{A, C\}) - v(\{A\}) + v(\{B, C\}) - v(\{B\})] = \tfrac{1}{6} \times (60 + 40) = \tfrac{100}{6} \approx 16.67. Size 2 gives 13×[v({A,B,C})−v({A,B})]=13×(90−60)=10\tfrac{1}{3} \times [v(\{A, B, C\}) - v(\{A, B\})] = \tfrac{1}{3} \times (90 - 60) = 10. The total is 16.67 + 10 = 26.67, which is 80/3.

Common mistakes and tradeoffs

It is tempting to think the Shapley value is just the equal split. In fact it splits by contribution, and gives equal shares only to players who are interchangeable. In the three-firm game the equal split would give 30 each, but the Shapley value gives A about 36.67, because A contributes more to the valuable groups.

It is tempting to think the Shapley value is always stable. In fact it need not lie in the core. In the three-firm example it does: (36.67, 26.67, 26.67) gives the pairs 63.33, 63.33 and 53.33, all at or above their solo values. In general a game can have a Shapley value that some group would reject, so the two answers measure different things.

It is tempting to think the formula is cheap to compute. In fact the number of orders grows as n!, and the number of coalitions as 2^n. For a few players that is fine, but for dozens of features or data points people use sampling to estimate the average.

Tradeoffs. The Shapley value always gives exactly one answer, and it satisfies several fairness rules at once, which is why it is widely used. Its cost is that it averages over arrival orders, which is not always the natural story, and that it ignores who is willing to leave. Use the core to test whether a deal holds, and the Shapley value to propose one fair split.

History

Lloyd Shapley introduced the value in 1953 in a paper titled "A value for n-person games". He showed that a single split can be derived from a few natural fairness properties, which is why it is called an axiomatic solution. The idea spread slowly at first and then widely, in economics and in political science, where the power-index version was used to study voting. Shapley shared the 2012 Nobel Memorial Prize in Economic Sciences with Alvin Roth, though that prize was for stable allocations and market design, a related body of work.

Recap

  • The Shapley value of a player is its marginal contribution averaged over all arrival orders.
  • Written as a formula, each coalition gets a weight that depends only on its size.
  • The Shapley values of all players add up to the value of the grand coalition.
  • In the three-firm game the split is (110/3, 80/3, 80/3), about (36.67, 26.67, 26.67).
  • Read next: SHAP Values for the machine-learning use, and Normal-Form Game for games without binding agreements.

Check yourself

QuestionIn one sentence, what does the Shapley value of a player measure?Show answer

It is the player's marginal contribution, meaning the value added when the player joins the players who arrived before, averaged over all orders in which the players could arrive.

QuestionA game has five players. How many orders of arrival are there, and how many coalitions not containing a given player?Show answer

There are 5! = 120 orders of arrival. A given player is excluded from the coalitions, and the remaining four players form 2^4 = 16 coalitions.

QuestionWhy does the Shapley value always add up to the value of the grand coalition?Show answer

Each order of arrival walks from the empty group to the full group, so the contributions in that order add up to v(N). Averaging over all orders keeps the total at v(N).

QuestionThree firms split a joint profit. One of them says the equal split is fair because everyone contributes equally. How would you respond using the Shapley value?Show answer

Equal contribution is not the same as equal marginal value. A firm that is part of the most valuable groups adds more when it joins, and the Shapley value credits it for that. In the three-firm example the Shapley split gives the firm in both valuable pairs about 36.67 against 26.67 for each of the others, so the equal split ignores real differences in what each firm brings.

Sources