I'm trying to build a customer segmentation framework on e-commerce data. To do this, I'm using k-means clustering on variables which quantify the purchase Recency, purchase Frequency, Monetary value of the purchase (RFM segmentation) + additionally I have also used the Age of the customer (not biological but age on the website). I have derived 5 clusters out of this data using elbow method & applying some business sense. The clusters have been able to segregate buyers as

  1. Best Customers (Almost Recent, Most Frequent, High Revenue, High Tenured)
  2. Reliable Customers (safe for business) (Almost Recent, Frequent, Decent Revenue, Mid Tenure)
  3. Dormant Customers
  4. Single Purchasers tending to become dormant
  5. New Customers

Now I would like to deploy this framework and use these insights in the marketing activities. I'm planning to schedule this as a weekly run. However, every week, there would be change in the data as the number of customers grow, number of purchases increase. Due to this the segments are bound to change (due to covariate shift). Previously cluster 5 were New Customers, now cluster 1 could be New customers etc. This can be inferred only by looking at the cluster level data. I'm wondering if there is a way to automate this.

  • $\begingroup$ so seeding the clusters with the previous weeks centres should do this (ie cluster 5 should stay new customers). However, I would avoid using an unsupervised method myself $\endgroup$
    – seanv507
    Sep 30, 2021 at 10:28
  • $\begingroup$ @seanv507 How else would you do it? $\endgroup$ Oct 1, 2021 at 4:44
  • $\begingroup$ well I don't know your exact goal.your categories seem like you could manually allocate - based on your business case. i would use a supervised method to eg predict which type of customers are likely to be good customers. $\endgroup$
    – seanv507
    Oct 1, 2021 at 9:20
  • $\begingroup$ @BhanutejaAryasomayajula - I am working on a similar RFM segmentation using k-means. Did you have to normalize/scale your R,F,M and tenure values to do clustering? because monetary units could be different from R,F. Here is my related post - stats.stackexchange.com/questions/576686/… $\endgroup$
    – The Great
    May 26, 2022 at 14:24
  • $\begingroup$ @TheGreat - Yes I had to normalise my data, otherwise the Eucledian distances wouldn't make sense. $\endgroup$ Jun 21, 2022 at 4:58

1 Answer 1


You can use online algorithm for $k$-means, so as your data grows and changes, you incrementally adapt. I didn't use it yet, but you may try the river package for Python that implements online machine learning algorithms, including $k$-means.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.