Last active
March 14, 2019 03:44
-
-
Save RedaAffane/723c43e77bf0dcf1bc67354ae468d059 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?