I have a very dataset with many observations (> 1 million), with mainly continuous variables and three categorical variables. After searching for clustering methods for mixed data, I decided to transform the categorical variables with a Multiple Correspondence Analysis into continuous variables. Other methods were also proposed in previous questions (Clustering of mixed type data with R), but I want to use k-means.

After the MCA, I retain ~ 90% of the variance keeping 32 components. I have 26 continuous variables. I wonder if it is possible (and advised) to provide different weight to the coordinates from the MCA, since they really represent 3 variables. for example, that the continuous variables had a weight of 1, and the components extracted from the MCA a weight of 0.09 (~ 3/32). In this question about weighet k-means I don't find the answer (https://stackoverflow.com/questions/48901178/weighted-kmeans-r), although if I don't find a solution I may try it.

As well, I am considering to do a hierarchical clustering on the centers of a preliminar k-means, similar to this hybrid approach (Hybrid (K-means + Hierarchical ) clustering), and also proposed by the tutorials of the FactoMineR package (http://factominer.free.fr/bookV2/index.html). However, I do not know how to weight the cluster centers with the number of observations of each clusters.

I would appreciate any suggestions!

My script is as follows (sorry, lack of example data):


# Perform MCA on categorical variables
mca.data.cat <- MCA(X=data.cat, ncp=32) ### Keep 91% variability

# Extract the coordinates in the MCA axes for all observations
mca.coords <- mca.data.cat$ind$coord

# Transform into dataframe
mca.coords.df <- as.data.frame(mca.coords)

# Join continuous variables and and MCA coords of the categorical variables
df.input<- cbind(cont.vars ,mca.coords.df)
df.input<- df.input %>% 
  na.omit() %>%          # Remove missing values (NA)
  scale()                       # Scale variables
df.input <- as.data.frame(df.input)

## Perform k-means
km.output <- kmeans(df.input, centers=100, nstart = 400, iter.max = 50)

### Perform hierarchical cluster analysis on the centers of the clusters
km.clorpt.centers <- as.data.frame(km.output$centers)
clorpt.hc <- HCPC(res= km.clorpt.centers, nb.clust=-1 )
  • $\begingroup$ Hi! I'm working on a similar problem where I have all the variables as categorical variables and applied MCA. When I visualize MCA components by clusters obtained through K-modes applied independently of MCA, the clusters are very overlapping with arbitrary shapes. I was wondering instead of applying k-modes, I should simply get MCA components and apply K-means on those components. Does that make sense? $\endgroup$ – Shahzeb Naveed Jun 17 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.