Cohort analysis

Python में Customer Segmentation

Karolis Urbonas

Head of Data Science, Amazon

Cohort analysis heatmap

Rows:

  • First activity
  • यहाँ: acquisition का महीना

Columns:

  • Time since first activity
  • यहाँ: acquisition के बाद के महीने

Cohort heatmap

Python में Customer Segmentation

Cohort analysis heatmap

Rows:

  • First activity
  • यहाँ: acquisition का महीना

Columns:

  • Time since first activity
  • यहाँ: acquisition के बाद के महीने

Python में Customer Segmentation

Online retail डेटा

UK-आधारित एक ऑनलाइन रिटेल स्टोर से 0.5 मिलियन से अधिक ट्रांज़ैक्शन.

हम पूरे कोर्स में इस डेटासेट के 20% रैंडम सैंपल का उपयोग करेंगे.

OnlineRetail

Python में Customer Segmentation

डेटा की शीर्ष 5 पंक्तियाँ

online.head()

Top 5 rows

Python में Customer Segmentation

Acquisition माह का cohort असाइन करें

def get_month(x): return dt.datetime(x.year, x.month, 1)

online['InvoiceMonth'] = online['InvoiceDate'].apply(get_month)
grouping = online.groupby('CustomerID')['InvoiceMonth']
online['CohortMonth'] = grouping.transform('min')
online.head()

top5-cohort-added

Python में Customer Segmentation

डेटा से integer मान निकालें

year, month और day के integer मान निकालने के लिए फंक्शन परिभाषित करें.

हम इसे पूरे कोर्स में उपयोग करेंगे.

def get_date_int(df, column):
    year = df[column].dt.year
    month = df[column].dt.month
    day = df[column].dt.day
    return year, month, day
Python में Customer Segmentation

Time offset मान असाइन करें

invoice_year, invoice_month, _ = get_date_int(online, 'InvoiceMonth') 
cohort_year, cohort_month, _ = get_date_int(online, 'CohortMonth')

years_diff = invoice_year - cohort_year months_diff = invoice_month - cohort_month
online['CohortIndex'] = years_diff * 12 + months_diff + 1 online.head()

top5-time-offset-added

Python में Customer Segmentation

हर cohort से मासिक सक्रिय ग्राहकों की गिनती करें

grouping = online.groupby(['CohortMonth', 'CohortIndex'])

cohort_data = grouping['CustomerID'].apply(pd.Series.nunique)
cohort_data = cohort_data.reset_index()
cohort_counts = cohort_data.pivot(index='CohortMonth', columns='CohortIndex', values='CustomerID')
print(cohort_counts)
Python में Customer Segmentation

online-pivot-counts

Python में Customer Segmentation

अब आपकी बारी: कुछ cohorts बनाएँ!

Python में Customer Segmentation

Preparing Video For Download...