Get startedGet started for free

Segment wholesale customers

You're now ready to use hierarchical clustering to perform market segmentation (i.e. use consumer characteristics to group them into subgroups).

In this exercise you are provided with the amount spent by 45 different clients of a wholesale distributor for the food categories of Milk, Grocery & Frozen. This is stored in the data frame customers_spend. Assign these clients into meaningful clusters.

Note: For this exercise you can assume that because the data is all of the same type (amount spent) and you will not need to scale it.

This exercise is part of the course

Cluster Analysis in R

View Course

Exercise instructions

  • Calculate the Euclidean distance between the customers and store this in dist_customers.
  • Run hierarchical clustering using complete linkage and store in hc_customers.
  • Plot the dendrogram.
  • Create a cluster assignment vector using a height of 15,000 and store it as clust_customers.
  • Generate a new data frame segment_customers by appending the cluster assignment as the column cluster to the original customers_spend data frame.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate Euclidean distance between customers
dist_customers <- ___

# Generate a complete linkage analysis 
hc_customers <- ___

# Plot the dendrogram


# Create a cluster assignment vector at h = 15000
clust_customers <- ___

# Generate the segmented customers data frame
segment_customers <- mutate(___, cluster = ___)
Edit and Run Code