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(",") |
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
# First, let's convert the dataframe "subsets_conversions" into a dictionnary | |
C_values = user_logs_aggr.set_index("channels").to_dict()["conversions"] | |
#For each possible combination of channels A, we compute the total number of conversions yielded by every subset of A. | |
# Example : if A = {c1,c2}, then v(A) = C({c1}) + C({c2}) + C({c1,c2}) | |
v_values = {} | |
for A in subsets(channels): | |
v_values[A] = v_function(A,C_values) |
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
SELECT "channels_subset", | |
sum("conversion") as "conversions_sum" | |
FROM | |
( | |
SELECT "user_id", | |
string_agg(DISTINCT("channel"), ',') as "channels_subset", | |
max("conversion") as "conversion" | |
FROM | |
( | |
SELECT "user_id", |
NewerOlder