Research Q-n: How do demographic and behavioral factors influence customer segmentation and satisfaction levels on an e-commerce platform.

Justification: The clustering analysis based on standardized variables (Total Spend, Item Purchased, and Rating) has resulted in the identification of four distinct customer groups. Each group exhibits unique demographic characteristics, such as age, gender, location, and membership status, along with distinct behavioral patterns in terms of spending, purchasing items, and providing ratings. To gain a deeper understanding of these clusters and their implications for customer satisfaction, further investigation is warranted.

The research question aims to explore the relationships between demographic attributes, behavioral patterns, and satisfaction levels within the identified customer segments. By understanding how these factors contribute to the formation of customer groups and influence satisfaction, businesses can tailor their strategies to better meet the needs of each segment, ultimately enhancing the overall customer experience on the e-commerce platform.

Analyzing the factors that differentiate these customer segments, such as age, gender, location, and membership status, will provide valuable insights into the diverse preferences and behaviors exhibited by different groups of customers. Additionally, investigating how these segments differ in terms of spending, item purchases, and rating assignments will contribute to a comprehensive understanding of customer satisfaction dynamics within the e-commerce platform.

#importing data
mydata <- read_csv("~/Desktop/E-commerce Customer Behavior .csv")
## Rows: 350 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Gender, City, Membership Type, Satisfaction Level
## dbl (6): Customer ID, Age, Total Spend, Items Purchased, Average Rating, Day...
## lgl (1): Discount Applied
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#reviewing first 1o rows
head(mydata)
## # A tibble: 6 Ă— 11
##   `Customer ID` Gender   Age City          `Membership Type` `Total Spend`
##           <dbl> <chr>  <dbl> <chr>         <chr>                     <dbl>
## 1           101 Female    29 New York      Gold                      1120.
## 2           102 Male      34 Los Angeles   Silver                     780.
## 3           103 Female    43 Chicago       Bronze                     511.
## 4           104 Male      30 San Francisco Gold                      1480.
## 5           105 Male      27 Miami         Silver                     720.
## 6           106 Female    37 Houston       Bronze                     441.
## # ℹ 5 more variables: `Items Purchased` <dbl>, `Average Rating` <dbl>,
## #   `Discount Applied` <lgl>, `Days Since Last Purchase` <dbl>,
## #   `Satisfaction Level` <chr>

Description:

#Use the describe() function to obtain a comprehensive statistical summary
describe (mydata)
## mydata 
## 
##  11  Variables      350  Observations
## --------------------------------------------------------------------------------
## Customer ID 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      350        0      350        1    275.5      117    118.5    135.9 
##      .25      .50      .75      .90      .95 
##    188.2    275.5    362.8    415.1    432.6 
## 
## lowest : 101 102 103 104 105, highest: 446 447 448 449 450
## --------------------------------------------------------------------------------
## Gender 
##        n  missing distinct 
##      350        0        2 
##                         
## Value      Female   Male
## Frequency     175    175
## Proportion    0.5    0.5
## --------------------------------------------------------------------------------
## Age 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      350        0       16    0.993     33.6    5.516     27.0     28.0 
##      .25      .50      .75      .90      .95 
##     30.0     32.5     37.0     41.0     43.0 
##                                                                             
## Value         26    27    28    29    30    31    32    33    34    35    36
## Frequency      9    25    24    11    48    25    33    10    24    25    25
## Proportion 0.026 0.071 0.069 0.031 0.137 0.071 0.094 0.029 0.069 0.071 0.071
##                                         
## Value         37    38    41    42    43
## Frequency     24     9    24     9    25
## Proportion 0.069 0.026 0.069 0.026 0.071
## 
## For the frequency table, variable is rounded to the nearest 0
## --------------------------------------------------------------------------------
## City 
##        n  missing distinct 
##      350        0        6 
##                                                                   
## Value            Chicago       Houston   Los Angeles         Miami
## Frequency             58            58            59            58
## Proportion         0.166         0.166         0.169         0.166
##                                       
## Value           New York San Francisco
## Frequency             59            58
## Proportion         0.169         0.166
## --------------------------------------------------------------------------------
## Membership Type 
##        n  missing distinct 
##      350        0        3 
##                                
## Value      Bronze   Gold Silver
## Frequency     116    117    117
## Proportion  0.331  0.334  0.334
## --------------------------------------------------------------------------------
## Total Spend 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      350        0       76    0.999    845.4    403.4    430.8    450.8 
##      .25      .50      .75      .90      .95 
##    502.0    775.2   1160.6   1460.5   1490.1 
## 
## lowest : 410.8  420.8  430.5  430.8  440.5 , highest: 1480.1 1480.3 1490.1 1500.1 1520.1
## --------------------------------------------------------------------------------
## Items Purchased 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      350        0       15    0.992     12.6    4.652        7        8 
##      .25      .50      .75      .90      .95 
##        9       12       15       20       21 
##                                                                             
## Value          7     8     9    10    11    12    13    14    15    16    17
## Frequency     25    33    34    47    28    33    32    11    24    24     1
## Proportion 0.071 0.094 0.097 0.134 0.080 0.094 0.091 0.031 0.069 0.069 0.003
##                                   
## Value         18    19    20    21
## Frequency      9     6    19    24
## Proportion 0.026 0.017 0.054 0.069
## 
## For the frequency table, variable is rounded to the nearest 0
## --------------------------------------------------------------------------------
## Average Rating 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      350        0       20    0.996    4.019   0.6688      3.1      3.2 
##      .25      .50      .75      .90      .95 
##      3.5      4.1      4.5      4.8      4.9 
##                                                                             
## Value        3.0   3.1   3.2   3.3   3.4   3.5   3.6   3.7   3.8   3.9   4.0
## Frequency     12    17    10    25    19     9    24     1    24     8    18
## Proportion 0.034 0.049 0.029 0.071 0.054 0.026 0.069 0.003 0.069 0.023 0.051
##                                                                 
## Value        4.1   4.2   4.3   4.4   4.5   4.6   4.7   4.8   4.9
## Frequency     34    12    20     8    31    11    22    21    24
## Proportion 0.097 0.034 0.057 0.023 0.089 0.031 0.063 0.060 0.069
## 
## For the frequency table, variable is rounded to the nearest 0
## --------------------------------------------------------------------------------
## Discount Applied 
##        n  missing distinct 
##      350        0        2 
##                       
## Value      FALSE  TRUE
## Frequency    175   175
## Proportion   0.5   0.5
## --------------------------------------------------------------------------------
## Days Since Last Purchase 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      350        0       54    0.999    26.59    15.08    10.00    12.00 
##      .25      .50      .75      .90      .95 
##    15.00    23.00    38.00    47.00    53.55 
## 
## lowest :  9 10 11 12 13, highest: 59 60 61 62 63
## --------------------------------------------------------------------------------
## Satisfaction Level 
##        n  missing distinct 
##      348        2        3 
##                                               
## Value          Neutral   Satisfied Unsatisfied
## Frequency          107         125         116
## Proportion       0.307       0.359       0.333
## --------------------------------------------------------------------------------

Explanation of ststistical summary (only relevant variables):

Age: The age distribution is slightly right-skewed with a mean of 33.60 and a median of 32.5. The range spans from 17 to 43, indicating variability. The standard deviation of 4.87 implies that approximately 68% of the data falls within the range of 28.73 to 38.47.

Total Spend: The total spend distribution has a mean of 845.38 and meadian of 775.06. With a substantial standard deviation of 362.06, there is notable variability in customer spending. Approximately 68% of the data falls within the range of 483.32 to 1207.44, highlighting the spread of spending patterns among customers.

Items Purchased: The average number of items purchased is 12.60 and median 12.0, with a moderate standard deviation of 4.16. This indicates a degree of variability. The distribution of items purchased spans from 8.44 to 16.76, demonstrating the range where approximately 68% of the data lies.

Average Rating: The average rating is 4.02 and median is 4.1, with a relatively small standard deviation of 0.58. This suggests a degree of consistency in customer ratings. The distribution spans from 3.44 to 4.60, capturing the range where about 68% of the data falls.

Days Since Last Purchase: On average customers make a purchase approximately every 26.59 days, with a standard deviation of 13.44. This indicates a degree of variability in the frequency of customer transactions. The distribution spans from 13.15 (if down rounded 13 days) to 40.03 (if down rounded 40 days) days, showing the range where approximately 68% of the data lies.

#rename column
colnames(mydata)[7]="Items_Purchased"
colnames(mydata)[1]="ID"
colnames(mydata)[6]="Total_Spend"
colnames(mydata)[5]="Membership"
colnames(mydata)[8]="Rating"
str(mydata)
## spc_tbl_ [350 Ă— 11] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ID                      : num [1:350] 101 102 103 104 105 106 107 108 109 110 ...
##  $ Gender                  : chr [1:350] "Female" "Male" "Female" "Male" ...
##  $ Age                     : num [1:350] 29 34 43 30 27 37 31 35 41 28 ...
##  $ City                    : chr [1:350] "New York" "Los Angeles" "Chicago" "San Francisco" ...
##  $ Membership              : chr [1:350] "Gold" "Silver" "Bronze" "Gold" ...
##  $ Total_Spend             : num [1:350] 1120 780 511 1480 720 ...
##  $ Items_Purchased         : num [1:350] 14 11 9 19 13 8 15 12 10 21 ...
##  $ Rating                  : num [1:350] 4.6 4.1 3.4 4.7 4 3.1 4.5 4.2 3.6 4.8 ...
##  $ Discount Applied        : logi [1:350] TRUE FALSE TRUE FALSE TRUE FALSE ...
##  $ Days Since Last Purchase: num [1:350] 25 18 42 12 55 22 28 14 40 9 ...
##  $ Satisfaction Level      : chr [1:350] "Satisfied" "Neutral" "Unsatisfied" "Satisfied" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   `Customer ID` = col_double(),
##   ..   Gender = col_character(),
##   ..   Age = col_double(),
##   ..   City = col_character(),
##   ..   `Membership Type` = col_character(),
##   ..   `Total Spend` = col_double(),
##   ..   `Items Purchased` = col_double(),
##   ..   `Average Rating` = col_double(),
##   ..   `Discount Applied` = col_logical(),
##   ..   `Days Since Last Purchase` = col_double(),
##   ..   `Satisfaction Level` = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
mydata$Total_Spend_z <- scale (mydata$Total_Spend)
mydata$Rating_z <- scale (mydata$Rating)
mydata$Items_Purchased_z <- scale (mydata$Items_Purchased)
mydata$Dissimilarity = sqrt(mydata$Total_Spend_z^2 + mydata$Rating_z^2 + mydata$Items_Purchased_z^2 ) #Finding outliers
head(mydata[order(-mydata$Dissimilarity), ], 5) #Finding top 5 objects with highest value of dissimilarity
## # A tibble: 5 Ă— 15
##      ID Gender   Age City          Membership Total_Spend Items_Purchased Rating
##   <dbl> <chr>  <dbl> <chr>         <chr>            <dbl>           <dbl>  <dbl>
## 1   128 Male      28 San Francisco Gold             1500.              21    4.9
## 2   158 Male      28 San Francisco Gold             1500.              21    4.9
## 3   188 Male      28 San Francisco Gold             1500.              21    4.9
## 4   218 Male      28 San Francisco Gold             1500.              21    4.9
## 5   260 Male      28 San Francisco Gold             1500.              21    4.9
## # ℹ 7 more variables: `Discount Applied` <lgl>,
## #   `Days Since Last Purchase` <dbl>, `Satisfaction Level` <chr>,
## #   Total_Spend_z <dbl[,1]>, Rating_z <dbl[,1]>, Items_Purchased_z <dbl[,1]>,
## #   Dissimilarity <dbl[,1]>

Results: No outliers were detected

round(head(mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")], 3), 2)
## # A tibble: 3 Ă— 3
##   Total_Spend_z[,1] Rating_z[,1] Items_Purchased_z[,1]
##               <dbl>        <dbl>                 <dbl>
## 1              0.76         1                     0.34
## 2             -0.18         0.14                 -0.38
## 3             -0.92        -1.07                 -0.87
#Finding Eudlidean distances, based on 6 Cluster variables, then saving them into object Distances

Distances <- get_dist(mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")], 
                      method = "euclidian")

fviz_dist(Distances) #We show the distance matrix

Result: We have 4 distinct groups

get_clust_tendency(mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")], #Hopkins statistics
                   n = nrow(mydata) - 1,
                   graph = FALSE) 
## $hopkins_stat
## [1] 0.9470231
## 
## $plot
## NULL

Result: It can be seen that the data set is highly clusterable (the H value = 0.9470231 which is far above the threshold 0.5)

#hierarchical clustering
WARD <- mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")] %>% #Selecting variables
  get_dist(method = "euclidean") %>%  #Selecting distance
  hclust(method = "ward.D2") #Selecting algorithm         

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

After 4 steps data are clustered in 4 groups: 349,348,347,346

fviz_dend(WARD, 
          k = 4, #Number of groups
          palette = "Set1", #Colours
          rect = TRUE) #Showing groups
## 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.

Result: 4 groups observed

set.seed(1)
library(NbClust)
Index <- NbClust(mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")],
                 distance = "euclidean",
                 method = "ward.D2", 
                 index ="all",
                 min.nc = 3, max.nc = 5) #Solution between 3 and 5 clusters

## *** : The Hubert index is a graphical method of determining the number of clusters.
##                 In the plot of Hubert index, we seek a significant knee that corresponds to a 
##                 significant increase of the value of the measure i.e the significant peak in Hubert
##                 index second differences plot. 
## 

## *** : The D index is a graphical method of determining the number of clusters. 
##                 In the plot of D index, we seek a significant knee (the significant peak in Dindex
##                 second differences plot) that corresponds to a significant increase of the value of
##                 the measure. 
##  
## ******************************************************************* 
## * Among all indices:                                                
## * 4 proposed 3 as the best number of clusters 
## * 11 proposed 4 as the best number of clusters 
## * 6 proposed 5 as the best number of clusters 
## 
##                    ***** Conclusion *****                            
##  
## * According to the majority rule, the best number of clusters is  4 
##  
##  
## *******************************************************************

According to elbow we should have 4 groups

mydata$Clustering_Ward <- cutree(WARD, 
                                 k = 4) #Number of groups
head(mydata)
## # A tibble: 6 Ă— 16
##      ID Gender   Age City          Membership Total_Spend Items_Purchased Rating
##   <dbl> <chr>  <dbl> <chr>         <chr>            <dbl>           <dbl>  <dbl>
## 1   101 Female    29 New York      Gold             1120.              14    4.6
## 2   102 Male      34 Los Angeles   Silver            780.              11    4.1
## 3   103 Female    43 Chicago       Bronze            511.               9    3.4
## 4   104 Male      30 San Francisco Gold             1480.              19    4.7
## 5   105 Male      27 Miami         Silver            720.              13    4  
## 6   106 Female    37 Houston       Bronze            441.               8    3.1
## # ℹ 8 more variables: `Discount Applied` <lgl>,
## #   `Days Since Last Purchase` <dbl>, `Satisfaction Level` <chr>,
## #   Total_Spend_z <dbl[,1]>, Rating_z <dbl[,1]>, Items_Purchased_z <dbl[,1]>,
## #   Dissimilarity <dbl[,1]>, Clustering_Ward <int>
#Showing the positions of initial leaders, used as starting point for k-means clustering

Leaders_initial <- aggregate(mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")], 
                             by = list(mydata$Clustering_Ward), 
                             FUN = mean)

Leaders_initial
##   Group.1 Total_Spend_z   Rating_z Items_Purchased_z
## 1       1     0.8828786  0.9042034         0.6427325
## 2       2    -0.2152637  0.1612694        -0.1290116
## 3       3    -0.9372473 -1.0603012        -0.9285388
## 4       4     1.6969367  1.3599059         1.7805649
kmeans_clu <- hkmeans(mydata[c("Total_Spend_z", "Rating_z", "Items_Purchased_z")], #Data
                      k = 4, #Number of groups
                      hc.metric = "euclidean", #Distance for hierar. clus.
                      hc.method = "ward.D2") #Alghoritm for hierar. clus.

kmeans_clu
## Hierarchical K-means clustering with 4 clusters of sizes 59, 117, 116, 58
## 
## Cluster means:
##   Total_Spend_z   Rating_z Items_Purchased_z
## 1     0.8828786  0.9042034         0.6427325
## 2    -0.2677722  0.0553610        -0.2266323
## 3    -1.0274382 -1.1956877        -0.9886035
## 4     1.6969367  1.3599059         1.7805649
## 
## Clustering vector:
##   [1] 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1
##  [38] 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2
##  [75] 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3
## [112] 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4
## [149] 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2
## [186] 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1
## [223] 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2
## [260] 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3
## [297] 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3 4
## [334] 2 3 1 2 3 4 2 3 1 2 3 4 2 3 1 2 3
## 
## Within cluster sum of squares by cluster:
## [1]  4.191274 21.910706 21.556494  6.156832
##  (between_SS / total_SS =  94.9 %)
## 
## Available components:
## 
##  [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
##  [6] "betweenss"    "size"         "iter"         "ifault"       "data"        
## [11] "hclust"

The high proportion (94.9%) of between-cluster sum of squares to total sum of squares indicates that the clustering has effectively separated the data into distinct groups. This suggests that the clusters are well-defined and exhibit significant differences from each other.In summary, the clustering seems to be successful in creating internally cohesive clusters, and a large proportion of the total variance in the data is explained by the differences between these clusters.

#Do we have any reclassification?
mydata$classificationKMeans <-kmeans_clu$cluster
head(mydata[, c("ID", "Clustering_Ward", "classificationKMeans")])
## # A tibble: 6 Ă— 3
##      ID Clustering_Ward classificationKMeans
##   <dbl>           <int>                <int>
## 1   101               1                    1
## 2   102               2                    2
## 3   103               3                    3
## 4   104               4                    4
## 5   105               2                    2
## 6   106               3                    3
table (mydata$Clustering_Ward)
## 
##   1   2   3   4 
##  59  94 139  58
table (mydata$classificationKMeans)
## 
##   1   2   3   4 
##  59 117 116  58

There was some reclassification according to numbers in 2 and 3 group.

table (mydata$Clustering_Ward,mydata$classificationKMeans)
##    
##       1   2   3   4
##   1  59   0   0   0
##   2   0  94   0   0
##   3   0  23 116   0
##   4   0   0   0  58

Based on Ward classification we see that in 1 and 4 group reclassification didn’t happen. After Ward classification 23 units from 3 were added to 2nd.

#Profile groups

Averages <- kmeans_clu$centers
round (Averages,3)
##   Total_Spend_z Rating_z Items_Purchased_z
## 1         0.883    0.904             0.643
## 2        -0.268    0.055            -0.227
## 3        -1.027   -1.196            -0.989
## 4         1.697    1.360             1.781
library (tidyr)
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:magrittr':
## 
##     extract
library(ggplot2)
Picture <- as.data.frame(Averages)
Picture$id <-1:nrow (Picture)
Picture <- pivot_longer(Picture, cols = c("Total_Spend_z", "Rating_z", "Items_Purchased_z"))
Picture$Group <- factor(Picture$id, 
                       levels = c(1, 2, 3, 4), 
                       labels = c("1", "2", "3", "4"))

Picture$NameF <- factor(Picture$name, 
                       levels = c("Total_Spend_z", "Rating_z", "Items_Purchased_z"), 
                       labels = c("Total_Spend_z", "Rating_z", "Items_Purchased_z"))

ggplot(Picture, aes(x = NameF, y = value)) +
  geom_hline(yintercept=0) +
  theme_linedraw() +
  geom_point(aes(shape = Group, col = Group), size=3) +
  geom_line(aes(group = id, linetype=Group, col=Group), size=1) +
  ylab("Average") +
  xlab("Cluster variables")+
  ylim(-2.2, 2.2)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Group 3 is below average for all cluster variables. Group 1 and 4 are above average for all cluster variables. Group 2 is below average in Total Spend and Items Purchased and a bit higher average or almost there in rating.

#Checking if clustering variables successfully differentiate between groups

#H_0: There is no significant difference in the means of Total_Spend_z, Rating_z, and Items_Purchased_z across different clusters
#H_1: There is significant difference in the means of Total_Spend_z, Rating_z, and Items_Purchased_z across different clusters

fit <- aov(cbind(Total_Spend_z, Rating_z, Items_Purchased_z) ~ as.factor(classificationKMeans), 
           data = mydata)

summary(fit)
##  Response 1 :
##                                  Df Sum Sq Mean Sq F value    Pr(>F)    
## as.factor(classificationKMeans)   3 343.85 114.616  7696.8 < 2.2e-16 ***
## Residuals                       346   5.15   0.015                      
## ---
## 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(classificationKMeans)   3  321.7 107.233  1359.1 < 2.2e-16 ***
## Residuals                       346   27.3   0.079                      
## ---
## 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(classificationKMeans)   3 327.64 109.213  1768.9 < 2.2e-16 ***
## Residuals                       346  21.36   0.062                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Result: We reject null hypothessis. There is a significant diffrence in the means of Total_Spend_z, Rating_z, and Items_Purchased_z across different clusters (p value less than 0.05)

#H_0: There is no association between gender and groups
#H_1: There is an association between gender and groups

hi_square <- chisq.test(mydata$Gender, as.factor(mydata$classificationKMeans))
hi_square
## 
##  Pearson's Chi-squared test
## 
## data:  mydata$Gender and as.factor(mydata$classificationKMeans)
## X-squared = 342.1, df = 3, p-value < 2.2e-16
round(hi_square$res, 2) 
##              
## mydata$Gender     1     2     3     4
##        Female  5.25 -7.52  7.62 -5.39
##        Male   -5.25  7.52 -7.62  5.39

Based on p value leass than 0.05 we can reject null hypothesis.there is an association between gender and groups

addmargins (round(prop.table(hi_square$observed,2),3),1)
##              
## mydata$Gender     1     2     3     4
##        Female 0.983 0.009 1.000 0.000
##        Male   0.017 0.991 0.000 1.000
##        Sum    1.000 1.000 1.000 1.000
aggregate (mydata$Age, 
           by=list(mydata$classificationKMeans),
           FUN=mean)
##   Group.1        x
## 1       1 30.71186
## 2       2 31.55556
## 3       3 39.36207
## 4       4 29.12069
#H_0: There is no significant difference in the age between groups
#H_1: There is a significant difference in the age between groups
fit_Age <- aov( Age ~ as.factor(classificationKMeans), 
           data = mydata)
summary.aov(fit_Age)
##                                  Df Sum Sq Mean Sq F value Pr(>F)    
## as.factor(classificationKMeans)   3   5996  1998.8   302.8 <2e-16 ***
## Residuals                       346   2284     6.6                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Based on p value less than 0.05 we reject null hypothesis. There is a statistical significant diffrence in age between groups

#H_0: There is no association between memebership and groups
#H_1: There is an association between membership and groups

hi_square_Membership <- chisq.test(mydata$Membership, as.factor(mydata$classificationKMeans))
hi_square_Membership
## 
##  Pearson's Chi-squared test
## 
## data:  mydata$Membership and as.factor(mydata$classificationKMeans)
## X-squared = 700, df = 6, p-value < 2.2e-16

Based on p value less than 0.05 we reject null hypothesis. there is an association between membership and groups

addmargins (round(prop.table(hi_square_Membership$observed,2),3),1)
##                  
## mydata$Membership 1 2 3 4
##            Bronze 0 0 1 0
##            Gold   1 0 0 1
##            Silver 0 1 0 0
##            Sum    1 1 1 1
#H_0: There is no association between city and groups
#H_1: There is an association between city and groups

hi_square_city <- chisq.test(mydata$City, as.factor(mydata$classificationKMeans))
hi_square_city
## 
##  Pearson's Chi-squared test
## 
## data:  mydata$City and as.factor(mydata$classificationKMeans)
## X-squared = 1050, df = 15, p-value < 2.2e-16

Based on p value less than 0.05 we reject null hypothesis. there is an association between city and groups

addmargins (round(prop.table(hi_square_city$observed,2),3),1)
##                
## mydata$City         1     2     3     4
##   Chicago       0.000 0.000 0.500 0.000
##   Houston       0.000 0.000 0.500 0.000
##   Los Angeles   0.000 0.504 0.000 0.000
##   Miami         0.000 0.496 0.000 0.000
##   New York      1.000 0.000 0.000 0.000
##   San Francisco 0.000 0.000 0.000 1.000
##   Sum           1.000 1.000 1.000 1.000

Conclusion:

On the basis of 3 standardized variables (Total Spend, Item Purchased and Rating), we clustered 350 customers into 4 groups by hierarchical clustering (Ward’s algorithm, squared Euclidean distance, none of customers were removed from the analysis because of high dissimilarity). The number of groups was determined based on the dendrogram, and further supported by elbow method. We further optimized the classification by using the K-means method, in which one unit was reclassified.

Group 1 (17%) consists of students who are 30 years old on average, and 98.3% of them are females. Group 1 members live in New York and hold Gold membership status. Members of this group have the second highest spend (USD) and second highest number of purchased items (pcs), as well they assign higher rating compared to 2 and 3 group.

Group 2 (33%) and is represented by customers who are 31 years old on average, and 99 % of them are males. 50.4% of them live Los Angeles and 48% live in Miami. All group members are silver membership holders. They spend less than the average, the number of purchased items is also less than average, however the rating points provided by them allign with average rating point.

Group 3 (33%) , composed of customers, with an average age of 39 years, and 100% of them are females. They are holders of Bronze membership and live in Chicago (50%) and Houstoun (50%). They spend less compare to all other 3 group, as well as purchase the smallest amount of items, and assign rating less than average( the most negative ones).

Group 4 (17%) is represented by customers who are 29 years old on average, and 100% of them are males. They have the highest results compare to all groups. They spend the most, buy the highest amount of items and assign highest rating points.