Research Methods and Techniques - Homework

Name: Pedro Eduardo Craveiro Silveira

Registration N. : 19631200

As my homework for RMT, I decided to do a Clustering to provide a Customer segmentation for a E-commerce platform. The datas collected from Kaggle platform offered detailed breakdown of 350 clientes’ interactions and transactions. The goal of this clustering is to identify and understand different groups of customers, providing the e-commerce platform with information that can help retaining customers and improving customers satisfaction levels.

I started the process importing my dataset, called “E-commerce”. Set the parameters according to those present on my data and named the columns present on it. Next, I used the function head to have a preview of the first 6 rows.

mydata <- read.csv("~/Desktop/Pedro/RMT/Homework/E-commerce.csv", header = TRUE, sep = ";", dec = ".")

colnames(mydata) <- c("ID", "Gender", "Age", "TotalSpend", "NumItems", "Rating", "LastBuy")


head(mydata)
##    ID Gender Age TotalSpend NumItems Rating LastBuy
## 1 101 Female  29     1120.2       14    4.6      25
## 2 102   Male  34      780.5       11    4.1      18
## 3 103   Male  43      510.7        9    3.4      42
## 4 104   Male  30     1480.3       19    4.7      12
## 5 105   Male  27      720.4       13    4.0      55
## 6 106   Male  37      440.8        8    3.1      22

Description of dataset:

• ID: Identificator Variable.

• Gender: (Female: F, Male:M).

• Age.

• TotalSpend: Total Expenditure on the platform in dollars ($)

• NumItems: Total of products purchased by each customer.

• Rating: Score given by customers (1 - 5)

• Lastbuy: Number of days since customer’s last purchase.

As my next step, I applied the ‘factor’ function to ‘Gender’, transforming the categorical variable into factor, to facilitate the subsequent use of this data.

mydata$GenderFactor <- factor(mydata$Gender,
                              levels = c("Female","Male"),
                              labels = c("F", "M"))

Here, I used “summary”, since this function gives me a brief statistical of each one of my variables.That allows me to find any major discrepancies on my data.

summary(mydata)
##        ID           Gender               Age         TotalSpend    
##  Min.   :101.0   Length:350         Min.   :26.0   Min.   : 410.8  
##  1st Qu.:188.2   Class :character   1st Qu.:30.0   1st Qu.: 501.9  
##  Median :275.5   Mode  :character   Median :32.5   Median : 775.2  
##  Mean   :275.5                      Mean   :33.6   Mean   : 845.4  
##  3rd Qu.:362.8                      3rd Qu.:37.0   3rd Qu.:1160.6  
##  Max.   :450.0                      Max.   :43.0   Max.   :1520.1  
##     NumItems        Rating         LastBuy      GenderFactor
##  Min.   : 7.0   Min.   :3.000   Min.   : 9.00   F:163       
##  1st Qu.: 9.0   1st Qu.:3.500   1st Qu.:15.00   M:187       
##  Median :12.0   Median :4.100   Median :23.00               
##  Mean   :12.6   Mean   :4.019   Mean   :26.59               
##  3rd Qu.:15.0   3rd Qu.:4.500   3rd Qu.:38.00               
##  Max.   :21.0   Max.   :4.900   Max.   :63.00

I am going to use “Age”, “TotalSpend”, “Rating” and “LastBuy” as my clustering variables. And, since I am doing a clustering, It is important to standardize my variables, so this way each variable can equally contribute to the results.

mydata$Age_z <- scale(mydata$Age)
mydata$TotalSpend_z <-  scale(mydata$TotalSpend)
mydata$Rating_z <- scale(mydata$Rating)
mydata$LastBuy_z <- scale(mydata$LastBuy)

Next we “rcorr” to calculate pearson correlation coefficients among all the cluster variables. Here we don’t want to find excessive correlation between variables, because too correlated variable will bring too similar information, and we don’t want that. Some variables will have higher correlation, like “TotalSpend_z” x “Rating_z”, but mostly they will be either “Weak” correlation (0.1 - 0.3) or “Semi strong” correlation (0.3 - 0.7).

library(Hmisc)
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
rcorr(as.matrix(mydata[, c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z")]),
      type= "pearson")
##              Age_z TotalSpend_z Rating_z LastBuy_z
## Age_z         1.00        -0.68    -0.72      0.17
## TotalSpend_z -0.68         1.00     0.94     -0.54
## Rating_z     -0.72         0.94     1.00     -0.43
## LastBuy_z     0.17        -0.54    -0.43      1.00
## 
## n= 350 
## 
## 
## P
##              Age_z  TotalSpend_z Rating_z LastBuy_z
## Age_z               0.0000       0.0000   0.0015   
## TotalSpend_z 0.0000              0.0000   0.0000   
## Rating_z     0.0000 0.0000                0.0000   
## LastBuy_z    0.0015 0.0000       0.0000

To search for outliers, one of the methods is to utilize “Dissimilarity”. This is a measure applied to calculate the distance of a unit to the center of the data, showing us the units that are unusually distant to the center in comparison to the rest of the units. On my research I found one Unit (ID: 440) that was outstanding a little, but since it wasn’t such a big difference, I decided to keep the unit on the data.

mydata$Dissimilarity <- sqrt(mydata$Age_z^2 + mydata$TotalSpend_z^2 + mydata$Rating_z^2 + mydata$LastBuy_z^2)
head(mydata[order(-mydata$Dissimilarity),], 10)
##      ID Gender Age TotalSpend NumItems Rating LastBuy GenderFactor     Age_z
## 340 440   Male  27      710.4       13    4.1      63            M -1.354404
## 328 428   Male  27      710.4       13    4.1      62            M -1.354404
## 350 450 Female  43      515.7       10    3.3      49            F  1.930422
## 338 438   Male  43      505.7       10    3.3      48            M  1.930422
## 316 416   Male  27      710.4       13    4.1      61            M -1.354404
## 46  146 Female  28     1490.1       21    4.9       9            F -1.149102
## 76  176   Male  28     1490.1       21    4.9       9            M -1.149102
## 106 206   Male  28     1490.1       21    4.9       9            M -1.149102
## 136 236   Male  28     1490.1       21    4.9       9            M -1.149102
## 148 248 Female  28     1490.1       21    4.9       9            F -1.149102
##     TotalSpend_z   Rating_z LastBuy_z Dissimilarity
## 340   -0.3727872  0.1392795  2.709020      3.054761
## 328   -0.3727872  0.1392795  2.634620      2.988980
## 350   -0.9105349 -1.2387512  1.667416      2.978319
## 338   -0.9381542 -1.2387512  1.593016      2.945991
## 316   -0.3727872  0.1392795  2.560219      2.923611
## 46     1.7806897  1.5173102 -1.308594      2.916495
## 76     1.7806897  1.5173102 -1.308594      2.916495
## 106    1.7806897  1.5173102 -1.308594      2.916495
## 136    1.7806897  1.5173102 -1.308594      2.916495
## 148    1.7806897  1.5173102 -1.308594      2.916495

Now, we will create another graphic called the ‘dissimilarity matrix.’ This graphic will display distances between pairs of units using colors and will inform us whether cluster groups are suitable for our dataset. Based on colors, if the badaset is suitable, we will be able to see possible clusters on the main diagonal of the image.

Since we are grouping units, not variables, we need to calculate distances between objects. One of the main methods to achieve this is by using ‘Euclidean distances.’ For this graphic, we will use the algorithm ‘Ward,’ which employs square Euclidean distance.

Also, in the bottom part of the result, R will provide us with the ‘Hopkins Statistics.’ This parameter is measured between 0 and 1, and if ‘Hopkins stats’ is greater than ‘0.5,’ it means that our dataset is suitable for clustering.

library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
distance <- get_dist(mydata[c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z")],
                    method= "euclidian")

distance2 <- distance^2

fviz_dist(distance2)

get_clust_tendency(mydata[c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z")],
                   n= nrow(mydata) - 1,
                   graph= FALSE)
## $hopkins_stat
## [1] 0.92225
## 
## $plot
## NULL

Our result shows “Hopkins Stats” is 0.92225, a number very close to 1, meaning that the units have a great potential for clustering.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
## 
##     src, summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
WARD <- mydata[c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z")] %>%
  
  get_dist(method= "euclidean") %>%
  hclust(method= "ward.D2")

WARD
## 
## Call:
## hclust(d = ., method = "ward.D2")
## 
## Cluster method   : ward.D2 
## Distance         : euclidean 
## Number of objects: 350

After that, we will start the first part of our actual clustering, setting R to create the graphic called “Dendrogram”. This graphic on a tree-like structure helps visualizing the division of the cluster groups, on the “Hierarchical clustering” process.

library(factoextra)
fviz_dend(WARD)
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## ℹ The deprecated feature was likely used in the factoextra package.
##   Please report the issue at <https://github.com/kassambara/factoextra/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Based on the image provided by the dendrogram, I decided to cluster the units into 6 different groups. I tried several options, but some with fewer groups would result in clusters that were too heterogeneous, while lower cuts would lead to too many groups, defeating the purpose of clustering. I understand that we are not supposed to make cuts close to the horizontals, but in this case, I was close to at least one of them, with the intent to keep the groups as homogeneous as possible.

fviz_dend(WARD,
          k = 6,
          cex = 0.5,
          palette = "jama",
          color_labels_by_k = TRUE,
          rect = TRUE)

mydata$ClusterWard <- cutree(WARD,
                             k = 6)

head(mydata)
##    ID Gender Age TotalSpend NumItems Rating LastBuy GenderFactor       Age_z
## 1 101 Female  29     1120.2       14    4.6      25            F -0.94380087
## 2 102   Male  34      780.5       11    4.1      18            M  0.08270722
## 3 103   Male  43      510.7        9    3.4      42            M  1.93042180
## 4 104   Male  30     1480.3       19    4.7      12            M -0.73849925
## 5 105   Male  27      720.4       13    4.0      55            M -1.35440411
## 6 106   Male  37      440.8        8    3.1      22            M  0.69861208
##   TotalSpend_z    Rating_z  LastBuy_z Dissimilarity ClusterWard
## 1    0.7590518  1.00054872 -0.1181901     1.5754321           1
## 2   -0.1791759  0.13927953 -0.6389920     0.6831208           2
## 3   -0.9243446 -1.06649734  1.1466143     2.6519959           3
## 4    1.7536228  1.17280256 -1.0853935     2.4847774           4
## 5   -0.3451679 -0.03297431  2.1138177     2.5343370           5
## 6   -1.1174035 -1.58325885 -0.3413909     2.0880387           6

In this step, R will calculate the location of the ‘Initial Leaders,’ which are the units serving as the initial centers for the subsequent clustering process. Each part of the number functions as a ‘coordinate’ for the unit within each of the cluster variables.

Initial_leaders <- aggregate(mydata[, c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z")],
                             by = list(mydata$ClusterWard),
                             FUN = mean)

Initial_leaders
##   Group.1      Age_z TotalSpend_z   Rating_z  LastBuy_z
## 1       1 -0.5923523    0.8828845  0.9042034 -0.1484546
## 2       2  0.1070650   -0.1101698  0.2648205 -0.8420164
## 3       3  1.7286599   -0.9543401 -0.9684908  1.0324484
## 4       4 -0.9190231    1.6969270  1.3599059 -1.1469661
## 5       5 -0.9544199   -0.4280543 -0.1577098  1.4070152
## 6       6  0.6384375   -1.1005700 -1.4228846 -0.2849493

On the next step, we will specify the location of the initial leaders and indicate to R the number of cluster groups we desire. This stage of the process is referred to as ‘K-Means Clustering.’ Since we are incorporating both methods, it is known as ‘Hierarchical K-Means.’

K-Means will provide us with several essential parameters for our clustering. Apart from informing us about the location of our final leaders, which may or may not be the same as the initial leaders. In our case, the dataset exhibited a strong clustering tendency, and we observed no changes in that aspect.

K_MEANS <- hkmeans(mydata[c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z")],
                   k = 6,
                   hc.metric = "euclidean",
                   hc.method = "ward.D2")

K_MEANS
## Hierarchical K-means clustering with 6 clusters of sizes 59, 59, 58, 58, 58, 58
## 
## Cluster means:
##        Age_z TotalSpend_z   Rating_z  LastBuy_z
## 1 -0.5923523    0.8828845  0.9042034 -0.1484546
## 2  0.1070650   -0.1101698  0.2648205 -0.8420164
## 3  1.7286599   -0.9543401 -0.9684908  1.0324484
## 4 -0.9190231    1.6969270  1.3599059 -1.1469661
## 5 -0.9544199   -0.4280543 -0.1577098  1.4070152
## 6  0.6384375   -1.1005700 -1.4228846 -0.2849493
## 
## Clustering vector:
##   [1] 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1
##  [38] 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2
##  [75] 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3
## [112] 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4
## [149] 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5
## [186] 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1
## [223] 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2
## [260] 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3
## [297] 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4
## [334] 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3
## 
## Within cluster sum of squares by cluster:
## [1] 10.095327  7.453354  8.848881  7.187079 51.794312  9.340248
##  (between_SS / total_SS =  93.2 %)
## 
## Available components:
## 
##  [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
##  [6] "betweenss"    "size"         "iter"         "ifault"       "data"        
## [11] "hclust"

Above, we were also informed of the sum of squares within groups. For these distances, lower values are preferable. R also provided us with ‘between_SS / total_SS,’ indicating how much of the total variability in the data is explained by the clustering structure. In our case, 93.2% of the variability is explained, a substantial amount.

fviz_cluster(K_MEANS,
             palette = "jama",
             repel = FALSE,
             ggtheme = theme_classic())

In the image above, we can observe the Cluster Plot, a two-dimensional interpretation of the multidimensional positions of the clusters. Units combine with others that are ‘geographically’ located closer to the centroids, forming clusters. As mentioned earlier, I chose to utilize a 6-part clustering to ensure homogeneity within groups. However, further splitting the units into smaller groups could render the entire clustering process unnecessary, defeating its purpose.

mydata$ClusterK_Means <- K_MEANS$cluster 
  head(mydata[c("ID", "ClusterWard", "ClusterK_Means")])
##    ID ClusterWard ClusterK_Means
## 1 101           1              1
## 2 102           2              2
## 3 103           3              3
## 4 104           4              4
## 5 105           5              5
## 6 106           6              6

In this section, we can observe that, throughout the process, the units did not move from one cluster group to another. In other words, the units were not reclassified during the K_Means part of the clustering, they remained in the same groups as they had been previously classified during the hierarchical classification.

table(mydata$ClusterWard)
## 
##  1  2  3  4  5  6 
## 59 59 58 58 58 58
table(mydata$ClusterK_Means)
## 
##  1  2  3  4  5  6 
## 59 59 58 58 58 58
table(mydata$ClusterWard, mydata$ClusterK_Means)
##    
##      1  2  3  4  5  6
##   1 59  0  0  0  0  0
##   2  0 59  0  0  0  0
##   3  0  0 58  0  0  0
##   4  0  0  0 58  0  0
##   5  0  0  0  0 58  0
##   6  0  0  0  0  0 58

The locations below indicate the positions of the Final Leaders. These locations will now be used to generate a profiling graphic, allowing us to have a better understanding of the behavior of each cluster group based on the mean values.

centroids <- K_MEANS$centers
centroids
##        Age_z TotalSpend_z   Rating_z  LastBuy_z
## 1 -0.5923523    0.8828845  0.9042034 -0.1484546
## 2  0.1070650   -0.1101698  0.2648205 -0.8420164
## 3  1.7286599   -0.9543401 -0.9684908  1.0324484
## 4 -0.9190231    1.6969270  1.3599059 -1.1469661
## 5 -0.9544199   -0.4280543 -0.1577098  1.4070152
## 6  0.6384375   -1.1005700 -1.4228846 -0.2849493
library(ggplot2)
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.3.2
Figure <- as.data.frame(centroids)
Figure$id <- 1:nrow(Figure)
Figure <- pivot_longer(Figure, col = c(Age_z, TotalSpend_z, Rating_z, LastBuy_z))

Figure$Groups <- factor(Figure$id,
                        levels = c(1,2,3,4,5,6),
                        labels = c("1","2","3","4","5","6"))

Figure$nameFactor <- factor(Figure$name,
                        levels = c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z"),
                        labels = c("Age_z", "TotalSpend_z", "Rating_z", "LastBuy_z"))

ggplot(Figure, aes(x = nameFactor, y = value)) +
  geom_hline(yintercept = 0) +
  theme_bw() +
  geom_point(aes(shape = Groups, col = Groups), size = 3) +
  geom_line(aes(group = id), linewidth = 1) +
  ylab("Averages") +
  xlab("cluster variables") +
  ylim(-2, 2)

As we can observe, each group is represented by one line and symbol with a specific color. This allows us to analyze the behavior of each of our cluster groups for every cluster variable. The variables are plotted along the ‘X’ axis of the graph, while the ‘Y’ axis displays their arithmetic means for each variable. This visualization provides a clearer perception of the characteristics of each segment, which will be further explained later.

Next, I am going to perform ANOVA to check if all cluster variables distinguish between the groups. In this situation, the null hypothesis (H0) and alternative hypothesis (H1) are:

H0: µVj,G1 = µVj,G2 = µVj,G3 = µVj, G4

H1: At least one µ for Vj is different.

We will perform this analysis for all our cluster variables. If we can reject H0, it will indicate that these variables actually contribute to cluster formation.

As we observed before on the profiling graph and now confirmed with the ANOVAs, given that we verified all p-values < 0.001, we can affirm that these variables contribute to the clustering process.

fit <- aov(cbind(Age_z, TotalSpend_z, Rating_z, LastBuy_z) ~ as.factor(ClusterK_Means),
data = mydata)
summary(fit)
##  Response 1 :
##                            Df Sum Sq Mean Sq F value    Pr(>F)    
## as.factor(ClusterK_Means)   5 320.16  64.032  763.73 < 2.2e-16 ***
## Residuals                 344  28.84   0.084                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##  Response 2 :
##                            Df Sum Sq Mean Sq F value    Pr(>F)    
## as.factor(ClusterK_Means)   5 347.42  69.485   15174 < 2.2e-16 ***
## Residuals                 344   1.58   0.005                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##  Response 3 :
##                            Df Sum Sq Mean Sq F value    Pr(>F)    
## as.factor(ClusterK_Means)   5 332.91  66.582  1423.4 < 2.2e-16 ***
## Residuals                 344  16.09   0.047                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##  Response 4 :
##                            Df  Sum Sq Mean Sq F value    Pr(>F)    
## as.factor(ClusterK_Means)   5 300.788  60.158  429.24 < 2.2e-16 ***
## Residuals                 344  48.212   0.140                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

For the validation, I will employ the ‘Criterion Validity’ approach. In this approach, I will use variables that were not utilized during the clustering process to check for mean differences. This validation can be conducted using either ANOVA for numerical variables or Chi-Square statistics for categorical variables.

I will begin by performing ANOVA for the numerical variable ‘NumItems’ and subsequently conduct Chi-Square statistics for the categorical variable ‘GenderFactor.’

aggregate(mydata$NumItems,
          by = list(mydata$ClusterK_Means),
          FUN = "mean")
##   Group.1         x
## 1       1 15.271186
## 2       2 11.677966
## 3       3  9.413793
## 4       4 20.000000
## 5       5 11.637931
## 6       6  7.568966
fit <- aov(NumItems ~ as.factor(ClusterK_Means),
           data = mydata)

summary(fit)
##                            Df Sum Sq Mean Sq F value Pr(>F)    
## as.factor(ClusterK_Means)   5   5758  1151.6    1466 <2e-16 ***
## Residuals                 344    270     0.8                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Here we tested ANOVA for the variable “NumItems” and can reject null hypothesis (p-value < 0.001), showing that at least one µ among the cluster groups, for that variable is different. Here we can check, for instance, the lowest mean for Number products bought at the platform belongs to cluster group 6. This data aligns with our profiling information, as in that graphic we found out that segment 6 had also the lowest “TotalSpend” mean and the lowest “Rating” mean among all clusters.

chisq_results <- chisq.test(mydata$GenderFactor, as.factor(mydata$ClusterK_Means))

chisq_results
## 
##  Pearson's Chi-squared test
## 
## data:  mydata$GenderFactor and as.factor(mydata$ClusterK_Means)
## X-squared = 12.417, df = 5, p-value = 0.0295

As previously mentioned, I also conducted a Pearson’s Chi-Square test with the variable ‘GenderFactor,’ where the hypotheses are:

H0: There is no association between variables.

H1: There is association between variables.

In this case, we can reject the null hypothesis (p-value = 0.03). Additionally, all expected frequencies are greater than 5. Further analysis of standardized residuals did not observe statistically significant deviations, as the highest deviation is 1.92 in group 5.

addmargins(chisq_results$observed)
##                    
## mydata$GenderFactor   1   2   3   4   5   6 Sum
##                 F    26  21  31  25  37  23 163
##                 M    33  38  27  33  21  35 187
##                 Sum  59  59  58  58  58  58 350
round(chisq_results$expected, 2)
##                    
## mydata$GenderFactor     1     2     3     4     5     6
##                   F 27.48 27.48 27.01 27.01 27.01 27.01
##                   M 31.52 31.52 30.99 30.99 30.99 30.99
round(chisq_results$res, 2)
##                    
## mydata$GenderFactor     1     2     3     4     5     6
##                   F -0.28 -1.24  0.77 -0.39  1.92 -0.77
##                   M  0.26  1.15 -0.72  0.36 -1.79  0.72
library(effectsize)

effectsize::cramers_v(mydata$GenderFactor, mydata$ClusterK_Means)
## Cramer's V (adj.) |       95% CI
## --------------------------------
## 0.15              | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].

In assessing the effect size, the Cramer’s V statistic yielded a result of ‘0.15,’ classifying it as ’Small.

CONCLUSIONS

During this whole process, one of the hardest parts was finding a dataset that could meet all the criteria necessary for this clustering. This process is probably not a struggle for a more experienced person, but for a first-timer, it demanded quite a good amount of time. The idea was to present a clustering that would provide interesting insights about the customers of this specific e-commerce platform. Throughout the process, I enjoyed learning how to code in practice and obtaining the expected results at each part of it. However, I must confess that the final conclusions are apparently not enlightening, even though they can be interesting in some aspects. Below, I am going to describe the characteristics for each cluster group.

Group 1 contains 16.9% of all units, below the average on the variable ‘Age.’ This group has the second-highest means for the variables ‘TotalSpend’ and ‘Rating’ and stays on the average for the variable ‘LastBuy.’ Their average number of products purchased is 15.3.

Group 2 also contains the same number of units, representing 16.9% of the total. This segment stays very close to the averages for most variables, including ‘Age,’ ‘TotalSpend,’ and ‘Rating,’ being significantly below the average only for ‘LastBuy.’ The number of males and females for this group is as expected.

Group 3 contains 16.7% of all units and is characterized by the highest average on ‘Age,’ the second-lowest for ‘TotalSpend’ and ‘Rating,’ and also by the second-highest average on ‘LastBuy.’ The findings in this group align with expectations, considering the e-commerce context.

Group 4, representing 16.7% of our total units, takes an opposite direction. This group has the lowest ‘Age’ average, alongside with Group 5, and presents the highest averages on ‘TotalSpend’ and ‘Rating,’ along with the lowest time since their last purchase on average. This group also aligns with our expectations regarding their engagement with e-commerce methods.

Group 5 could represent a point of attention for the platform. It constitutes 16.7% of all units, similar to the previous group. As mentioned earlier, this group is, on average, the youngest. However, they are below the average on the variables ‘TotalSpend’ and ‘Rating,’ while having a higher average on ‘LastBuy.’ Some demographic data could possibly explain this behavior, such as employment status. For now, it represents a point of attention, and the platform could seek higher engagement among these units.

Group 6, comprising 16.7% of units, has the lowest ‘Rating’ average, which reflects on their low average on ‘TotalSpend.’ Although they are fairly close to the average in terms of ‘Age,’ they express dissatisfaction with the services/products supplied by the platform.This segment has the lowest average on ‘NumItems’ (7.6 products). This group should also be a point of attention for the business, attempting to understand why these units have such a negative perception of the platform and working to retain clients while increasing their expenditures on the platform.