October 02, 2026
Customer retention in e-commerce through predictive models
Customer Retention in E-commerce Through Predictive Models
Enzo Eluan Cruz; Gabrielle Maria Romeiro Lombardi
DOI: 10.22167/2675-6528-202602866
Article derived from a Course Conclusion 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
The growth of e-commerce has expanded the availability of data related to consumer behavior, enabling the application of analytical methods for understanding different purchasing profiles. The objective was to analyze the behavior and profile of e-commerce customers based on demographic, behavioral, financial, and perceptual characteristics, seeking to identify patterns related to consumption, satisfaction, and purchase recency. A public and synthetic dataset was used, with 350 records and 11 variables. The analysis included data exploration, K-Means segmentation, construction of RFM indicators, engagement, spending ranges, and inactivity, as well as supervised models for classifying the satisfaction level and estimating total spending. The segmentation identified seven clusters with different behavioral combinations, presenting a Silhouette index of 0.7139. In satisfaction classification, Random Forest and XGBoost correctly classified all observations in the test set, while Logistic Regression achieved an accuracy of 0.9714. In total spending estimation, Random Forest showed the best performance, with an R² of 0.999396. The results highlighted different behavioral configurations among consumers and a strong structuring of relationships in the database. Considering the synthetic nature of the data, the findings are exploratory and should not be generalized to real consumers without external validation.
Keywords: data science; E-commerce; Consumer behavior; Satisfaction; Customer segmentation.
1. Introduction
The advancement of e-commerce has intensified the need to understand consumer behavior in highly competitive and data-driven digital environments. In this context, the ability to identify consumption patterns, segment customers, and anticipate churn risks becomes a strategic differentiator for companies operating in the digital environment. The growing availability of transactional, behavioral, and perceptual data, combined with the development of artificial intelligence techniques, enables the application of more robust analytical methods capable of transforming data into relevant information for decision-making. As highlighted by Silva et al. (2021), e-commerce has expanded access to information and raised consumer expectations, making the use of more sophisticated strategies to attract and retain customers essential.
In this scenario, customer retention plays a central role in the sustainability of companies, especially in markets where the cost of acquiring new consumers tends to be high. The literature indicates that customer satisfaction is directly related to organizational success and long-term loyalty.
As Rossi and Slongo (1998) argue, satisfaction analysis is one of the pillars for the development of effective marketing actions. However, traditional approaches based solely on descriptive analyses or point-in-time evaluations present limitations given the volume and complexity of data available in digital environments. Therefore, the use of analytical models capable of capturing more complex patterns and providing predictive support for decision-making becomes necessary.
Recent studies demonstrate the growing application of Machine Learning techniques in predicting churn and segmenting customers in e-commerce environments. Xiahou and Harada (2022) used the K-Means algorithm for consumer segmentation, subsequently applying classification models to predict customer abandonment in the B2C context. Recent research, such as Rahman et al. (2025), also explores algorithms like Random Forest to identify behavioral patterns and classify consumers with a higher probability of churn, reinforcing the potential of these techniques for retention strategies. Robust models based on ensemble learning algorithms, such as the one proposed by Wang and Chen (2019) with Logistic Regression and XGBoost, also show promising results in churn problems. Despite these advances, there is still room for studies that simultaneously integrate exploratory analysis, feature engineering, customer segmentation, and multiple predictive models within a single analytical framework applied to the e-commerce context, a gap that the present work seeks to address.
Given this context, the present work aimed to analyze the behavior and profile of e-commerce customers based on demographic, behavioral, financial, and perceptual characteristics, seeking to identify patterns related to consumption, satisfaction, and purchase recency. For this purpose, exploratory data analysis techniques, customer segmentation, construction of behavioral indicators, and supervised modeling were employed as analytical instruments for the characterization of the different profiles present in the dataset. Additionally, we sought to evaluate patterns associated with the level of satisfaction and total spending observed, contributing to an integrated understanding of the characteristics of the consumers represented in the analyzed database.
2. Material and Methods
The present study adopted a quantitative methodological approach, of an exploratory and predictive nature, to analyze the behavior of customers in e-commerce. The research was structured in stages that included the preparation and exploratory analysis of data, customer segmentation, construction of derived indicators, and application of supervised learning models. The methodological focus was on classifying the level of satisfaction and estimating the total observed expenditure.
The dataset used was the “E-commerce Customer Behavior Dataset”, a public and synthetic database made available on the Kaggle platform by Laksika (2024). This dataset contained 350 individual customer records and 11 original variables, covering demographic characteristics (gender, age, city), consumption (total spending, items purchased, days since last purchase), and perceptual (average rating, satisfaction level, membership type, discount application). The synthetic nature of the data was considered in the interpretation of the findings.
Data preparation involved checking the integrity of the database, including variable types and absence of duplicates, while maintaining the original 350 records. Two missing values were identified in the “Satisfaction Level” variable; for classification, 348 valid observations were used. In supervised models, imputation of missing values in the explanatory variables was performed via Scikit-learn “pipelines”, using the median for numerical variables and the most frequent category for categorical ones, adjusted only on the training set.
Outlier analysis was conducted using the Interquartile Range (IQR) criterion for the variables “Age”, “Total Spend”, “Items Purchased”, “Average Rating”, and “Days Since Last Purchase”, without removing observations. Exploratory data analysis characterized the dataset through descriptive statistics and graphical representations. The non-parametric Kruskal-Wallis test and Mann-Whitney pairwise comparisons were applied to assess differences between satisfaction groups, with a significance level of 5%.
Customer segmentation was implemented with the K-Means algorithm, an unsupervised learning technique. The variables “Age”, “Total Spend”, “Items Purchased”, “Days Since Last Purchase”, and “Average Rating” were standardized using StandardScaler. The number of clusters (k) was defined by the joint analysis of the Elbow Method and the Silhouette index, resulting in the selection of seven clusters. K-Means was applied with k-means++ initialization, 10 independent initializations, and random_state=42. The visualization of the groups was performed by Principal Component Analysis (PCA), for exclusively graphical purposes, and the quality of the segmentation was evaluated by the Silhouette index.
Derived indicators were constructed to synthesize dimensions of customer behavior, including RFM metrics (Recency, Frequency, and Monetary Value), an engagement index, a total spending stratification, and an inactivity risk indicator. The RFM metrics were based on “Days Since Last Purchase”, “Items Purchased” (frequency proxy) and “Total Spend”, converted into scores from 1 to 5 and combined into an RFM Score, generating exploratory categories. The “Engagement Score” was a normalized heuristic index (0 to 100), composed of recency, items purchased, total spending, and average rating. The total spending stratification generated four categories based on percentiles, and the inactivity risk indicator was defined from the 75th percentile of “Days Since Last Purchase”. These indicators were used only for descriptive analyses.
Supervised modeling comprised two tasks: classification of satisfaction level (“Satisfaction Level”) and regression for total spend estimation (“Total Spend”). Only original attributes from the dataset were used as predictors. The data were divided into 80% for training and 20% for testing, with stratification by “Satisfaction Level” in classification. For classification, Logistic Regression, Random Forest, and XGBoost were compared, evaluated by accuracy, macro precision, macro recall, and macro F1-score. In regression, Random Forest Regressor, XGBoost Regressor, and Ridge Regression were compared, evaluated by R², RMSE, and MAE. Performance consistency was verified by cross-validation in five partitions for both tasks.
3. Results and Discussion
The results obtained throughout the different analytical stages showed that the behavior of consumers represented in the database cannot be adequately described by a single variable. Exploratory analyses, cluster segmentation, derived indicators, and supervised models converged in demonstrating distinct combinations between spending, purchase intensity, recency, evaluation, and satisfaction. This finding reinforces the importance of analyzing the consumer profile in a multidimensional way, using data science techniques as tools to support the understanding of patterns present in the database.
The initial exploratory analysis allowed for the characterization of consumer profiles and the examination of relationships between demographic, behavioral, financial, and perceptual characteristics. A balanced distribution between genders was observed, with 175 observations in each category, reflecting an original characteristic of the dataset and not a result of sample balancing. Consumer age was concentrated in the central ranges of the distribution, with no identification of significant outlier values, which describes the composition of the synthetic sample but does not allow for inferences about financial capacity or consumption propensity in a real population.
The variables related to purchasing behavior showed notable variations among observations, especially concerning total spending, the quantity of items acquired, and the interval since the last purchase. The distribution of customers’ total spending revealed different accumulated consumption ranges in the database, which were subsequently explored in conjunction with other behavioral characteristics for a deeper understanding of the profiles.
The variable representing the days since the last purchase also showed variation among consumers, indicating the recency of the last consumption interaction. It was observed that longer periods since the last purchase should not be interpreted, in isolation, as evidence of customer abandonment, as the dataset does not contain a variable that explicitly records the occurrence of churn or evasion.
The joint analysis of satisfaction level and purchase recency revealed differences in the distribution of days since the last purchase between satisfaction levels. Visually, consumers classified as dissatisfied showed longer periods since their last purchase than those predominantly observed in the neutral and satisfied categories, suggesting an association between these factors within the analyzed dataset.
The Kruskal-Wallis non-parametric test confirmed a statistically significant difference between the recency distributions of different satisfaction levels. Subsequent pairwise comparisons, performed using the Mann-Whitney test, identified which specific categories exhibited these differences. This finding points to an association between satisfaction and recency in the base, but does not establish a direct causal relationship between them.
Therefore, it is not possible to conclude that a lower level of satisfaction caused a longer period of inactivity or, conversely, that a longer period since the last purchase caused dissatisfaction. The exploratory analysis, in general, showed a variation in demographic, financial, behavioral, and perceptual characteristics, providing important subsidies for the subsequent segmentation analyses and construction of behavioral indicators. It is fundamental to reiterate that, due to the synthetic nature of the database, these patterns should be interpreted as characteristics of the analyzed set, without presuming their reproduction in real consumer populations.
Customer segmentation results
The application of the K-Means algorithm, configured for seven clusters, allowed the organization of the 350 consumers into distinct groups, based on different combinations of the five characteristics used in the segmentation: age, total spending, quantity of items purchased, days since last purchase, and average rating. This unsupervised approach was crucial for identifying intrinsic behavioral patterns without the need for predefined target variables.
The selected segmentation solution demonstrated a Silhouette index of 0.7139. This value indicates that, in the multidimensional space of standardized variables, the observations presented a relatively defined separation between clusters. The choice of the number of clusters was guided by the joint analysis of the Elbow Method and the Silhouette index, seeking a balance between inertia reduction and the quality of group separation, as detailed in the methodology.
To facilitate the visualization of the structure of the identified groups, Principal Component Analysis (PCA) was applied. The first two principal components jointly explained 91.43% of the variance of the standardized variables, with 74.23% attributed to the first component and 17.20% to the second. The resulting two-dimensional projection allowed for observation of the spatial organization of the groupings and the existence of distinct regions between some of the groups, although PCA was used exclusively for graphical representation purposes, without altering the original grouping process.
The characterization of the clusters revealed significant differences, mainly in the dimensions related to consumption, recency, and evaluation. Cluster two, for example, stood out with the highest average spending of 1,459.77, the largest average quantity of items purchased (twenty), the shortest average days since the last purchase (11.17), and the highest average rating (4.81). This group, within the analyzed base, gathered observations with higher consumption intensity, accumulated spending, and more recent purchases.
Cluster five also showed relatively high spending and item quantity, with averages of 1,165.04 and 15.27, respectively, accompanied by an average rating of 4.54. However, its average recency of 24.59 days was higher than that observed in cluster two, indicating a distinct behavioral combination, despite the high consumption values. Cluster one occupied an intermediate position in relation to spending and purchase intensity, with an average spending of 805.49, an average of 11.68 items, and an average interval of 15.27 days since the last purchase, in addition to an average rating of 4.17.
In contrast, cluster zero presented the lowest average spending among the groupings (446.89), the lowest average quantity of items acquired (7.57), and the lowest average rating (3.19). Despite these reduced levels, its average recency of 22.76 days was lower than that found in some groups with higher spending, demonstrating that lower accumulated spending does not necessarily correspond to a longer period since the last purchase. Cluster four, with relatively reduced spending (499.88) and an average of 9.41 items, stood out due to the average interval of 40.47 days since the last purchase, while cluster three presented the longest average interval of the entire segmentation, with 53.18 days, despite registering average spending of 703.69 and 12.76 items acquired.
Finally, cluster six presented intermediate values for spending (671.55), number of items (10.04), and evaluation (3.80), accompanied by a recency of 34.62 days on average. The comparison of profiles demonstrates that the analyzed dimensions did not vary uniformly among the clusters. Although clusters two and five combined higher levels of spending, number of items, and evaluation, other groups presented distinct combinations of consumption and recency. This segmentation allowed for the identification of different behavioral configurations within the base, rather than establishing a single ordering of customers into better or worse profiles.
Results of the derived indicators
The construction of the derived indicators complemented the exploratory analysis and segmentation, synthesizing different dimensions of the observed behavior in the dataset. RFM metrics, engagement index, stratification by total spending, and the operational inactivity indicator were examined. These indicators were used exclusively for the description and comparison of patterns present in the database, without participation as explanatory variables in the supervised models, in order to avoid redundancies and information leakage.
The exploratory classification based on the RFM score distributed the 350 observations into five categories. The “At Risk” category showed the highest frequency, gathering 137 consumers, which corresponds to 39.14% of the total. Next, the “Loyal Customers” category encompassed 91 observations, or 26.00%. The “Champions” and “Potential Loyalists” categories presented 59 observations each, representing 16.86% of the total, while “Lost” gathered only four consumers, or 1.14%.
The comparison of the profiles showed differences in the dimensions used for the construction of the indicator. The “Champions” category presented an average spending of 1,455.55, an average of 19.9 items acquired, 11.3 days since the last purchase, and an average rating of 4.81. In contrast, the “At Risk” category registered an average spending of 509.49, an average of 8.8 items, an average recency of 31.9 days, and an average rating of 3.40.
The “Loyal Customers” category presented intermediate higher values in consumption, with an average spending of 1,038.73 and an average of 14.1 items. The “Potential Loyalists” category, on the other hand, registered an average spending of 742.05, 12.0 items, and 37.2 days since the last purchase. The “Lost” category, composed of only four observations, presented an average spending of 475.25 and an average interval of 45 days since the last purchase, characterizing a profile of lower engagement and recency.
Despite the denominations attributed to the RFM categories, it is important to emphasize that these classifications do not represent real states of loyalty, risk, or abandonment observed in the database. They result exclusively from the defined intervals for the RFM score and should be interpreted as exploratory labels that facilitate comparison between different combinations of recency, purchase intensity, and spending, without inferring causality or definitive customer behavior states.
The “Engagement Score” presented values ranging from 18.66 to 99.32, with an average of 50.75 and a median of 51.46. The distribution of operational levels of this index indicated a higher concentration in the “Medium” and “High” categories, with 116 (33.14%) and 110 observations (31.43%), respectively. The “Very High” category gathered 66 consumers (18.86%), while “Low” presented 58 observations (16.57%), reflecting the combination of the dimensions of recency, purchase intensity, spending, and evaluation that compose it.
As the engagement index was constructed heuristically, with weights defined within the scope of this study, its distribution directly reflects the combination of these dimensions. Therefore, higher values should not be interpreted as a validated measure of real engagement, but rather as an internal comparative synthesis of the characteristics available in the database, allowing for a descriptive and exploratory analysis of consumer behavior.
The stratification based on Total Spend organized the observations into four spending ranges. The “Medium” category concentrated the majority of customers, with 173 individuals (49.43%), followed by the “Low” category, with 88 (25.14%). The “High” and “Premium” categories presented 46 (13.14%) and 43 observations (12.29%), respectively. These categories were defined from percentiles of the total spending distribution, serving as an instrument for descriptive segmentation.
Consumers classified as “Premium” showed the highest average spending, with 1,480.50, while the “High” category registered an average of 1,255.17. The “Medium” and “Low” categories showed average spending of 774.21 and 460.74, respectively. These differences are a direct consequence of the criterion used for category construction and represent only ranges of accumulated spending observed in the dataset, without implying future customer value or financial contribution.
The operational inactivity indicator classified 89 observations, corresponding to 25.4% of the total, in the upper quartile of the Days Since Last Purchase distribution, using 38 days since the last purchase as a threshold. The remaining 261 observations, or 74.6%, remained below this cutoff point. In granular classification, 168 consumers were classified as “Low Inactivity”, 93 as “Medium Inactivity”, 51 as “High Inactivity”, and 38 as “Critical Inactivity”.
These categories exclusively represent relative positions in the recency distribution of the analyzed base and should not be interpreted as a predictive model of evasion or churn. The group above the inactivity threshold showed an average recency of 45.6 days and an average spending of 585.19, while the observations below the threshold had an average recency of 20.1 days and an average spending of 934.11. Although the group with higher inactivity also showed lower average spending and a higher concentration of dissatisfaction, these results represent descriptive associations and do not allow us to conclude that inactivity caused lower spending or dissatisfaction.
A particularly noteworthy finding was that, among the 89 observations classified above the operational inactivity threshold, all presented the satisfaction level “Unsatisfied”. This high regularity in the association should be interpreted with caution, especially due to the synthetic nature of the database, not constituting evidence of a causal relationship or an expected pattern in real consumer populations. Together, the derived indicators provided different ways to synthesize the observed consumer characteristics, enriching the exploratory and descriptive analysis of behavior.
Satisfaction level classification results
The classification task’s main objective was to examine the ability of the original dataset features to distinguish the three levels of satisfaction recorded in the Satisfaction Level variable: Satisfied, Neutral, and Unsatisfied. After excluding two records that lacked information for this variable, 348 observations were used for the classification task, ensuring data integrity for modeling.
The distribution of classes was relatively close among the three categories: the Satisfied class presented 125 observations (35.92%), followed by the Unsatisfied class, with 116 (33.33%), and the Neutral class, with 107 records (30.75%). The division of data into training and testing sets was stratified, resulting in 278 observations for training and 70 for testing, approximately preserving this class distribution in both subsets.
Three classification algorithms were compared: Logistic Regression, used as a linear reference model, and Random Forest and XGBoost, employed as tree-based methods capable of representing non-linear relationships and interactions between features. The numerical explanatory variables included age, total spending, items purchased, average rating, and days since last purchase, while the categorical ones were gender, city, membership type, and discount applied.
The tree-based models, Random Forest and XGBoost, presented maximum performance on the test set. Both correctly classified all 70 observations, resulting in accuracy, macro precision, macro recall, and macro F1 equal to 1.0000. Logistic Regression also demonstrated high performance, with an accuracy of 0.9714 and a macro F1 of 0.9716, and a small difference between training and test accuracy of 0.0070, indicating good consistency.
Five-fold stratified cross-validation confirmed the maintenance of high performance across different data splits. Random Forest and XGBoost presented an average macro F1 of 0.9971, with a low standard deviation of 0.0058, while Logistic Regression achieved an average of 0.9742 and a standard deviation of 0.0140. These results indicate that the high performance was not limited to the initial test set but is consistent across different subsets of the dataset.
However, values close to perfect classification should be interpreted with caution, considering the synthetic nature of the dataset and the high separability observed between some features and satisfaction classes. The Random Forest confusion matrix showed the correct classification of all 70 observations in the test set, with no incorrect classifications: 22 belonging to the Neutral class, 25 to the Satisfied class, and 23 to the Unsatisfied class.
In the analysis of variable importance for the Random Forest model, Days Since Last Purchase presented the highest relative importance (0.1559), followed by Total Spend (0.1381), Items Purchased (0.1273), and Average Rating (0.1097). Variables related to discount application, age, and membership type also contributed to the model’s decisions. In XGBoost, the distribution of importances showed a distinct pattern, with the category City_Houston standing out, whose relative importance was 0.3309, followed by Discount Applied_False (0.1432), Total Spend (0.1330), Age (0.1222), and Days Since Last Purchase (0.0895).
The high importance attributed to a specific category of city in the XGBoost model should be interpreted with special caution. Considering the synthetic nature of the base, this association may reflect artificial regularities present in the data generation process, and it is not appropriate to interpret it as evidence that geographical location exerts a causal influence on consumer satisfaction. In general, the three algorithms demonstrated a high capacity to distinguish satisfaction levels within the structure of the analyzed dataset.
The maximum performance of Random Forest and XGBoost, combined with the high results of Logistic Regression and cross-validation, suggests strong class separability from the available features. However, this result should be understood in the context of a synthetic and relatively small dataset, in which certain relationships between attributes and satisfaction may exhibit higher regularity than found in real data. Thus, the obtained values demonstrate the models’ capacity to represent the internal patterns of the dataset, but do not allow inferring equivalent performance in real consumers without external validation.
Total Spend Estimation Results
The second supervised task was formulated as a regression problem, aiming to estimate the total observed customer spending, represented by the Total Spend variable, from the other original characteristics available in the dataset. The 350 available observations were used, as the variable of interest did not present missing values, ensuring the completeness of the database for this analysis.
The Total Spend variable presented an average of 845.38, with a standard deviation of 362.06, and a median of 775.20. The observed values ranged between 410.80 and 1,520.10, showing a considerable amplitude of accumulated spending among the analyzed observations. The numerical variables used as predictors were age, items purchased, average rating, and days since last purchase, while the categorical ones included gender, city, membership type, and discount applied.
Three algorithms were compared for the regression task: Random Forest Regressor and XGBoost Regressor, used to represent possible non-linear relationships, and Ridge Regression, employed as a regularized linear reference model. Total Spend was excluded from the set of explanatory variables because it is the target variable itself, and derived attributes that incorporated spending information, such as RFM, Engagement Score, and Value Tier, were also excluded to avoid redundancies.
The three models showed high performance in estimating total observed expenditure. Random Forest achieved the highest coefficient of determination on the test set, with R² of 0.999396, followed by an RMSE of 9.03 and an MAE of 3.93. XGBoost presented similar performance, with R² of 0.999301, RMSE of 9.72, and MAE of 4.99, indicating a high predictive capacity for both tree-based models.
Ridge regression also achieved high performance, with R² of 0.996977, although it presented higher errors than tree-based models, with RMSE of 20.22 and MAE of 15.04. Considering the R², RMSE, and MAE metrics together, Random Forest showed the best performance on the test set among the evaluated models, demonstrating its robustness in predicting total spending.
Five-fold cross-validation reinforced the consistency of the observed performance. The Random Forest presented an average R² of 0.999039 and low standard deviation, indicating high and stable performance across the different data splits. Ridge regression obtained an average R² of approximately 0.9977, while XGBoost presented an approximate average of 0.9959, with greater variability between partitions.
Thus, the Random Forest maintained the best performance also in cross-validation, both in terms of average explanation of variability and stability among the evaluated subsets. The relationship between the observed and estimated values by the Random Forest showed strong proximity around the reference line, reflecting the low error values obtained by the model. The small visual dispersion observed is consistent with the high R² and the reduced RMSE and MAE values.
Although the models’ performance was very high, this result should be interpreted in light of the dataset’s structure. Ridge regression, despite being a regularized linear model, achieved an R² greater than 0.996, suggesting the presence of strongly structured and near-linear relationships between Total Spend and the available explanatory variables. This behavior is compatible with the synthetic nature of the dataset, in which the relationships between variables may exhibit greater regularity than expected in real e-commerce data.
Thus, the results demonstrate that the models were capable of reproducing the internal patterns of the analyzed set with high precision, but they do not constitute evidence of equivalent performance in real environments. The high performance obtained is also consistent with the patterns observed in the exploratory and segmentation stages, in which consumers with a larger quantity of acquired items, better evaluations, and certain association profiles presented distinct levels of accumulated spending. However, the relationships identified by the models should be interpreted as associations present in the database, not as causal evidence about the factors that determine consumer spending.
In summary, the supervised models showed a high capacity to estimate the total expenditure observed within the analyzed database, with emphasis on Random Forest, which demonstrated the best performance in both the test set and cross-validation. The high explanatory capacity also observed in the Ridge model suggests a strong structuring of the relationships between the variables of the synthetic set. As in the satisfaction classification task, the results should be understood as evidence of internal performance within the database, not as a guarantee of generalization to real consumers without external validation.
Integrated discussion of results
The integrated analysis of the results reinforces the understanding that consumer behavior in e-commerce is multifaceted, and cannot be simplified to a single dimension. The various analytical steps, from initial exploration to supervised modeling, converged on the identification of complex patterns that combine spending, purchase intensity, recency, evaluation, and satisfaction, underscoring the relevance of multidimensional approaches in data science for understanding the consumer profile.
Customer segmentation by K-Means revealed seven distinct clusters, each with a particular combination of the analyzed characteristics. This approach demonstrated that consumers with similar levels in a specific dimension do not always exhibit equivalent behaviors in others. For example, cluster three, which showed a higher average spending than some groups, also registered the largest average interval since the last purchase, indicating a complexity that transcends simplistic classifications of “best” or “worst” customer.
The results of this work are compatible with behavioral segmentation approaches employed in previous studies in the context of e-commerce, such as those by Xiahou and Harada (2022) and Rahman et al. (2025). However, it is important to note that, in the present study, the variable “Items Purchased” was used as an approximation of purchase frequency due to the absence of a variable that recorded the effective number of transactions. This limitation prevents the interpretation of the frequency component as transactional, differentiating its application from studies based on complete purchase histories.
The RFM analysis reinforced the behavioral heterogeneity observed in the segmentation, organizing observations into exploratory categories of recency, purchase intensity, and spending. The higher concentration in the “At Risk” category (39.14% of consumers) should be interpreted as a descriptive label derived from the RFM score intervals, rather than as evidence of actual churn risk. The RFM categories, as well as the “Engagement Score”, were constructed in an exploratory and heuristic manner, serving as internal comparative tools for the database.
One of the most consistent patterns identified was the association between satisfaction and purchase recency. Exploratory analysis demonstrated that consumers classified as “Unsatisfied” presented, on average, longer periods since their last purchase compared to the “Neutral” and “Satisfied” categories. This difference was confirmed by the Kruskal-Wallis test, indicating that the recency distributions were not equivalent across satisfaction levels, establishing a significant association within the analyzed base.
Although this result is relevant for the characterization of the profiles present in the database, it does not allow for the establishment of a causal direction. It is not possible to determine, from the available data, whether dissatisfaction preceded the longer period without purchases, whether the reduction in activity contributed to the satisfaction assessment, or whether both are associated with other characteristics not represented in the dataset. This association, however, finds a parallel in the literature that relates satisfaction to the continuity of purchasing behavior in e-commerce, even if the constructs and methods used in other studies are not directly equivalent to the variables of this research.
The high separability observed between satisfaction and other characteristics of the dataset was also reflected in the supervised modeling. The Random Forest and XGBoost models correctly classified all observations in the test set, while Logistic Regression presented an accuracy of 0.9714. Cross-validation maintained equally high values, indicating that the performance was not restricted to a single data split, which suggests a strong structuring of the internal relationships in the dataset.
However, results close to perfect classification should be interpreted with caution. The fact that all 89 observations located above the operational inactivity threshold belong to the “Unsatisfied” class, associated with the striking recency differences between the classes, reveals a highly regular structure in the base. Thus, the high performance may primarily reflect the inherent separability of the synthetic data, and not necessarily the algorithms’ ability to generalize to real consumers in e-commerce environments.
This interpretation is reinforced by the analysis of variable importance. In Random Forest, Days Since Last Purchase, Total Spend, Items Purchased, and Average Rating showed relevant contributions to the satisfaction classification. In XGBoost, on the other hand, the high importance attributed specifically to the City_Houston category suggests the presence of particular patterns in the synthetic data generation, making it inappropriate to interpret this result as evidence of causal geographical influence on consumer satisfaction.
The regression task to estimate total spending showed similar behavior. Random Forest achieved an R² of 0.999396 on the test set and maintained an average R² of 0.999039 in cross-validation. Although this performance demonstrates a high capacity to reproduce the internal patterns of the database, Ridge Regression also presented an R² greater than 0.996, even using a regularized linear structure, which suggests strongly structured and near-linear relationships between Total Spend and the explanatory variables available in the analyzed synthetic set.
The high performance of a linear model suggests that the relationships between Total Spend and the explanatory variables exhibit strong structuring in the analyzed synthetic dataset. In data from real consumers, a greater presence of noise, unobserved variables, and less regular behaviors is expected, which is why the results should not be directly extrapolated to commercial applications. Considered together, the results indicate that the profile of consumers represented in the database was differentiated mainly by the combination of purchase intensity, accumulated spending, recency, evaluation, and satisfaction.
Cluster analysis showed that these dimensions combine in distinct ways among consumers; the derived indicators allowed synthesizing part of these differences; and the supervised models demonstrated that the original characteristics of the database have a strong relationship with satisfaction and total observed spending. Thus, the machine learning techniques employed fulfilled an instrumental function in the study: they allowed organizing, comparing, and representing behavioral patterns present in the dataset. The main result lies not in the isolated performance of the algorithms, but in the identification of different consumer behavior configurations and in the understanding of the existing relationships between consumption, recency, evaluation, and satisfaction within the structure of the analyzed database.
4. Conclusion
This work sought to analyze the behavior and profile of e-commerce customers based on demographic, behavioral, financial, and perceptual characteristics, with the aim of identifying patterns related to consumption, satisfaction, and purchase recency. It was found that the behavior of the consumers represented in the database is multifaceted, not being restricted to a single dimension. K-Means segmentation identified seven distinct clusters, each with particular combinations of spending, purchase intensity, recency, evaluation, and age. A consistent association was observed between satisfaction level and purchase recency, where dissatisfied consumers, on average, had longer periods since their last interaction. Additionally, supervised models demonstrated a high capacity to classify satisfaction levels and estimate total spending, with Random Forest and XGBoost achieving maximum performance in classification and Random Forest presenting an R² of 0.999396 in spending estimation. The main contribution of the study lies in demonstrating the instrumental role of data science techniques for organizing, comparing, and representing complex behavioral patterns, allowing for an integrated understanding of consumption profiles and the relationships between variables in the analyzed database.
However, it is essential to acknowledge the limitations inherent in the synthetic nature and small size of the dataset used. The observed relationships exhibited high regularity, leading to model performances close to perfection, and are therefore not generalizable to real consumers without external validation. The use of “Items Purchased” as a proxy for purchase frequency and the descriptive nature of the inactivity indicator also limit inferences about transactional behavior and churn risk. For future studies, it is suggested to apply the developed analytical framework to real, longitudinal databases that include transaction history and other behavioral characteristics, in order to evaluate the stability and generalizability of the identified patterns in more complex and dynamic e-commerce contexts.
Bibliographic References
Digital marketing, E-commerce and pandemia: a bibliographic review on the brazilian panorama. Research, Society and Development, [S. I.], v. 10, n. 5, p. e45210515054, 2021. DOI: 10.33448/rsd-v10i5.15054. Disponível em: https://rsdjournal.org/rsd/article/view/15054. Acesso em: 2 nov. 2025.
RAHMAN, M. et al. Customer Segmentation and Churn Prediction Based on K-Means and Random Forest: A Case Study of E-commerce Data. 2025. Acesso em: 23 abr 2026
ROSSI, Carlos Alberto; SLONGO, Luiz. Pesquisa de satisfação de clientes: 0 estado-da-arte e proposição de um método brasileiro. Revista de Administração Contemporânea, v. 2, n. 1, p. 101-125, Jan./Abr. 1998. Disponível em: https://www.scielo.br/j/rac/a/nwpfNHVMj4LYjbrxbQmCFNS/?lang=pt. Acesso em: 02 nov. 2025.
THARMALIGAN, LAKSIKA. E-commerce Customer Behavior Dataset. Kaggle, ano. Disponível em: https://www.kaggle.com/datasets/uom190346a/e-commerce-customer-behavior-dataset. Acesso em: 04 jan 2026.
WANG, Y.; CHEN, L. A Hybrid Prediction Model for E-Commerce Customer Churn Based on Logistic Regression and XGBoost. Ingénierie des Systèmes d’Information, v. 24, n. 5, p. 517-523, 2019. Acesso em: 23 abr 2026.
XIAHOU, X.; HARADA, Y. B2C E-Commerce Customer Churn Prediction Based on K-Means and SVM. Journal of Theoretical and Applied Electronic Commerce Research, v. 17, n. 2, p. 458-475, 2022. Acesso em: 23 abr 2026.
Article originating from the Final Course Project 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