4
$\begingroup$

I want to use k-means clustering on my dataset to capture the similarity based on two attributes for two groups. I am looking to split my data first into training and testing, and then find clusters based on the training data and test the same on the new data.

The only concern I have right now is that during sampling, the distribution of data should not be biased. I have data for two groups 0 and 1, for which I want to split, and validate whether the two attributes for new data fall into group 0 or 1.

What are the points that I need to take care in mind while sampling the data? I assume it should not be random sampling, and needs to be done properly, to ensure that skewness is not present in the data, else the entire objective of clustering will fail.

$\endgroup$
1
  • 1
    $\begingroup$ Assuming that the data set is not tiny, why do you assume sampling at random is a bad idea? $\endgroup$
    – deemel
    Commented Jun 11, 2018 at 16:36

3 Answers 3

5
$\begingroup$

Train and test splits are only commonly used in supervised learning.

There is a simple reason for this:

Most clustering algorithms cannot "predict" for new data. K-means is a rare exception, because you can do nearest-neighbor classification on the centroids to predict. But for any method that doesn't use centroids, it's not clear how you would apply this to "test" data.

Furthermore, how would you evaluate quality? The data is not labeled. So you could look at least-squares as in k-means and check which clustering (of multiple random runs) produced the smallest errors. But that won't be very different from just doing this on the entire data set at once, without splitting.

Much of supervised learning just does not transfer to unsupervised.

$\endgroup$
3
$\begingroup$

I have data for two groups 0 and 1, for which I want to split, and validate whether the two attributes for new data fall into group 0 or 1.

This isn't a clustering problem, it's a classification problem. You want to know whether or not these two attributes are correlated with your group assignments: the attributes are your features and the group assignment is the target you are trying to predict. You're more interested in performing inference on the features than on accurately predicting the target, which is perfectly fine. Classification models can sometimes be difficult to interpret: the simpler you go, the easier interpretation is. Here are a few simple models to try:

  • Naive Bayes
  • Decision Trees
  • Logistic Regression (A bit harder to interpret, but still doable)

If you're not even that interested in performing inference on the features and just want to know more generally "how well do the groups cluster in the attribute space?", you could bootstrap KNN to estimate the probability that a member from one group is in a region dominated by its own group.

$\endgroup$
0
$\begingroup$

This question seems to be a supervised problem, where train and split are is commonly done, however if you are intrested in splitting the data, you can do it as follows:

from sklearn.model_selection import train_test_split

X_train,X_test = train_test_split(X,test_size=0.25)
$\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.