ComeçarComece de graça

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.

Este exercício faz parte do curso

Analyzing Marketing Campaigns with pandas

Ver curso

Instruções do exercício

  • Build a for loop within our ab_segmentation() function that runs through each unique value in the user-inputted column name segment.
  • Isolate the rows in marketing where the marketing channel is 'Email' and the user-inputted column segment equals subsegment.
  • Print the results of the lift() and stats.ttest_ind() functions.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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')
Editar e executar o código