Simple K-Means do not handle iris.arff

I have this class below, I built it, taking into account the examples given on the wiki and in the thesis, why can't SympleKMeans process data? The class can print Datasource dados, so its nothing bad in the processing file, an error in the assembly.

package slcct; import weka.clusterers.ClusterEvaluation; import weka.clusterers.SimpleKMeans; import weka.core.Instance; import weka.core.Instances; import weka.core.converters.ConverterUtils.DataSource; public class Cluster { public String path; public Instances dados; public String[] options = new String[2]; public Cluster(String caminho, int nclusters, int seed ){ this.path = caminho; this.options[0] = String.valueOf(nclusters); this.options[1] = String.valueOf(seed); } public void ledados() throws Exception{ DataSource source = new DataSource(path); dados = source.getDataSet(); System.out.println(dados) if(dados.classIndex()==-1){ dados.setClassIndex(dados.numAttributes()-1); } } public void imprimedados(){ for(int i=0; i<dados.numInstances();i++) { Instance actual = dados.instance(i); System.out.println((i+1) + " : "+ actual); } } public void clustering() throws Exception{ SimpleKMeans cluster = new SimpleKMeans(); cluster.setOptions(options); cluster.setDisplayStdDevs(true); cluster.getMaxIterations(); cluster.buildClusterer(dados); Instances ClusterCenter = cluster.getClusterCentroids(); Instances SDev = cluster.getClusterStandardDevs(); int[] ClusterSize = cluster.getClusterSizes(); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(cluster); eval.evaluateClusterer(dados); for(int i=0;i<ClusterCenter.numInstances();i++){ System.out.println("Cluster#"+( i +1)+ ": "+ClusterSize[i]+" dados ."); System.out.println("Centróide:"+ ClusterCenter.instance(i)); System.out.println("STDDEV:" + SDev.instance(i)); System.out.println("Cluster Evaluation:"+eval.clusterResultsToString()); } } } 

Error:

 weka.core.WekaException: weka.clusterers.SimpleKMeans: Cannot handle any class attribute! at weka.core.Capabilities.test(Capabilities.java:1097) at weka.core.Capabilities.test(Capabilities.java:1018) at weka.core.Capabilities.testWithFail(Capabilities.java:1297) at weka.clusterers.SimpleKMeans.buildClusterer(SimpleKMeans.java:228) at slcct.Cluster.clustering(Cluster.java:53)//Here. at slcct.Clustering.jButton1ActionPerformed(Clustering.java:104) 
+4
source share
3 answers

I believe that you do not need to set the class index as you are clustering, not classifying. Try this guide for Java software clustering .

+7
source

In your ledados () function, simply delete the code block indicated below. This will work. Since you do not have a specific class in your data.

 if(dados.classIndex()==-1){ dados.setClassIndex(dados.numAttributes()-1); } 

Your new feature:

 public void ledados() throws Exception{ DataSource source = new DataSource(path); dados = source.getDataSet(); System.out.println(dados) } 
+3
source

You do not need a class attribute in the data when performing clustering k

0
source

All Articles