K-means Clustering Algorithm with Geographical Visualization source code

Download Free projects with Source Code


This Java application  provides a idea of data-mining and visualisation features all with awesome front end. All functionality  is provided by modules, with the goal that the software is easy to extend, contribute to, and customise.

Algorithm Stpes :

# Function: K Means
# -------------
# K-Means is an algorithm that takes in a dataset and a constant
# k and returns k centroids (which define clusters of data in the
# dataset which are similar to one another).
def kmeans(dataSet, k):
    # Initialize centroids randomly
    numFeatures = dataSet.getNumFeatures()
    centroids = getRandomCentroids(numFeatures, k)
    # Initialize book keeping vars.
    iterations = 0
    oldCentroids = None
    # Run the main k-means algorithm
    while not shouldStop(oldCentroids, centroids, iterations):
        # Save old centroids for convergence test. Book keeping.
        oldCentroids = centroids
        iterations += 1
        # Assign labels to each datapoint based on centroids
        labels = getLabels(dataSet, centroids)
        # Assign centroids based on datapoint labels
        centroids = getCentroids(dataSet, labels, k)
    # We can get the labels too by calling getLabels(dataSet, centroids)
    return centroids

Running Steps :

Step 1 : Install JDK with any platfor as windows,mac etc

Step 2 : Run java class Main.java

Step 3 : Initialize K-means entity number in input textbox , this value will be assigned to number of entities in clustering as below

Step 4 : Loading data from any plain text file with deleimeter with latitude and longitude