K-means cosine zero-vector detection
7 views (last 30 days)
Show older comments
I keep getting this error:
Error using kmeans (line 145) Some points have small relative magnitudes, making them effectively zero. Either remove those points, or choose a distance other than 'cosine'.
Error in runkmeans (line 7) [L, C]=kmeans(data, 10, 'Distance', 'cosine', 'EmptyAction', 'drop')
I wonder if anyone can tell me what the criterion is that Matlab uses in order to decide whether a point has a "small relative magnitudes" and is "effectively zero"?
I would love to remove the points, but I don't know how to detect them. It is not simply zero-vectors, because if I force the vector to be non-zero by adding a 1 at the end, I still get this error.
Any help would be greatly appreciated!
Thanks,
0 Comments
Answers (2)
Tom Lane
on 9 May 2012
The function wants to treat each row of the data matrix as a point in some space with dimension size(data,2). Imagine rays extending from the origin to the points represented by each row. For cosine distance, the function wants to normalize each ray to have length 1. It does something like this:
dnorm = sqrt(sum(data.^2, 2));
Try computing this yourself, and see if the minimum value is tiny compared with the maximum value. If that's the case (ratio less than eps), the function is declaring that one point is so close to the origin that it's not reasonable to assign an angle to it.
If you believe the disparity in magnitudes of the points is not a problem, you could try normalizing each row to unit length before sending it into kmeans.
2 Comments
Tom Lane
on 9 May 2012
Just type "eps" at the MATLAB command line and you'll see its numeric value. Type "help eps" for more details.
MML
on 13 Mar 2014
Dow, I am facing the same problem. Please share if you finally managed to do K-means cosine clustering.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!