Running k-means clustering over input data file
Code: "clustering_km_spmf.py". Programming language: Python
DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/clustering_km_spmf_5239.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 ca.pfv.spmf.algorithms.clustering.kmeans import AlgoKMeans
# create input data
data="""1 2 3 4
1 6 8 8
1 2 3 3
2 4 5 5
4 7 8 7
7 6 8 9
4 4 3 3
2 2 5 5
7 5 5 5
5 6 8 9
"""
file = open("data.txt", "w")
file.write(data)
file.close()
out="output.txt"
alg=AlgoKMeans()
alg.runAlgorithm("data.txt", 3) # make 3 clusters
# alg.printStatistics()
alg.saveToFile(out)
print "Clusters="
print open(out).read()
You see the box below because you did not login.