Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the base classifier in stacking method when using Weka API?

Tags:

java

api

weka

I was trying to use stacking method weka api in java and found a tutorial for single classifier. I tried implementing stacking using the method described in the tutorial method but the classification is done with default Zero classifier in Weka.I was able to set meta classifier using "setMetaClassifier" but not able to change the base classifier.What is the proper method to set base classifier in stacking ?

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Random;    
import weka.classifiers.Evaluation;
import weka.classifiers.meta.Stacking;
import weka.core.Instances;
public class startweka {
public static void main(String[] args) throws Exception{ 
BufferedReader breader=new BufferedReader(new FileReader("C:/newtrain.arff")); 
Instances train=new Instances(breader); 
train.setClassIndex(train.numAttributes()-1); 
breader.close(); 
String[] stackoptions = new String[1]; 
{ 
      stackoptions[0] = "-w weka.classifiers.functions.SMO"; 
} 
Stacking nb=new Stacking(); 
J48 j48=new J48(); 
SMO jj=new SMO(); 
nb.setMetaClassifier(j48); 
nb.buildClassifier(train); 
Evaluation eval=new Evaluation(train); 
eval.crossValidateModel(nb, train, 10, new Random(1)); 
System.out.println(eval.toSummaryString("results",true)); 
                        }} 
like image 670
user3201928 Avatar asked Feb 26 '14 12:02

user3201928


1 Answers

Ok i found the answer in other forum weka nabble.The code for setting base classifier is

Stacking nb=new Stacking();
SMO smo=new SMO();
Classifier[] stackoptions = new Classifier[1];
stackoptions[0] = smo;
nb.setClassifiers(stackoptions);

OR

Stacking nb=new Stacking();
SMO smo=new SMO();
Classifier[] stackoptions = new Classifier[] {smo};
nb.setClassifiers(stackoptions);
like image 71
user3201928 Avatar answered Oct 23 '22 18:10

user3201928