Predictive Modelling & Segmentation Case Study

Author

Data Science Team

Published

April 24, 2026

1. Elbow Method

Section 1

Code
print(fviz_nbclust(scaled_data, kmeans, method = "wss") + 
  labs(title = "Elbow Method for Optimal K"))

Section 2

2. Perform clustering

Code
km_res <- kmeans(scaled_data, centers = 3, nstart = 25)
customer_data$segment <- as.factor(km_res$cluster)

3. Visualize Clusters

Code
print(fviz_cluster(km_res, data = scaled_data, geom = "point",
             ellipse.type = "convex", main = "Customer Segments"))

Section 4

4. Propensity Plot

customer_data <- customer_data %>% mutate(propensity_score = (frequency * 0.6) - (recency * 0.4))

ggplot(customer_data, aes(x = propensity_score, y = monetary, color = segment)) + geom_point(size = 3, alpha = 0.7) + theme_minimal() + labs(title = “Unsupervised Segments within Supervised Propensity”, x = “Supervised Propensity Score”, y = “Monetary Value”)