Home/Data Analytics/Mall Customer Segmentation
Machine learning · Customer analytics

Mall Customer Segmentation

K-Means clustering of 200 shoppers into five marketing segments, with a recommendation for each.

RoleIndividual project
Year2025
ToolsPython, pandas, scikit-learn, seaborn, matplotlib, Jupyter
200mall customers in the source dataset
3behavioural features: age, income, spending score
5segments, chosen with the elbow method
1clustered dataset ready for the marketing team

At a glance

The business question

The mall's management team wanted to understand its customer base in order to:

  • identify high-value customers;
  • optimise marketing spend;
  • design targeted campaigns for different customer segments; and
  • let the marketing team drill down to individual customers.

Rather than treating all customers the same, clustering lets the business make decisions based on how people actually spend.

What I found

Customers plotted by annual income and spending score, coloured by cluster, with centroids in black
Five customer segments by annual income and spending score. Black dots are the cluster centres.
Segment Customers Avg. age Avg. income (k$) Avg. spending score How I read it
1 39 33 87 82 Prime customers. High income, high spending
2 22 25 26 79 Enthusiastic spenders. Lower income, high spending
0 81 43 55 50 Mainstream. Middle income, middle spending
3 35 41 88 17 Untapped potential. High income, low spending
4 22 46 27 20 Low priority. Lower income, low spending

Segment numbers are the cluster labels in the exported CSV; the descriptive names are mine. Averages are computed from that file.

Recommendations by segment

Prime customers

The most valuable group. Prioritise premium offerings, loyalty programmes and exclusive promotions.

Enthusiastic spenders

Selective but intentional. Highlight trending products, promotions and value-for-money offers.

Everyone else

Less immediate revenue potential. Keep up brand awareness and social media marketing without heavy targeted spend. Test what would move the high-income, low-spending group.

Under the hood

Method

  1. Explore and clean. Loaded and inspected the data, checked for missing values and consistency (univariate and bivariate analysis).
  2. Select features. Age, annual income and spending score.
  3. Choose the number of clusters. Used the elbow method: fit K-Means for k = 1 to 10 and plot the inertia (within-cluster sum of squares), then look for the bend.
  4. Cluster. K-Means from scikit-learn with random_state=42 for reproducibility. I clustered three ways: income vs spending, age vs spending, and all three features together.
  5. Visualise. Plotted clusters with their centroids with seaborn and matplotlib.
Elbow plot of inertia against number of clusters for the multivariate clustering
Elbow plot for the multivariate clustering: inertia falls steeply until about four to six clusters, then flattens.
# Inertia for different values of k (multivariate clustering)
inertia_values3 = []

for k in range(1, 11):
    kmeans = KMeans(n_clusters=k, random_state=42)
    kmeans.fit(df3)
    inertia_values3.append(kmeans.inertia_)

plt.plot(range(1, 11), inertia_values3, marker='o')
plt.title('Elbow Method for Optimal k (Multivariate Clustering)')
plt.xlabel('Number of clusters (k)')
plt.ylabel('Inertia')
plt.savefig('elbow_multivariate.png')
plt.show()
# Plot clusters with centroids
plt.figure(figsize=(10, 6))

sns.scatterplot(data=centres, x='Annual Income (k$)', y='Spending Score (1-100)',
                s=200, color='black', label='Centroids')

sns.scatterplot(data=df2, x='Annual Income (k$)', y='Spending Score (1-100)',
                hue='Cluster_Income_Spending', palette='Set1')

plt.title('Clusters of Annual Income vs Spending Score with Centroids')
plt.xlabel('Annual Income (k$)')
plt.ylabel('Spending Score (1-100)')
plt.legend()
plt.savefig('clusters_with_centroids.png')
plt.show()

Dataset

The data has three behavioural variables: Age, Annual Income (k$) and Spending Score (1–100), a metric representing customer spending behaviour at the mall. The exported file adds two columns, Cluster_Income_Spending and Cluster_Age_Spending, so the marketing team can filter to any segment.

Limitations and next steps

  • Small dataset. Two hundred customers is enough to demonstrate the method but not to size a campaign.
  • The spending score is a given metric. I did not have the underlying transactions, so the segments describe behaviour as scored, not revenue.
  • Cluster labels are not business labels. The names above are my interpretation and should be validated with the marketing team.
  • Next: scale the features before multivariate clustering, compare with silhouette scores, and reconcile the 199 rows in the exported CSV with the 200 customers in the source dataset.

Files

Skills demonstrated

Unsupervised learningK-Means clusteringElbow methodpandasscikit-learnseaborn and matplotlibCustomer segmentationTurning models into marketing actions