/** * Predicts the cluster memberships for a given instance. Either this or * clusterInstance() needs to be implemented by subclasses. * * @param instance the instance to be assigned a cluster. * @return an array containing the estimated membership probabilities of the * test instance in each cluster (this should sum to at most 1) * @exception Exception if distribution could not be computed successfully */ @Override public double[] distributionForInstance(Instance instance) throws Exception { double[] d = new double[numberOfClusters()]; d[clusterInstance(instance)] = 1.0; return d; }
/** * Predicts the cluster memberships for a given instance. Either this or * clusterInstance() needs to be implemented by subclasses. * * @param instance the instance to be assigned a cluster. * @return an array containing the estimated membership probabilities of the * test instance in each cluster (this should sum to at most 1) * @exception Exception if distribution could not be computed successfully */ @Override public double[] distributionForInstance(Instance instance) throws Exception { double[] d = new double[numberOfClusters()]; d[clusterInstance(instance)] = 1.0; return d; }
public Clustering getClusteringResult() { Clustering clustering = null; weka.core.Instances wekaInstances= this.instanceConverter.wekaInstances(instances); try { clusterer.buildClusterer(wekaInstances); int numClusters = clusterer.numberOfClusters(); Instances dataset = getDataset(instances.numAttributes(), numClusters); List<Instance> newInstances = new ArrayList<Instance>() ; //Instances(dataset); for (int i = 0; i < wekaInstances.numInstances(); i++) { weka.core.Instance inst = wekaInstances.get(i); int cnum = clusterer.clusterInstance(inst); Instance newInst = new DenseInstance(instances.instance(cnum)); newInst.insertAttributeAt(inst.numAttributes()); newInst.setDataset(dataset); newInst.setClassValue(cnum); newInstances.add(newInst); } clustering = new Clustering(newInstances); } catch (Exception e) { e.printStackTrace(); } instances = null; return clustering; }
processor.setMinAndMax(0,theClusterer.numberOfClusters()); } catch (Exception e) { e.printStackTrace();
int numClusters=0; try { numClusters = theClusterer.numberOfClusters(); } catch (Exception e) { e.printStackTrace();