//选择初始的k个质点 for (int j = initInstances.numInstances() - 1; j >= 0; j--) { instIndex = RandomO.nextInt(j+1); hk = new DecisionTableHashKey(initInstances.instance(instIndex), initInstances.numAttributes(), true); if (!initC.containsKey(hk)) { m_ClusterCentroids.add(initInstances.instance(instIndex)); initC.put(hk, null); } initInstances.swap(j, instIndex); if (m_ClusterCentroids.numInstances() == m_NumClusters) { break; } } //重复迭代, 直到converged=true时退出。converged=true时,再跌代也不会改变每个节点的cluster while (!converged) { emptyClusterCount = 0; m_Iterations++; converged = true; for (i = 0; i < instances.numInstances(); i++) { Instance toCluster = instances.instance(i); int newC = clusterProcessedInstance(toCluster, true); if (newC != clusterAssignments[i]) { converged = false; } clusterAssignments[i] = newC; } //重新计算质心 //迭代次数已达上限时,设置converged=true退出 } squaredErrors, clusterStdDevs, 这些是用来做什么的? clusterStdDevs, 衡量同一类中、同一个属性各个值的标准差 squaredErrors, 记录的是每个类中, 类中每个点到其质心的距离的平方和 这两个变量用来衡量聚类结果的好坏