September 30, 2026
Customer segmentation in online retail using k-means
Customer Segmentation in Online Retail Using K-means
Claudecir Réboli Junior; Henrique Raymundo Gioia
DOI: 10.22167/2675-6528-202602784
Article derived from a Final Course Work (TCC), with content based on the student’s original work and adapted to the editorial format of the E&S Magazine with the support of the ResumeAI tool, an artificial intelligence solution developed by Instituto Pecege for textual synthesis and organization.
Summary
In the context of the growing relevance of data for organizational decision-making, customer segmentation was analyzed as a strategic tool for value generation in online retail companies. The objective was to segment customers from a transactional database of an online store, aiming to identify consumption patterns and support marketing decisions. For this purpose, a quantitative approach was used, with the application of data treatment techniques, manual product categorization, and Z-Score normalization, followed by the implementation of the K-Means algorithm. The definition of the number of clusters considered the silhouette and elbow methods, complemented by an angular analysis. The results showed a highly concentrated structure, in which the majority of customers presented low individual value, while a small portion concentrated significant revenue share. The presence of unitary clusters was observed, interpreted as customers with extreme behavior and high strategic value. The analysis allowed for the identification of different consumption profiles and the proposal of distinct strategies, from scalable actions to highly personalized approaches. It was concluded that data-driven segmentation enabled a greater understanding of customer behavior and provided relevant subsidies for managerial decisions, highlighting growth opportunities and risks associated with revenue concentration.
Keywords: Data analysis; Consumer behavior; Clustering; Market segmentation; Retail.
1. Introduction
In the contemporary world, the consolidation of a data-driven decision-making culture has become a strategic objective for most organizations. However, raw data, by itself, does not support effective decisions; it is essential to subject it to treatment, organization, and analysis processes to convert it into relevant and consistent information (Herdiana et al., 2025).
The ability to transform data into valuable information is crucial for creating value in companies. Falcão et al. (2016) highlight that the value of information for an organization depends directly on the manager’s skill in analyzing and using it for correct decision-making, in order to achieve specific objectives.
In this scenario, customer segmentation emerges as a fundamental strategy. Kotler and Keller (2012) argue that dividing the market into segments is essential, as consumers have diverse preferences. John et al. (2023) reinforce that this strategy allows organizations to better understand and meet their consumers’ demands by grouping them based on shared characteristics. Haley (1968) adds that it is more effective to leverage existing market segments than to try to create new ones, adapting marketing strategies to consumer needs.
For market segmentation, several methodologies are employed, with the K-Means algorithm being one of the most frequent, as pointed out by Gomes and Meisen (2023) in a literature review. The popularity of K-Means lies in its simplicity and applicability to large databases. This method falls within the field of unsupervised machine learning, where algorithms are used to identify natural structures and groupings in data without prior supervision (Mahesh, 2019; Goldschmidt and Passos, 2005).
Despite the extensive use of customer segmentation techniques in the literature, a gap is observed in the practical application of these approaches in real transactional databases. This gap is particularly evident in the identification of consumption patterns that can be directly translated into effective business actions.
In this sense, the present research seeks to answer the following question: how can the application of the K-Means algorithm to online retail transactional data contribute to the identification of customer segments with strategic relevance?
The relevance of this study lies in its potential to provide an in-depth understanding of customer behavior, offering subsidies for managerial decisions and highlighting growth opportunities and risks associated with revenue concentration. Given this context, the present work aims to segment customers from an online retail transactional base using the K-Means algorithm, seeking to identify distinct consumption profiles and analyze their implications for the formulation of marketing, retention, and customer value maximization strategies.
2. Material and Methods
The present research adopted a quantitative methodological approach, with the purpose of segmenting customers from an online retail transactional base. The study focused on the application of data treatment techniques, exploratory analysis, and unsupervised machine learning algorithms, aiming to identify consumption patterns. This methodology was selected to answer the research question about the contribution of the K-Means algorithm in identifying customer segments with strategic relevance.
The empirical object consisted of a public transactional dataset, named “Online Retail”, obtained from the UC Irvine Machine Learning Repository. The database corresponds to transaction records of an online retail company, located in the United Kingdom, covering the period from December 2010 to December 2011. Initially, the set was composed of 541,909 records and eight variables: InvoiceNo, StockCode, Description, Quantity, InvoiceDate, UnitPrice, CustomerID, and Country.
The initial data cleaning and manipulation steps were performed in Microsoft Excel software, using the Power Query tool. Observations with null values or blank spaces in the CodCliente and Descricao variables were removed, as well as records where Quantidade was less than or equal to zero. Observations of CodEstoque that did not represent products (such as fees) were also excluded. After cleaning, the database was reduced to 396,370 observations.
Next, the manual categorization of products into categories such as Accessories, Food, Animals, Toys, Kitchen, Decoration, Lighting, Garden, Materials, Stationery, Romantic, Seasonal, Utilities, Glassware, Vintage, and Others was performed. This categorization aimed to structure the data for segmentation, ensuring consistency with the business context and reproducibility of the study (Falcão et al., 2016; Gomes and Meisen, 2023). After categorization, the transaction value per customer in each category was summed.
Customer segmentation was conducted through a computational approach based on Machine Learning, specifically unsupervised learning (Géron, 2019; Mahesh, 2019; Goldschmidt and Passos, 2005). The K-Means algorithm was implemented using the Python programming language, in the Spyder environment, through the Anaconda distribution. The choice of K-Means was justified by its simplicity and scalability on large datasets (Gomes and Meisen, 2023).
To circumvent the K-Means sensitivity to distinct scales, the data were normalized using the Z-Score technique (Goldschmidt and Passos, 2005). This normalization transformed the values of each attribute so that they presented a mean equal to zero and a standard deviation equal to one, according to the formula Z = (x – μ) / σ. The definition of the initial centroids and the parameters of the K-Means algorithm followed the guidelines of Johnson and Wichern (2007).
The settings adopted in the sklearn library for K-Means were: init = ‘k-means++’, max_iter = 100, n_init = 100, and random_state = 100. The determination of the optimal number of clusters, a critical step (Bassab et al., 1990), was performed using three methods: the silhouette coefficient (Géron, 2019), the elbow method (Géron, 2019), and a complementary angular analysis (Herdiana et al., 2025).
The silhouette coefficient calculated the average silhouette coefficient of all observations, using the formula (b-a) / max(a-b). The elbow method calculated the Within-Cluster Sum of Squares (WCSS), plotting the values to identify the inflection point of the curve, where WCSS = ΣΚ=1 ΣΧ₁€CK ||Xi – μκ||². Herdiana et al.’s (2025) angular analysis measured the angle formed between line segments of the elbow plot, indicating the smallest tan(ψ) value.
Although the silhouette coefficient and visual elbow analysis suggested two clusters as mathematically optimal, angular analysis indicated the formation of six clusters as the most suitable configuration. This decision was made to reconcile statistical optimization with managerial utility, allowing for the identification of more differentiated and relevant consumption profiles for the formulation of marketing, retention, and customer value maximization strategies.
3. Results and Discussion
The application of the K-Means algorithm to the transactional database resulted in the formation of six distinct clusters, according to the initial analysis. Cluster 0 stood out for grouping the vast majority of clients, with 4,298 individuals, representing 99.15% of the total base. This group was responsible for 6,093,130 of the transacted value, corresponding to 69.55% of the total revenue. In contrast, Clusters 1, 2, and 5 were composed of only one client each, representing a minimal share of the client quantity but contributing 3.19%, 2.96%, and 1.92% of the transacted value, respectively. Cluster 3, with 30 clients (0.69%), generated 1,388,548 of the total value, and Cluster 4, with four clients (0.09%), contributed 572,121 to the revenue. This initial distribution already indicated significant heterogeneity in the client base, with a concentration of value in a few individuals.
To validate the configuration of six clusters, an additional exploratory analysis was performed with the formation of four clusters. In this new configuration, Cluster 1 encompassed 4,299 customers (99.17% of the base), accounting for 6,261,602 of the transacted value, or 71.47% of the revenue. Cluster 0, with 31 customers (0.71%), contributed 1,505,278 of the value, or 17.18% of the revenue. Cluster 2, with one customer (0.03%), generated 259,657 of the value (2.96%), and Cluster 3, with four customers (0.09%), represented 734,529 of the total (8.38%). Although this four-cluster configuration might seem more simplified, it demonstrated a crucial limitation by grouping customer ID 16446, who had the fourth highest revenue in the base (168,472) and was highly specialized in the Stationery category, within a larger cluster. This merge would compromise the model’s ability to capture atypical and strategically relevant profiles for the business, justifying the maintenance of the original six clusters.
The decision to maintain the segmentation into six clusters, even with the presence of unitary groupings (Clusters 1, 2, and 5), aligns with the properties of the K-Means algorithm in databases with high heterogeneity and extreme observations. These unitary clusters were not considered statistical noise, but rather representations of customers with exceptional consumption patterns and high strategic value. Jointly, the three unitary clusters and Cluster 4 (with four customers) were responsible for 8.07% of the total revenue. The identification of these extreme profiles is managerially relevant, as it allows for the formulation of highly customized strategies, focused on customer retention and value maximization over time. The analysis of the centroids of each cluster by consumption category, after reorganization for greater clarity, revealed specific patterns that underpin marketing strategies.
Cluster Analysis
The cluster analysis was performed by grouping the results into three managerial groups, defined by similar characteristics regarding representativeness in the customer base, contribution to revenue, and consumption pattern. The first grouping, named Low-Medium Average Ticket, is composed exclusively of Cluster 1. This cluster concentrates 4,298 customers, corresponding to 99.15% of the total base, and is responsible for R$6,093,130 of the transacted value, or 69.55% of the revenue. The consumption profile of this group is diversified, with a higher participation in the Utilities, Kitchen, and Vintage categories, whose centroid values were 215, 146, and 134, respectively. The large number of customers and the dispersion of consumption across various categories indicate that this group is the main base supporting the online store’s sales volume.
Despite its vast representativeness in terms of number of clients, the participation of the Low-Medium Average Ticket group in revenue is proportionally smaller, suggesting a lower average transaction value per client compared to other groupings. From a managerial perspective, the main opportunity for this group lies in increasing the value generated per client. This can be achieved through scalable strategies, such as increasing the average ticket, encouraging repeat purchases, and implementing cross-selling actions. However, the massive size of the group limits the viability of highly individualized strategies, making it more effective to adopt large-scale segmented marketing campaigns, aiming to optimize engagement and conversion efficiently.
The second grouping, named High Average Ticket, is formed by Clusters 2 and 3. This group, although representing a small number of clients, with 30 clients in Cluster 2 (0.69% of the base) and four clients in Cluster 3 (0.09% of the base), has a high individual contribution to revenue. Cluster 2 accounts for 1,388,548 of the transacted value, or 15.85% of the revenue, with a higher concentration of consumption in Utilities (8,231), Materials (6,293), and Kitchen (5,726). Cluster 3, on the other hand, contributes 572,121 of the transacted value (6.53%) and shows a higher concentration in the Kitchen (19,699), Romantic (18,389), and Materials (17,828) categories. Together, these two clusters sum up to 34 clients, representing only 0.78% of the base, but are responsible for 22.38% of the total transacted value, highlighting their economic relevance.
The main characteristic of the High Average Ticket grouping is the significant economic contribution per client, making them strategic targets for retention and relationship maximization actions. From a managerial point of view, initiatives such as loyalty programs, personalized service, and up-selling offers are highly recommended for this group. The objective is to increase purchase recurrence and the long-term value of the relationship. However, the small number of clients in this grouping also represents a considerable risk for the business, as the loss of a few individuals can generate a disproportionate financial impact on the company’s total revenue, requiring continuous monitoring and care.
The third grouping, classified as Very High Average Ticket, is composed of Clusters 4, 5, and 6. This group is the smallest in the adopted solution, gathering only seven clients in total, which corresponds to 0.16% of the client base. However, these few clients are responsible for approximately 8.07% of the transacted value, demonstrating exceptionally high purchasing power and engagement. Cluster 4, with a single client, showed a strong concentration in Stationery, with a value of 168,470 in the centroid. Cluster 5, also with one client, stood out for Decoration (70,211), Romantic (31,822), and Vintage (31,132). Finally, Cluster 6, also unitary, presented a higher concentration in Utilities (53,998), Toys (30,485), and Materials (29,815).
The results for the “Altíssimo Ticket Médio” (Very High Average Ticket) cluster show consumption behaviors with extremely high transaction values compared to other groups. From a managerial perspective, these clients are considered of utmost economic relevance and require individualized and strategic monitoring. The opportunity lies in establishing long-term commercial relationships, with personalized service and integration with operational processes, such as logistics and supply planning, to ensure satisfaction and loyalty. However, the interpretation of these groupings requires caution, as the formation of clusters with few clients can be a result of genuinely differentiated consumption profiles or the influence of extreme observations on the K-Means algorithm. Thus, these findings should be viewed as evidence of extreme or highly differentiated behaviors in the studied database, and not necessarily as generalizable market segments.
Synthesis of Clusters
The organization of the results into three managerial groups revealed a consumption structure strongly concentrated in the analyzed customer base. The first group, encompassing the vast majority of customers, represents the main sales volume base and demands scalable marketing strategies. In contrast, the High and Very High Average Ticket groups, although numerically small, concentrate a significant portion of revenue, justifying highly personalized approaches focused on retention and individualized relationship management. This duality of consumption profiles underscores the need for a multifaceted marketing strategy capable of meeting the diverse needs and values of customers.
The concentration of revenue in a very small portion of the client portfolio represents a substantial risk for the business. Clusters 2 to 6, which correspond to only 0.85% of the client base, are responsible for 30.45% of the transacted value. This proportion is even more pronounced than the 80/20 relationship, often associated with the Pareto principle (Pareto, 1996), indicating a high dependence on a few clients for revenue sustainability. Therefore, the findings emphasize the urgency of developing differentiated relationship strategies, combining mass actions for the majority base with individualized, high-touch initiatives for high-value clients, mitigating risks and exploring growth opportunities.
Limitations of K-Means and Other Algorithms
Although the K-Means algorithm was selected for its simplicity, scalability, and widespread use in customer segmentation, its application in this study revealed some inherent limitations. K-Means relies on distances and centroids, making it sensitive to variable scale, data distribution, and notably, the presence of extreme observations. The identification of unitary clusters, while interpreted as high strategic value profiles, may also be a manifestation of this sensitivity to outliers, requiring careful interpretation of the results.
The literature points to the existence of alternative methods that could offer complementary perspectives. Hierarchical clustering, for example, would allow an analysis of group formation at different levels of granularity, without the need to pre-define the number of clusters, which could enrich the understanding of the data structure. Another algorithm, DBSCAN, would be useful for verifying whether the customers identified as outliers by K-Means are, in fact, isolated observations or part of denser regions. The absence of a comparison with these approaches constitutes a limitation of the research, as it prevents verification of the robustness and reproducibility of the identified clusters, leaving an opportunity for future investigations.
In summary, customer segmentation through the K-Means algorithm allowed for the identification of distinct consumption profiles and their strategic implications for online retail. The results revealed a heterogeneous customer base, with a large majority of low individual value and a small portion of very high-value customers, who concentrate a disproportionate share of revenue. This in-depth understanding of customer behavior provides valuable subsidies for formulating marketing, retention, and customer value maximization strategies, addressing both growth opportunities and risks associated with revenue concentration, and responding to the objective of identifying consumption patterns and supporting marketing decisions.
4. Conclusion
The study sought to segment customers from an online retail transactional database using the K-Means algorithm, aiming to identify distinct consumption profiles and analyze their implications for formulating marketing, retention, and customer value maximization strategies. A highly concentrated consumption structure was observed, where the vast majority of customers, corresponding to 99.15% of the base, presented low individual value but were responsible for 69.55% of the revenue. In contrast, a small portion of customers, representing 0.85% of the base, was identified as concentrating 30.45% of the total revenue, including single-unit clusters representing extreme and high strategic value consumption profiles. This segmentation enabled an in-depth understanding of customer behavior, providing subsidies for the formulation of differentiated marketing strategies, from scalable actions for the majority base to highly personalized approaches for high-value customers, and highlighted growth opportunities and risks associated with revenue concentration.
Despite the relevance of the findings, the research presented limitations. The K-Means algorithm demonstrated sensitivity to the scale of the variables, the distribution of the data, and the presence of extreme observations, which may have influenced the formation of unitary clusters. Additionally, the use of data from a single UK retailer and a one-year period restricts the generalization of the results, and the manual categorization of products may have introduced interpretative biases. For future studies, it is suggested to compare the identified groupings with alternative methods, such as hierarchical clustering or DBSCAN, in order to verify the robustness and reproducibility of the results, enriching the understanding of the data structure and managerial applicability.
Bibliographic References
Bussab, W. O.; Miazaki, E. S.; Andrade, D. F. 1990. Introdução à análise de agrupamentos. IME-USP, São Paulo, SP, Brasil. Disponível em: <https://cicerocq.wordpress.com/wp-content/uploads/2019/05/analise-de-agrupamento_bussab.pdf>. Acesso em: 12 abr. 2026.
Falcão, R. F.; Mazzero, S.; Campomar, M. C.; Toledo, G. 2016. A criação de valor para o cliente com base nos processos estratégicos de segmentação e posicionamento. Revista Interdisciplinar de Marketing, 6(2): 25–41.
Goldschmidt, R.; Passos, E. 2005. Data mining: conceitos, técnicas, algoritmos e orientações para aplicações. 1ed. Elsevier, Rio de Janeiro, RJ, Brasil.
Gomes, M. A.; Meisen, T. 2023. A review on customer segmentation methods for personalized customer targeting in e-commerce use cases. Information Systems and e-Business Management, 21: 527-570.
Géron, A. 2019. Hands-on machine learning with Scikit-Learn and TensorFlow: concepts, tools, and techniques to build intelligent systems. 2ed. O’Reilly Media, Inc., Sebastopol, CA, EUA.
Haley, R. I. 1968. Benefit segmentation: a decision-oriented research tool. Journal of Marketing, 32(3): 30-35.
Herdiana, I.; Kamal, M. A.; Estri, M. N. 2025. A more precise elbow method for optimum K-means clustering. arXiv (Cornell University).
John, J.; Shobayo, O.; Ogunleye, B. 2023. An exploration of clustering algorithms for customer segmentation in the UK retail market. Analytics, 2(4): 809–823.
Johnson, R. A.; Wichern, D. W. 2007. Applied multivariate statistical analysis. Pearson Prentice Hall, Upper Saddle River, NJ, EUA.
Kotler, P.; Keller, K. L. 2012. Administração de marketing. 14ed. Pearson, São Paulo, SP, Brasil.
Mahesh, B. 2019. Machine learning algorithms – a review. International Journal of Science and Research (IJSR), 9(1): 381-386.
Pareto, V. 1996. Manual de economia política. Editora Nova Cultural, São Paulo, SP, Brasil. Disponível em: <https://www.projetos.unijui.edu.br/economia/files/Pareto.pdf>. Acesso em: 12 abr. 2026.
Article originating from the Final Course Work of the Specialization in Data Science and Analytics of the MBA USP/Esalq
To learn more about the course, click here and access the MBX Academy platform