Run different clustering algorithms using data from a file
Source code name: "clustering_all.py"
Programming language: Python
Topic: Data mining/clustering
DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/clustering_all_3789.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from java.awt import Color
from java.util import Random 
from jminhep.cluster import * 

# create a data holder
data = DataHolder("Example")

# fill 3D data with Gaussian random numbers
rand = Random()
for i in range(100):
      a =[]
      a.append( 10*rand.nextGaussian() )
      a.append( 2*rand.nextGaussian()+1 )
      a.append( 10*rand.nextGaussian()+3 )
      data.add( DataPoint(a) )
      del a

# show the data
# HTable(data)

# Print data
# data.print()

# initialte partitioner
pat = Partition(data);

# set mode
pat.set(3, 0.001, 1.7, 1000);

# probability for membership (only for Fuzzy algorithm)
pat.setProbab(0.68)


# define types of cluster analysis
mode =[]
mode.append(111)
mode.append(112)
mode.append(113)
mode.append(114)
mode.append(121)
mode.append(122)
# mode.append(131)
# mode.append(132)

 

for i in range(len(mode)):
        print "test=",i
        pat.run(mode[i])
        print "algorithm: " +  pat.getName()
        print "Compactness: " + str(pat.getCompactness())
        print "No of final clusters: " + str(pat.getNclusters())
        Centers = pat.getCenters()
#        Centers.Print()


You see the box below because you did not login.