Skip to content

Instantly share code, notes, and snippets.

@RedaAffane
Last active March 14, 2019 03:44
Show Gist options
  • Save RedaAffane/723c43e77bf0dcf1bc67354ae468d059 to your computer and use it in GitHub Desktop.
Save RedaAffane/723c43e77bf0dcf1bc67354ae468d059 to your computer and use it in GitHub Desktop.
from collections import defaultdict
n=len(channels)
shapley_values = defaultdict(int)
for channel in channels:
for A in v_values.keys():
if channel not in A.split(","):
cardinal_A=len(A.split(","))
A_with_channel = A.split(",")
A_with_channel.append(channel)
A_with_channel=",".join(sorted(A_with_channel))
shapley_values[channel] += (v_values[A_with_channel]-v_values[A])*(factorial(cardinal_A)*factorial(n-cardinal_A-1)/factorial(n))
# Add the term corresponding to the empty set
shapley_values[channel]+= v_values[channel]/n
@DataPiggott
Copy link

Hello Reda,
I'm trying to run your example from Medium.com on marketing attribution and the code seems to be partial. Is it possible to obtain your full code to test it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment