1
votes

Hi I modified my K mean clustering Algorithm to use the haversian formula for lognitude and latitude instead of euclidean distance . i modified the euclidean distance file in the core folder. here is what i did.

public static double distance(double lat1, double lon1, double lat2, double lon2) { double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

after that i imported opened the weka-src.jar after extracted it in Netbeans and Cleaned and Built the File

It created all the class files in the folder. and i made a weka.jar file using command prompt but then i replaced the original weka.jar file in the weka installation folder and weka doesn't work anymore.

Any idea what's the problem.

i am also trying ANT to create weka.jar ..

Thanks

1

1 Answers

0
votes

Consider using ELKI. It includes Geodetic distances out of the box, and is usually faster than Weka, too. It also has index acceleration for geodetic distances in algorithms such as DBSCAN and OPTICS.

Be careful with k-means and other distances though. K-means is really only designed for squared Euclidean, because of the mean. Computing the mean on latitude and longitude is dangerous. Consider you have points all over Alaska. Your mean will likely be somewhere in the Norwegian sea, because you did not take the +-180 degree wraparound into account.

In the worst case, this may stop your k-means from converging, and it will run in an endless loop.