Building an A/B test segmenting function
In the previous lesson, you observed that your personalization experiment is highly statistically significant. However, when running experiments, it is important to check how new features are affecting specific demographics. Sometimes features that are highly appealing to one group are less appealing to others.
Since you want to segment our data multiple times, you will build a function ab_segmentation()
that analyzes the impact of your A/B tests on segments of data that you can reuse each time you want to conduct this kind of analysis.
Your function will take in a column name and run through each unique value in that column calculating lift and statistical significance.
Cet exercice fait partie du cours
Analyzing Marketing Campaigns with pandas
Instructions
- Build a for loop within our
ab_segmentation()
function that runs through each unique value in the user-inputted column namesegment
. - Isolate the rows in marketing where the marketing channel is
'Email'
and the user-inputted columnsegment
equalssubsegment
. - Print the results of the
lift()
andstats.ttest_ind()
functions.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
def ab_segmentation(segment):
# Build a for loop for each subsegment in marketing
for subsegment in ____:
print(subsegment)
# Limit marketing to email and subsegment
email = marketing[(marketing['marketing_channel'] == ____) & (marketing[segment] == ____)]
subscribers = email.groupby(['user_id', 'variant'])['converted'].max()
subscribers = pd.DataFrame(subscribers.unstack(level=1))
control = subscribers['control'].dropna()
personalization = subscribers['personalization'].dropna()
print('lift:', ____)
print('t-statistic:', ____, '\n\n')