customer segmentation is just the task of segmenting customers it can be solved in several ways and it need not always be complex model clustering provides mathematical framework which can be leveraged for finding out such segment boundaries in the data clustering is especially useful when we have lot of attributes about the customer on which we can make different segments alsooften it is observed that clustering-based segmentation will be superior to an arbitrary segmentation process and it will often encompass the segments that can be devised using such an arbitrary process clustering strategy now that we have some information about what customer segmentation isvarious strategies and how it can be usefulwe can start with the process of finding out customer segments in our online retail dataset the dataset that we have consists of only the sales transactions of the customers and no other information about themi no other additional attributes usually in larger organizations we will usually have more attributes of information about the customers that can help in clustering howeverit will be interesting and definitely challenge to work with this limited attribute datasetso we will use rfm--recencyfrequency and monetary value--based model of customer value for finding our customer segments rfm model for customer value the rfm model is popular model in marketing and customer segmentation for determining customer' value the rfm model will take the transactions of customer and calculate three important informational attributes about each customerrecencythe value of how recently customer purchased at the establishment frequencyhow frequent the customer' transactions are at the establishment monetary valuethe dollar (or pounds in our casevalue of all the transactions that the customer made at the establishment combination of these three values can be used to assign value to the customer we can directly think of some desirable segments that we would want on such model for examplea high value customer is one who buys frequentlyjust bought something recentlyand spends high amount whenever he buys or shopsdata cleaning we hinted in the "exploratory data analysissection about the return transactions that we have in our dataset before proceeding with our analysis workflowwe will find out all such transactions and remove them another possibility is to remove the matching buying transactions also from the dataset but we will assume that those transactions are still important hence we will keep them intact another data cleaning operation is to separate transactions for particular geographical region onlyas we don' want data from germany' customers to affect the analysis for another country' customers the following snippet of code achieves both these tasks we focus on uk customerswhich are notably the largest segment (based on country!in [ ]separate data for one geography cs_df cs_df[cs_df country ='united kingdom'separate attribute for total amount cs_df['amount'cs_df quantity*cs_df unitprice remove negative or return transactions