3
$\begingroup$

I have 1000 sets of one dimensional data (360 each in length), and I want k means to classify what is a small/medium/large value (n_clusters=3) for each set of data, but I'm getting a lot of instances where the large group only has 1 data point because that value is so far away from the rest, but the rest look like they can clearly create 3 clusters.

In some other cases, it does seem to make sense to use 1 data point as the large group since the rest are so close together. It's not clear if there can be 3 distinctive clusters.

What would be an efficient way to deal with this?

$\endgroup$
  • $\begingroup$ "I have [...] one dimensional data [...], and I want k means to classify what is a small/medium/large value". That sounds super simple - why don't you create a simple rule? Why do you want to use k-means for that? $\endgroup$ – Martin Thoma May 21 at 17:33
  • $\begingroup$ because not that simple in real life, not linear like 1,2,3,4,5 try to make a one rule fits all for example these two set of data: 2,3,5,6,40; and ,22.5,22.5,23,23.1 or 0,0,0,50 $\endgroup$ – sculpter May 21 at 17:38
  • $\begingroup$ 0.33 and 0.66 percentile: [[2,3], [5], [6, 40]] and [[22.5, 22.5], [23, 23.1]] and [[0, 0, 0], [50]] $\endgroup$ – Martin Thoma May 21 at 17:47
  • 1
    $\begingroup$ if 6 and 40 are in the same group, in a real life situation you probably dont want to treat 6.1 and 55 in the same manner. in that data set it only makes sense to have 2 groups [[2,3,5,6],[40]] now you could try to classify them with an arbitrary score based on standard deviation but changes in data would still make nonsensical clusters $\endgroup$ – sculpter May 21 at 17:53
  • $\begingroup$ I don't get your logic here. But the important point I want to make is that you have some logic in mind. If that is the case, then machine learning is the wrong approach. $\endgroup$ – Martin Thoma May 21 at 18:04
3
$\begingroup$

Two ideas come to mind, which could be combined or not.

  1. Try to identify the single point as an outlier, and remove it from consideration for the clustering.
  2. Allow $k$ to vary a little.

Using both and allowing $k\in\{2,3\}$ allows you to find only two groups in the main set of points, plus the outlier. Using just (2) with $k\in\{3,4\}$ could find clusters Low/Med/Large/Outlier...that has the nicety that outlier detection is done by the k-means algorithm rather than another preprocessing step, but runs the risk of finding four honest clusters when you only wanted three.

$\endgroup$
3
$\begingroup$

When your data has outliers K-means is not a good choice (as you can understand from the way the algorithm behave). In your case I suggest using k-medoids (also called PAM for Partitioning Around Medoids) which isn't outlier-sensitive.

K-medoids takes more time to compute compared to K-means but you'll not notice the difference with such order of magnitude in your data.

$\endgroup$
1
$\begingroup$

K-mrans is not robust to outliers. And that is what you are seeing here.

Mathematically, k-means does what it is expected to do. Putting an extreme value in its own cluster reduces variance, which is the objective.

In your case, I don't think you want to do clustering in the first place. Instead, define thresholds that discretize your data into three ranges manually. Then the same thesholds will be used across all series.

$\endgroup$

Your Answer

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

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