5
$\begingroup$

I am trying to cluster some big data by using the k-prototypes method. I am unable to use K-Means as I have both categorical and numeric data. I have been using the package "clustMixType" and have been able to create clusters if I define what k value I want. I want to find the optimal k value though and can't find anything on this online already.

$\endgroup$
5
  • 3
    $\begingroup$ This is more of a methodology question. You should probably ask this on the data science stack exchange. There are multiple measures of the "quality" of a cluster partition. A set of them are available in the clue package. $\endgroup$
    – lmo
    Commented Jul 20, 2017 at 16:58
  • 3
    $\begingroup$ I agree that this isn't a specific programming question that's appropriate for this site. That fact that you are using R seems to be irrelevant to your question. You should probably ask at Cross Validated or Data Science if you need help deciding how to analyze your data. $\endgroup$
    – MrFlick
    Commented Jul 20, 2017 at 17:03
  • $\begingroup$ A simple way to deal with this to optimize error + ck, where c is a reasonable constant. $\endgroup$
    – ElKamina
    Commented Jul 21, 2017 at 6:06
  • $\begingroup$ Use an appropriate internal clustering criterion to help you select the best k. That is, do clustering with different k (say 2 through 20) and compare the values of of the criterion on a plot. Pay attention to peaks, elbows on such a plot. I recommend either Ratkowsky–Lance or BIC (or AIC) clustering criterions because they allow for mix of quantitative and categorical data. You may find more on our site CrossValidated about clustering criterions aka clustering validation indices. $\endgroup$
    – ttnphns
    Commented Jul 29, 2017 at 8:45
  • $\begingroup$ Thank you all for your response! I ended up worked out manually all the in-cluster errors and summing them and plotting a graph using the Elbow rule. $\endgroup$
    – Fiona
    Commented Aug 1, 2017 at 11:48

2 Answers 2

1
$\begingroup$

As far as I know there's no generic optimal k.

It depends a lot on your dataset and your goal. A lower K would yield more fuzzy prototypes but would generalize better. There are always trade-offs

One way to pick K is to plot the data, and look at it. Even then you might want to try other values to see if they work better for your application.

$\endgroup$
0
$\begingroup$

You may use the code as below to plot the elbow curve. The input to the code below is the .

data <- <input the data here>
# Elbow Method for finding the optimal number of clusters
set.seed(123)
# Compute and plot wss for k = 2 to k = 15.
k.max <- 15
data <- na.omit(data) # to remove the rows with NA's
wss <- sapply(1:k.max, 
              function(k){kproto(data, k)$tot.withinss})
wss
plot(1:k.max, wss,
     type="b", pch = 19, frame = FALSE, 
     xlab="Number of clusters K",
     ylab="Total within-clusters sum of squares")
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.