Customer and product segmentation basics

Machine Learning for Marketing in Python

Karolis Urbonas

Head of Analytics & Science, Amazon

Data format

# Customer by product/service matrix
wholesale.head()

Wholesale header

Machine Learning for Marketing in Python

Unsupervised learning models

  • Hierarchical clustering
  • K-means
  • Non-negative matrix factorization (NMF)
  • Biclustering
  • Gaussian mixture models (GMM)
  • And many more
Machine Learning for Marketing in Python

Unsupervised learning models

  • Hierarchical clustering
  • K-means
  • Non-negative matrix factorization (NMF)
  • Biclustering
  • Gaussian mixture models (GMM)
  • And many more
Machine Learning for Marketing in Python

Unsupervised learning steps

  1. Initialize the model
  2. Fit the model
  3. Assign cluster values
  4. Explore results
Machine Learning for Marketing in Python

Explore variables

wholesale.agg(['mean','std']).round(0)
        Fresh    Milk  Grocery  Frozen  Detergents_Paper  Delicassen
mean  12000.0  5796.0   7951.0  3072.0            2881.0      1525.0
std   12647.0  7380.0   9503.0  4855.0            4768.0      2820.0
# Get the statistics
averages = wholesale.mean()
st_dev = wholesale.std()
x_names = wholesale.columns
x_ix = np.arange(wholesale.shape[1])

# Plot the data import matplotlib.pyplot as plt plt.bar(x_ix-0.2, averages, color='grey', label='Average', width=0.4) plt.bar(x_ix+0.2, st_dev, color='orange', label='Standard Deviation', width=0.4) plt.xticks(x_ix, x_names, rotation=90) plt.legend() plt.show()
Machine Learning for Marketing in Python

Bar chart of averages and standard deviations

Bar chart

Machine Learning for Marketing in Python

Visualize pairwise plot to explore distributions

import seaborn as sns
sns.pairplot(wholesale, diag_kind='kde')
plt.show()
Machine Learning for Marketing in Python

Pairwise plot review

Pairplot Raw

Machine Learning for Marketing in Python

Let's practice!

Machine Learning for Marketing in Python

Preparing Video For Download...