library(readr)
mydata <- read_csv("customer_segmentation.csv")
## Rows: 22 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (15): ID, CS_helpful, Recommend, Come_again, All_Products, Profesionalis...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
use <- scale(mydata[, -1], center = TRUE, scale = TRUE)
dist_matrix <- dist(use)
d <- dist(as.matrix(dist_matrix))
seg.hclust <- hclust(d)
library(ggplot2)
plot(seg.hclust)
groups.3 <- cutree(seg.hclust, 3)
table(groups.3)
## groups.3
## 1 2 3
## 17 2 3
mydata$ID[groups.3 == 1]
## [1] 1 2 3 6 7 8 9 10 11 12 13 14 15 16 17 18 21
mydata$ID[groups.3 == 2]
## [1] 4 22
mydata$ID[groups.3 == 3]
## [1] 5 19 20
aggregate(mydata[, -1], list(groups.3), median)
## Group.1 CS_helpful Recommend Come_again All_Products Profesionalism
## 1 1 1 1.0 1.0 2 1.0
## 2 2 3 2.5 1.5 3 1.5
## 3 3 2 1.0 3.0 3 2.0
## Limitation Online_grocery delivery Pick_up Find_items other_shops Gender Age
## 1 1 2 2 3.0 1 2.0 1 2.0
## 2 2 3 3 2.5 2 1.5 1 2.5
## 3 1 2 3 1.0 2 3.0 2 2.0
## Education
## 1 2
## 2 5
## 3 2
aggregate(mydata[, -1], list(groups.3), mean)
## Group.1 CS_helpful Recommend Come_again All_Products Profesionalism
## 1 1 1.294118 1.117647 1.235294 1.823529 1.235294
## 2 2 3.000000 2.500000 1.500000 3.000000 1.500000
## 3 3 2.333333 1.666667 2.666667 3.000000 2.333333
## Limitation Online_grocery delivery Pick_up Find_items other_shops Gender
## 1 1.352941 2.235294 2.235294 2.705882 1.294118 2.647059 1.176471
## 2 2.000000 3.000000 3.000000 2.500000 2.000000 1.500000 1.000000
## 3 2.000000 2.000000 3.000000 1.000000 2.000000 3.000000 2.000000
## Age Education
## 1 2.411765 3.117647
## 2 2.500000 5.000000
## 3 2.666667 2.333333
cluster_means <- aggregate(mydata[, -1], list(groups.3), mean)
write.csv(groups.3, "clusterID.csv")
write.csv(cluster_means, "cluster_means.csv")
Answer:
table(groups.3)
## groups.3
## 1 2 3
## 17 2 3
Answer:
Examining cluster means and medians helps identify the characteristics that distinguish one customer segment from another. This information can be used to develop targeted marketing strategies for each group.
Answer:
The median is less sensitive to outliers and is often preferred when the data contain extreme values. The mean is useful when the data are approximately normally distributed. In market segmentation studies, the median is often more robust.
Answer:
These measures help describe the central tendency and variability of each cluster.
Answer:
K-means clustering requires selecting the number of clusters before analysis and works efficiently on large datasets.
Hierarchical clustering produces a dendrogram that visualizes how observations are grouped and does not require specifying the number of clusters in advance.
I prefer hierarchical clustering for exploratory analysis because the dendrogram helps visualize cluster relationships.
Answer:
Examples include:
There are numerous job postings that list cluster analysis as a required or preferred skill.
Answer:
Use:
mydata[, -1]
rather than:
mydata
because the first column contains customer IDs, which are identifiers and should not be included when calculating cluster means or medians.