Question about kmeans centroid
이전 댓글 표시
hi, i have a quick question about kmeans.
i randomly generated 1,000 number in the range of (0,1) and clustered them into 20.
however, i found the mean of each cluster is slightly different from their centroid. Why? By definition, they should be the same, right?
thanks.
댓글 수: 1
Walter Roberson
2012년 7월 20일
mean versus median ?
채택된 답변
추가 답변 (2개)
Peter Perkins
2012년 7월 20일
Rebecca, are you seeing something like this?
>> x = rand(1000,1);
>> [idx,c] = kmeans(x,20);
>> c2 = grpstats(x,idx,@mean);
>> c - c2
ans =
0
0
-1.38777878078145e-17
0
0
0
0
0
0
-1.38777878078145e-17
0
0
0
-2.77555756156289e-17
0
0
-5.55111512312578e-17
0
0
0
That is to be expected, the differences are due to different rounding errors. Consider this:
>> x = rand(1000,1);
>> ( sum(x) - sum(x(randperm(length(x)))) ) / sum(x)
ans =
-7.87959181618481e-16
which is because the sums are in different order. Same idea.
If you're seeing something else, you;ll have to provide more info. Hope this helps.
카테고리
도움말 센터 및 File Exchange에서 k-Means and k-Medoids Clustering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!