Skip to content

Commit 5b1f6af

Browse files
committed
fix the k-means clustering expectation calculation error
1 parent a2b931d commit 5b1f6af

File tree

1 file changed

+3
-2
lines changed
  • src/main/java/com/github/chen0040/clustering/kmeans

1 file changed

+3
-2
lines changed

src/main/java/com/github/chen0040/clustering/kmeans/KMeans.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ public double[] calcCenter(DataFrame context){
132132
int m = elements.size();
133133
for(int i=0; i < n; ++i){
134134
double sum = 0;
135-
double[] x = context.row(i).toArray();
135+
136136
for(int j=0; j < m; ++j){
137-
sum += x[j];
137+
double[] x = context.row(j).toArray();
138+
sum += x[i];
138139
}
139140

140141
newCenter[i] = sum / m;

0 commit comments

Comments
 (0)