什么是 A/B 测试?

Python 中的 A/B 测试

Moe Lotfy, PhD

Principal Data Science Manager

A/B 测试简介

  • A/B 测试是……

     
    • 用于比较哪个版本更优的实验
    • 基于指标:注册率、人均销售额等
    • 使用随机分配并分析结果
Python 中的 A/B 测试

是否进行 A/B 测试?

A/B 测试的良好用法:

  • 优化转化率
  • 发布新应用功能
  • 评估广告的增量效果
  • 评估药物试验的影响

不宜进行 A/B 测试:

  • 流量不足/样本量过小
  • 无清晰、合理的假设
  • 存在伦理问题
  • 机会成本高
Python 中的 A/B 测试

A/B 测试基本步骤

  1. 明确目标与方案/体验
  2. 随机抽样选取用户
  3. 将用户随机分配至:
    • 对照组:当前方案
    • 处理/测试组:新方案
  4. 记录行为并计算指标
  5. 检验是否具有统计显著差异

A/B testing steps

Python 中的 A/B 测试

随机化的价值

  • 可推广性与代表性
  • 最小化组间偏差
  • 通过隔离处理效应建立因果关系

 

随机抽样与随机分配示意图

1 https://www.statology.org/random-selection-vs-random-assignment/
Python 中的 A/B 测试

Python 随机分配示例

checkout.info()
RangeIndex: 9000 entries, 0 to 8999
Data columns (total 6 columns):
 #   Column         Non-Null Count  Dtype  
 0   user_id        9000 non-null   int64  
 1   checkout_page  9000 non-null   object 
 2   order_value    7605 non-null   float64
 3   purchased      9000 non-null   float64
 4   gender         9000 non-null   object 
 5   browser        9000 non-null   object 
dtypes: float64(2), int64(1), object(3)
memory usage: 422.0+ KB
Python 中的 A/B 测试

Python 随机分配示例

checkout['gender'].value_counts(normalize=True)
F    0.507556
M    0.492444
Name: gender, dtype: float64
sample_df = checkout.sample(n=3000)
sample_df['gender'].value_counts(normalize=True)
M    0.506333
F    0.493667
Name: gender, dtype: float64
Python 中的 A/B 测试

Python 随机分配示例

checkout.groupby('checkout_page')['gender'].value_counts(normalize=True)
checkout_page  gender
A              M         0.505000
               F         0.495000
B              F         0.507333
               M         0.492667
C              F         0.520333
               M         0.479667
Name: gender, dtype: float64
Python 中的 A/B 测试

¡Vamos a practicar!

Python 中的 A/B 测试

Preparing Video For Download...