Giter Club home page Giter Club logo

geo-cluster's Introduction

#Geographical KMeans

This small library is an implementation of KMeans clustering for geographical points, written in Groovy. It uses the Haversine Formula as its distance metric.

KMeans is both clever and powerful but it has two important things to think about: 1) which distance metric you use to calculate distance between points (e.g. x/y grid distance may not always be correct) and 2) how to optimize for k, the number of clusters. KMeans makes no assumption naively about your choice of k and it may take several runs to find the 'correct' k value for your domain. For example, one may run this algrothim several times to find the optimal k where no cluster has locations more than 100 kilometers away from the center.

Build

Gradle is used as the build tool. Run gradlew jar (or just gradle jar if gradle is installed on your system)to create the jar file, then include in your project.

Usage

The basic approach is to pass a List of objects which implement the GeographicPoint interface to the ClusterService's cluster method, along with k, the number of clusters to create.

	List<GeographicPoint> points = [point1, point2,...]
	// cluster the points into a list
	List<Cluster> clusters = ClusterService.cluster(points, 10)
	clusters.each {cluster->
		println "Cluster has ${cluster.points.size()} points:"
		cluster.points.each {point->
			println "${point.latitude} / ${point.longitude}"
		}
	}

Note: the cluster algorithm is iterative and may take several lengthy iterations to converge. Additionally, if the initial clusters are generated randomly (as is the default), clusters are not guaranteed to contain the same points on each run.

Potential Future work

As this is a first pass, it is extremely simplistic. There are several things I'd like to add, time permitting:

  • An algorithm more accurate than Haversine. The earth, after all, is not a sphere but rather a non-uniform ellipse
  • Increased Unit testing for different clustering scenarios
  • Structure for setting latitude and longitude precision
  • Framework for iteratively finding the optimal k value based on some pluggable criteria (e.g. no clusters more than X distance away from the center)

geo-cluster's People

Contributors

spember avatar

Stargazers

Ghiwook Nam avatar  avatar Ivan Korol avatar Erhan Sunar avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

esunar hnulst

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.