Customer Segmentation in Python
Karolis Urbonas
Head of Data Science, Amazon
# Import key libraries from sklearn.cluster import KMeans import seaborn as sns from matplotlib import pyplot as plt
# Fit KMeans and calculate SSE for each *k* sse = {} for k in range(1, 11): kmeans = KMeans(n_clusters=k, random_state=1) kmeans.fit(data_normalized) sse[k] = kmeans.inertia_ # sum of squared distances to closest cluster center
# Plot SSE for each *k* plt.title('The Elbow Method') plt.xlabel('k'); plt.ylabel('SSE') sns.pointplot(x=list(sse.keys()), y=list(sse.values())) plt.show()
The elbow criterion chart:
The elbow criterion chart:
datamart_rfm
Customer Segmentation in Python