Shapley Value Functions Example: ShapleyGenerateCombination, ShapleyAddOnePlayer; Step 3 - Teradata Vantage

Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
8.10
1.1
Published
October 2019
Language
English (United States)
Last Update
2019-12-31
dita:mapPath
ima1540829771750.ditamap
dita:ditavalPath
jsj1481748799576.ditaval
dita:id
B700-4003
lifecycle
previous
Product Category
Teradata Vantageā„¢

Step 3 computes the Shapley value for each player.

The Shapley number for each project(player) is computed as an average of the sum of incremental contributions of each project (in this example, three total), using the combined SQL query shown below. The results match with those described above.

SQL Calls

Compute Shapley value for each player:

SELECT player, SUM(partial_avg) / 3 AS shapley_value FROM (
  SELECT player, size, SUM(partial_value) AS partial_avg FROM (
	SELECT player, 
      (project_comb_cost."value" - project_addone_cost."value") / divisor AS
		partial_value, project_addone_cost.size AS size 
	FROM project_comb_cost INNER JOIN
		project_addone_cost
		ON (project_comb_cost.comb = project_addone_cost.comb2)
	) AS stratum
	GROUP BY player, size
) AS stratum_avg
GROUP BY player
ORDER BY player;

Output

 player shapley_value 
 ------ ------------- 
 1             2000.0
 2            10000.0
 3             8000.0