from java.io import FileReader
from weka.core import Instances
from jhplot import Web
xf="weather.arff"
url="https://datamelt.org/examples/data/weka/"+xf
print "Loading ",xf
print Web.get(url)
data = Instances(FileReader(xf))
from weka.clusterers import EM;
cls = EM() # new instance of clusterer
cls.setOptions(["-N", "2"])
cls.buildClusterer(data) # build the clusterer
print cls
# print cluster membership
from weka.core import Utils
for i in range(data.numInstances()):
cluster = cls.clusterInstance(data.instance(i))
dist = cls.distributionForInstance(data.instance(i))
print ( str(i+1)+" - "+str(cluster)+" - "+Utils.arrayToString(dist))
Ads help maintain this website.