1
Customer Segmentation for E-commerce Using
Logistic Regression-Nearest Neighbour and
Decision Tree
Kalidasan Nediyamparambath
Master of Science in Information Technology(IT)
Technische Hoschule OWL Lemgo, Germany
I. MOTIVATION deal with problems with the abandoning of shopping carts and
the loss of customers. Using customer segmentation, one may
Customers are the most precious asset for any organisation. gain valuable insights into the factors that are responsible for
without them, it is difficult to continue operating. Each these actions. By categorising customers according to their
consumer has unique preferences. Not all consumers can be engagement level, purchase history, and lifecycle stage,
handled similarly. In the fast-paced realm of online commerce, businesses can implement individualised strategies that can
understanding and dealing with the varied requirements of reduce the number of customers who abandon their shopping
clients is crucial for achieving success. Customer segmentation carts and prevent churn. Companies can customise their
is essential for the maintenance of sustainable corporate advertising efforts, product suggestions, and promotions when
growth. they properly categorise their clients. To generate personalised
Customer segmentation is the process of categorising clients experiences that boost connection and relevance,
based on shared features. It might be based on many personalised email campaigns, curated product suggestions,
parameters. The key segmentation criteria are Demographic, and changed landing pages are implemented. This ultimately
Psychographic, Geographic, and Behavioural. It accurately results in higher engagement and loyalty.
mirrors the individual demands of each consumer and Some characteristics define the constantly shifting context
identifies the most straightforward method to meet those of the e-commerce industry. These characteristics include
wants. This technique’s main contribution is significant. It is not quick changes in client behaviour, trends in the market, and the
only simplifying marketing but also enhancing the acceptance dynamics of competition. firms can acquire the agility and
of the business. It gives businesses the ability to scrutinise the flexibility that is necessary to effectively adapt to these
purchase patterns of their clients to enhance customer service changes by utilising customer segmentation. This allows the
and happiness. In addition to this, it assists firms in firms to better serve their unique customers. E-commerce
determining their target consumers and improving their platforms can maintain their competitiveness and stay ahead
marketing methods to boost income. of the curve in an environment that is always changing if they
The platforms that facilitate e-commerce cater to a diverse continuously analyse data from their customers and adapt
spectrum of customers, each of whom has their own set of their segmentation tactics in response to the shifting
preferences, habits, and needs. By classifying clients according circumstances of the market. Their ability to sustain their
to demographic factors such as age, gender, geography, and competitiveness and remain ahead of advances is made
economic status, businesses have the opportunity to get possible as a result of this. In addition to influencing product
valuable insights about their customer base. Having this development and innovation, customer segmentation serves
understanding serves as the basis for targeted marketing as a guide for marketing strategies. By understanding the
campaigns, personalised product recommendations, and needs, preferences, and problems that are experienced by
pricing strategies that are tailored to certain customer groups. different types of customers, businesses can develop their
Behavioural patterns and buying habits are analysed through product offerings to meet the demands of the market. The
the process of customer segmentation, which delves further provision of new features, the expansion of product lines, or
into demographic characteristics. Through the analysis of the development of services that are tailored to a certain niche
purchase frequency, average order value, browsing history, and are all examples of customer centric innovations that may
involvement with marketing campaigns, businesses can assist businesses in distinguishing themselves and remaining
identify high-value customers, forecast future spending trends, successful in the highly competitive e-commerce industry.
and tailor promotions to maximise conversion rates. Through Apart from increasing sales right away, customer segmentation
the categorization of customers based on their actions, is a key part of building ties with customers that last.
ecommerce platforms have the potential to offer individualized Businesses can gain customers’ trust, loyalty, and support over
experiences that are suited to the preferences and motivations time by giving them personalised experiences and showing
of each individual. E-commerce businesses frequently have to that they understand their needs. Targeted communications,
2
special deals, and personalised support that go deeper with machine learning, in which computers utilise labelled training
customers help them feel like they belong and connect with data to predict or make conclusions regarding new, raw data.
the brand, which turns one-time buyers into repeat buyers and Supervised learning involves training examples that include
brand champions. input attributes and their associated suitable output or label.
The process of customer sorting used to be easier and more The objective is to establish a relationship between input
manual than it is now. Businesses relied on limited data variables and output variables, enabling the algorithm to
sources, basic segmentation criteria, and human analysis generalise and provide precise predictions for new data.
methods to divide customers into groups and make sure their Supervised learning may be categorised into two primary
marketing strategies were targeted to the right people. Still, groups: classification and regression. Classification tasks
companies were able to effectively target and connect with involve predicting the category of a new data point, whereas
different types of customers by using the data they had. regression tasks involve predicting a continuous value.
Human processing and basic statistical methods were needed Supervised learning techniques often used are logistic
to process huge amounts of data or recognise complex regression, decision trees, support vector machines (SVM), and
patterns. This limited the level of detail and accuracy of artificial neural networks.
segmentation models. Often, segmentation criteria were set Logistic regression is a supervised learning technique
based on broad ideas or personal experience instead of facts. specifically designed for binary classification applications.
This led to rough targeting and marketing methods that might Logistic regression predicts the possibility of a data point
not work. Marketing campaigns often had low reaction and belonging to a specific class by utilising a logistic function. It is
conversion rates, which wasted resources and missed chances well accepted in predictive modelling and can determine a
to make money [1]. Without advanced statistics or real-time linear decision boundary that classifies the classes according to
feedback tools, it was hard to keep track of how clients the input characteristics. [5] Logistic regression is frequently
responded and figure out how well the campaign worked. In used in binary classification tasks where the result variable
the past, businesses didn’t have as many reliable or useful ways might take on one of two categories (0 or 1). Logistic regression
to divide their customer base as they do now, thanks to has some unique features. The training process recognises
advanced data analytics and technology that makes these patterns in the input data, like as images, and links them to
methods possible. certain outputs or labels. Training a logistic model using a
The advent of Machine learning algorithms, powered by regression approach does not need significant processing
extensive data and computer power, has transformed how resources. Logistic regression is simpler to implement,
organisations segment their customers. Complex data may be comprehend, and train compared to other machine-learning
examined by algorithms to reveal patterns, trends, and techniques. A dataset is said to be linearly separable if it is
correlations that may not be apparent by conventional represented by a graph in which the two data classes are
approaches. Algorithms can analyse intricate data and identify separated by a straight line. When using logistic regression, the
patterns, trends, and connections that may not be evident by y variable can only take on two possible values. Therefore, if
traditional methods [2]. E-commerce businesses may employ linearly separable data is utilised, it is possible to properly
machine learning to get vital information about their customer categorise data into two distinct categories. Logistic regression
base and develop accurate and effective marketing strategies. assesses the significance of an independent/predictor variable
by its coefficient size and indicates whether the connection is
positive or negative. A sigmoid function is used to represent
II. STATE OF THE ART
the probabilities and predictions. It is an S-shaped curve that
This section explores the current developments in client has a value between 0 and 1. If the output of the function is
segmentation approaches, with an emphasis on the latest greater than the threshold then the model will predict the
developments utilising algorithms. With the help of instance belongs to the class and if the output is lesser, it does
sophisticated machine learning classifiers such as Logistic not belong to the class.
Regression, K-Nearest Neighbours, and Decision Trees to K-nearest neighbours (KNN) is an algorithm for classification
investigate how firms may successfully segment their and regression tasks that is implemented under supervised
consumer base in the dynamic e-commerce market to improve learning [6]. A dataset including plotted dots on a graph, where
their development and profitability. each point corresponds to an observation characterised. The
Machine learning (ML) is a technique that enables systems KNN algorithm examines the” k” nearest neighbours to the
to learn autonomously from real-world interactions and point that is categorised or predicted. After determining the k
generalise from instances without requiring explicit nearest neighbours, labels are determined. The KNN algorithm
programming, unlike rule-based programming. Machine predicts the label for the new point by considering the k closest
learning is crucial and has a wide range of applications. neighbours. The new point is allocated the label that is most
Machine learning classifiers are used to effectively segment often used among the neighbours and determines the closest
the customers.[3] Machine learning classifiers are algorithms neighbours by using a distance metric, usually Euclidean
that group data points into distinct classes or categories distance, however, other metrics such as Manhattan distance
according to their attributes. These classifiers are essential in or cosine similarity may also be used. Distance between
supervised learning.[4] Supervised learning is a core concept in
3
locations is determined by their characteristics, and the k testing purposes. The findings of the previous phase are used
closest neighbours are selected appropriately. Using their to determine which machine learning model ought to be
characteristics, determine the distance between locations and presented as the best option.
then choose the k closest neighbours. The value of k, which
denotes the number of neighbours to take into account, is a
vital parameter in KNN. A lower k number may result in
intricate decision boundaries, while a higher k value can lead
to more uniform boundaries. The ideal value of k is established
by cross-validation and varies based on the dataset and specific
situation [7]. The KNN method predicts the output value for a
new point in a regression problem by averaging the output
values of its k closest neighbours. KNN is well-suited for
predicting continuous values.
In the area of machine learning, the decision tree algorithm
is a kind of supervised learning that is widely used for solutions
to classification and regression tasks. It creates a tree structure
that can predict accurately about the target variable. In this
procedure, data is recursively divided into subsets according to
the feature values provided. The decision made on every
particular feature value by such an algorithm generates a node Figure 1
in the obtained tree structure. These edges emanating from a
A. Dataset Description
node represent possible outcomes of this choice. The process
uses multiple attributes and criteria to partition data most The data of an E-Commerce platform has been taken from
vitally usually to improve accuracy and increase precision [8]. the open-source data repository website Kaggle including the
Decision trees employ Gini impurity, Entropy or Information records of purchases made by consumers between December
gain as splitting criteria. After tree construction, leaf nodes give 1, 2010, and December 9, 2011. The data include the details of
predictions or classifications for each record. Interpretability is 4000 customers and consist of 8 variables.
one key feature of the decision tree algorithm because its
predictions can be visualized and understood quite easily. Serial Number Attribute Data Type
Decision trees are also capable of handling both numerical and 1 InvoiceNo String or Integer
categorical data which makes it more versatile among other
2 StockCode String
algorithms [9].
Here in this paper. We have initiated an innovative approach 3 Description String
using machine learning techniques to segment the customers 4 Quantity Integer
of the e-commerce platform. Logistic regression, k-Nearest 5 InvoiceDate DateTime
neighbour, and Decision tree are the three algorithms 6 UnitPrice Float
implemented effectively to segment the customers. The test 7 CustomerID Integer
results of the models have gone through a detailed comparison 8 Country String
for accuracy and distinguished the better algorithm for
segmentation. In the modern world, the field of machine
learning is expanding at an extraordinarily rapid rate. The Table 1
methods of machine learning can discover patterns and
insights that are uniform, and they may be used to generate B. Data Pre-processing
accurate predictions [10]. With the available data set, different analyses and
evaluations as shown below.
III. SOLUTIONS 1) Checking the missing values: By checking the data for
In the experiment, we followed a sequential analytical any missing values, we were able to prevent the occurrence of
approach that had to be considered while performing the biased findings, preserve the effectiveness of the model, and
segmentation tasks. A number of different processes are reduce the number of instances of incorrect classification.
shown in Figure 1. The procedure begins with the collection of 2) Splitting Data: The train test split function of Sklearn
data and the organisation of datasets to identify and correct was used to split the data into train and test data sets. It was
any values that are missing. For analysis, the dataset is divided proportionally classified as 20% test data and 80% train data.
into two separate groups: one for conducting training, and the 3) Feature Scaling: The E-commerce dataset had
other for conducting testing. During the subsequent phase, the characteristics that were assessed on different scales. We used
effectiveness of many different machine learning classifiers will the StandardScaler() function from the Python Sklearn module
be evaluated by making use of distinct datasets for training and to standardise the data values to a common format.
4
C. Classifiers we have used 3 supervised machine learning data. The training score indicates a minor drop when exposed
classifiers including Logistic Regression, K-Nearest Neighbours to more examples. This points out the fact that, it starts to
and Decision Tree to compare the performance and predict the generalize more well when more data are supplied often and
results. To understand the performance of the machine reduces overfitting. Similarly, introducing more data improved
learning models, we used the learning curves. It represents the the cross-validation score as well as the ability to generalise. It
relationship between the training score and the cross- has been shown that training instances beyond a certain point
validation score. Learning curves help to detect underfitting does not result in substantial Improvement in the
and overfitting. A model is determined as underfitting if the generalisation of the model.
training score is high and the validation score is low. Then it is The confusion matrix represents the performance of the
easy to assess the underlying data patterns. High training score logistic regression model in a multiclass classification problem.
and low validation score represents overfitting. Here the model It shows that the model has a strong ability to correctly classify
will be more complex. In some cases, both values will be close a class, as indicated by the high true positivity along the
and can be regarded as a Just right model. The accuracy of the diagonal for classes 2, 6, and 9. There are some patterns of
models and learning Curves are explained in the figures. misclassification, especially for class 0, which has been
disturbed with class 9 six times. The model performs well in a
D. Performance Evaluation wide range of classes. Intense colors in the figure correspond
to sample counts, with darker lines indicating higher rates.
The performance of the model is evaluated using a
Overall, the model exhibits good classification power with
confusion matrix. As we are dealing with a multi-class problem
room for improvement in distinguishing between some
un-normalised confusion matrix is adopted. The number of
groups.
instances that are correctly or incorrectly classified, broken
down by class, is clearly and understood with this un-
normalized confusion matrix. Each row in the matrix
corresponds to the occurrences of an actual class (true label),
and each column corresponds to the occurrences of a
predicted class (predicted label). When it comes to assessing
the effectiveness of classification models, the confusion matrix
is a very useful assessment tool.
IV. EXPERIMENTS AND RESULTS
In this study, we are evaluating the performance of various
machine learning classifiers such as Logistic Regression, K-
Nearest Neighbour and Decision Tree.
Figure 3
In the K-Nearest Neighbour model, the calculated Precision
of the prediction was 78.532%. The figure3 shows, that the
training score gradually decreases, indicating that the model
begins to generalize rather than memorize, reducing the risk of
overfitting. The cross-validation score initially improves with
more data, indicating that additional data helps the model
better capture underlying patterns and generalize to new,
unseen data. The cross-validation score appears to plateau as
the number of training samples continues to increase,
indicating a limitation on how much the model can learn from
new data. With more training samples, the training score and
cross-validation tend to converge and increase performance.
Figure 2
The confusion matrix shows the performance of the
classification model in 11 classes. The model exhibits high
In logistic regression model, the calculated precision of the accuracy for some classes, as evidenced by the large statistics
prediction was 88.34%. Evaluating the trends in the Learning on the diagonal, especially for class 6 with 359 correct
curve gives some valuable insights into the performance. In predictions however, there are notable cases of
figure2 the model was overfitting since there was a smaller misclassification since is incorrectly predicted in subject 0 as
quantity of data available, and it was simpler to memorize the subject 9. Overall, the model shows strong predictive power.
5
features and model parameters is needed and for increased
segmentation accuracy.
Future work should also investigate clustering methods that
combine different models to improve forecast performance
and robustness. Advanced clustering algorithms methods such
as k-means, hierarchical clustering and neural networks may
provide new segmentation techniques to capture nonlinear
patterns and interactions among customer characteristics.
Ultimately, Machine learning has various capabilities for
segmenting customers that may greatly improve the
understanding and targeting of diverse client groups. improved
customer segmentation aims to enable more personalized
marketing strategies, better resource utilization, and improved
customer satisfaction. The findings of this report should serve
Figure 4
as a foundation to develop a more targeted approach to
In Decision Tree model the calculated precision of prediction customer relationship management and to improve
was 84.53%. Figure 4 shows the training scores are consistently performance through data-driven insights.
higher at all training set sizes, indicating that the model fits the
training data well. However, the cross-validation score is very
low and shows some variability, indicating that the model does REFERENCES
not generalize to unseen data. Consistent differences between
[1] B. Cooil, L. Aksoy, and T. Keiningham, “Approaches to customer
training and cross-validation scores indicate overfitting; the segmentation,” Journal of Relationship Marketing, vol. 6, pp. 9–39, 01
decision tree is likely to have a large variance. The confusion 2007.
matrix shows the classification performance in 11 classes. In [2] J. Salminen, M. Mustak, M. Sufyan, and B. J. Jansen, “How can
particular, higher values in shape distortion for classes 2, 6, and algorithms help in segmenting users and customers? a systematic
review and research agenda for algorithmic customer segmentation,”
9 indicate stronger classification accuracy for these classes. Journal of Marketing Analytics, vol. 11, no. 4, pp. 677–692, 2023.
However, the model seems to mix class 0 with class 9 and class [3] B. Cooil, L. Aksoy, and T. L. Keiningham, “Approaches to customer
6 with class 7, as can be seen in the diagonal gap numbers. segmentation,” Journal of Relationship Marketing, vol. 6, no. 3-4, pp. 9–
Although most classes show a good number of correct 39, 2008.
classifications, misclassifications indicate potential areas for [4] R. Caruana and A. Niculescu-Mizil, “An empirical comparison of
supervised learning algorithms,” in Proceedings of the 23rd
improving the model. International Conference on Machine Learning, ICML ’06, (New York, NY,
USA), p. 161–168, Association for Computing Machinery, 2006.
[5] “Logistic Regression: Equation, Assumptions, Types, and Best Practices.”
V. SUMMARY AND OUTLOOK [Link]
is-logistic-regression/:˜:text=Practices
The primary objective of this experiment was to understand [6] R. Tiwari, M. K. Saxena, P. Mehendiratta, K. Vatsa, S. Srivastava, and R.
the capabilities of different machine learning algorithms in Gera, “Market segmentation using supervised and unsupervised
customer segmentation. machine learning can be cumulatively learning techniques for e-commerce applications,” Journal of Intelligent
used to implement targeted marketing based on customer & Fuzzy Systems, vol. 35, no. 5, pp. 5353–5363, 2018.
[7] O. Kramer and O. Kramer, “K-nearest neighbors,” Dimensionality
segmentation. Using techniques including decision trees, k- reduction with unsupervised nearest neighbors, pp. 13–23, 2013.
Nearest Neighbours (k-NN), and logistic regression, machine [8] A. Shi, C. Lim, and S. Ang, Customer Churn Analysis for Live Stream E-
learning is an effective method for identifying customer Commerce Platforms by Using Decision Tree Method, pp. 168–178.
clusters based on interaction policy, demographics, and 10 2023.
[9] B. Charbuty and A. Abdulazeez, “Classification based on decision tree
purchasing behaviour. algorithm for machine learning,” Journal of Applied Science and
Logistic regression provided a robust starting point capable Technology Trends, vol. 2, no. 01, pp. 20–28, 2021.
of handling linear relationships. The classifier outstands other [10] L. Frank, “Applying machine learning algorithms to enhance
models with a high accuracy of Prediction which is 88.34%. personalized recommendations in salesforce customer engagement
solutions,” 02 2024.
while k-NN provided a more refined approach through the use
of similarity decisions Decision trees revealed hierarchical
patterns in consumer decision making. However, each model
exhibited various limitations, such as the possibility of
overfitting decision trees and the sensitivity of k-NN to the
choice of k and distance measures Confusion matrices and
learning curves showed that although some receptor segments
were clearly described by the models, others were often
misclassified These findings suggest that further adjustment of