-2
package cbr;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
import weka.clusterers.ClusterEvaluation;
import weka.clusterers.FarthestFirst;
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.Remove;
public class Cluster {
protected int m_ClusterCentroids;
protected Instances 
protected Instances m_instances;
protected int m_Seed;
public static void main(String[] args) throws Exception {
Instances data = new Instances(new 
BufferedReader(new  
FileReader("FinalDatasetforCBSAPDS.arff")));
data.setClassIndex(data.numAttributes() -1);
Remove filter = new Remove();
filter.setAttributeIndices("" +(data.classIndex() + 1));
filter.setInputFormat(data);
Instances dataClusterer = Filter.useFilter(data, filter);
FarthestFirst clusterer = new FarthestFirst();
clusterer.setNumClusters(5);
clusterer.setSeed(5127); // set the seed size
String[] options = new String[2];
int nClusters = 5;
int seed = 5127;
options[0] = String.valueOf(nClusters);
options[1] = String.valueOf(seed);
clusterer.setOptions(options);           
ClusterEvaluation eval= new ClusterEvaluation();
eval.setClusterer(clusterer);
eval.evaluateClusterer(data);
System.out.println("# of clusters: " + 
eval.getNumClusters());
clusterer.buildClusterer(dataClusterer);
eval.setClusterer(clusterer);
eval.evaluateClusterer(data);
System.out.println(eval.clusterResultsToString());
Instances centroids = clusterer.getClusterCentroids();
int numclusters = clusterer.getNumClusters();
String filename = "Final_Dataset";
filename += "for_CBSAPDS";
filename += ".txt";
File file = new File(filename);
try (Writer writer = new BufferedWriter(new 
FileWriter(file))) {
for (int i= 0; i<=5127; i++) {
for (int j= 0; j<numclusters; j++) {
String centroidsStr= centroids.instance(i).toString();
String[] to = centroidsStr.split(",");
writer.write(Integer.toString(i));
writer.write(",");
writer.write(data.instance(j) + "," + "case" + i + "," + (to[0]));
writer.write("\n");
}

}

System.out.println("\nInformation:");
}

}

}

This is the java code for farthestfirst clustering algorithm I wrote to integrate farthestfirst clustering algorithm with CBR. But it throws an Exception like:

Exception in thread ''main'' java.lang.Exception: illegal options: 5 527 at weka.core.Utils.checkForRemainingOptions(Utils.java:505) at weka.clusterers.FarthesFirst.setOptions(FarthestFirst.java:568)
at cbr.Cluster.main(Cluster.java)

So I need help on this issues

Degefe
  • 1
  • 1

1 Answers1

0

You are passing the wrong arguments to your setOptions(..) method. The API states, that you can supply the parameters as following Strings: "-N <number of clusters>" and "-S <seed>"

So you need to construct your parameters to look like this, if you want to use the setOption method. However, this seems to be overhead, as this method does the same as setSeed and setNumClusters (that you are already using) so you might just get rid of the setOptions(..) method and the respective parameters.

Coronero
  • 160
  • 1
  • 9