> Ok, so something like:
>
> While (I < k)
> {
> classifier.train(dataset[i])
> arrayOfClassifiers[i] = classifier;
> ++I;
> }
> votingClassifier.train(arrayOfClassifers);
>
> should work? If so I think that should do what I need. Thanks...
Yes, something like that.
import weka.core.Instances;
import weka.classifiers.Classifier;
import weka.classifiers.bayes.BayesNet;
import weka.classifiers.meta.Vote;
Instances[] datasets = ... // from somewhere
// test whether datasets are all compatible
// NB: you're not allowed to violate Weka's underlying assumption,
// that all classifiers got trained on the same data. Hence the
// structure of the datasets must be exactly the same. The data
// itself can differ though.
for (int i = 1; i < datases.length; i++) {
if (!datasets[0].equalsHeader(datasets[i]))
throw IllegalStateException("Training sets not compatible!");
}
// train classifiers
Classifier[] classifiers = new Classifier[datasets.length];
for (int i = 0; i < datasets.length; i++) {
classifiers[i] = new BayesNet();
classifiers[i].buildClassifier(datasets[i]);
}
// setup Vote
Vote vote = new Vote();
vote.setClassifiers(classifiers);
// output predictions on test set
Instances test = ... // from somewhere
if (!datasets[0].equalHeaders(test))
throw new IllegalStateException("Test set not compatible!");
for (int i = 0; i < test.numInstances(); i++) {
double pred = vote.classifyInstance(test.instance(i));
System.out.println((i+1) + ". " + pred);
}
NB: this code has never been compiled, but was written from memory.
See wiki article "Use Weka in your Java code" for how to use the Weka
API:
http://weka.wiki.sourceforge.net/Use+Weka+in+your+Java+codeCheers, Peter
--
Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
http://www.cs.waikato.ac.nz/~fracpete/ Ph. +64 (7) 858-5174
_______________________________________________
Wekalist mailing list
Send posts to:
Wekalist@...
List info and subscription status:
https://list.scms.waikato.ac.nz/mailman/listinfo/wekalistList etiquette:
http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html