Python 中的客户细分
Karolis Urbonas
Head of Data Science, Amazon
基于三项指标的行为分群:
RFM 可按多种方式分组:
我们将实现基于百分位的分组。
计算百分位的流程:
包含 8 个 CustomerID 和随机计算的 Spend 值的数据。
spend_quartiles = pd.qcut(data['Spend'], q=4, labels=range(1,5))data['Spend_Quartile'] = spend_quartilesdata.sort_values('Spend')
# Create numbered labels r_labels = list(range(4, 0, -1))# Divide into groups based on quartiles recency_quartiles = pd.qcut(data['Recency_Days'], q=4, labels=r_labels)# Create new column data['Recency_Quartile'] = recency_quartiles# Sort recency values from lowest to highest data.sort_values('Recency_Days')
如图,四分位标签是反向的,因为更近期的客户更有价值。
可按用例用字符串或其他值定义列表。
# Create string labels r_labels = ['Active', 'Lapsed', 'Inactive', 'Churned']# Divide into groups based on quartiles recency_quartiles = pd.qcut(data['Recency_Days'], q=4, labels=r_labels) # Create new column data['Recency_Quartile'] = recency_quartiles # Sort values from lowest to highest data.sort_values('Recency_Days')
为各四分位分配自定义标签
Python 中的客户细分