给点一组 c 点资料 X = {x1, ..., xc} ,每一点都有 d 维;给定一个群聚的数目 k, 求其最好的聚类结果。
(1)package ;
class Centroid {
private double mCx, mCy;
private Cluster mCluster;
public Centroid(double cx, double cy) {
= cx;
= cy;
}
public void entroid() { //only called by CAInstance
int numDP = ();
double tempX = 0, tempY = 0;
int i;
//caluclating the new Centroid
for (i = 0; i < numDP; i++) {
tempX = tempX + (i).getX();
//total for x
tempY = tempY + (i).getY();
//total for y
}
= tempX / numDP;
= tempY / numDP;
//calculating the new Euclidean Distance for each Data Point
tempX = 0;
tempY = 0;
for (i = 0; i < numDP; i++) {
(i).calcEuclideanDistance();
}
//calculate the new Sum of Squares for the Cluster
();
}
public void setCluster(Cluster c) {
= c;
}
public double getCx() {
return mCx;
}
public double getCy() {
return mCy;
}
public Cluster getCluster() {
return mCluster;
}
2)import ;
class Cluster
kmeans算法Java实现 来自淘豆网m.daumloan.com转载请标明出处.