Example usage for weka.classifiers.functions LibSVM setShrinking

List of usage examples for weka.classifiers.functions LibSVM setShrinking

Introduction

In this page you can find the example usage for weka.classifiers.functions LibSVM setShrinking.

Prototype

public void setShrinking(boolean value) 

Source Link

Document

whether to use the shrinking heuristics.

Usage

From source file:Tubes.Classification.java

public static void main(String[] args) throws FileNotFoundException, IOException, Exception {

    StringToWordVector filter = new StringToWordVector();

    File training = new File(classTrain);
    File testing = new File(classTest);

    BufferedReader readTrain = new BufferedReader(new FileReader(training));
    BufferedReader readTest = new BufferedReader(new FileReader(testing));

    Instances dataTrain = new Instances(readTrain);
    Instances dataTest = new Instances(readTest);

    filter.setInputFormat(dataTrain);/*from   www  .  j  av  a 2 s.  c o  m*/
    dataTrain = Filter.useFilter(dataTrain, filter);

    dataTrain.setClassIndex(dataTrain.numAttributes() - 1);
    dataTest.setClassIndex(dataTest.numAttributes() - 1);

    Classification classify = new Classification();
    NaiveBayes bayes = new NaiveBayes();
    //        RandomForest rf = new RandomForest();
    //        BayesNet bayesNet = new BayesNet();
    LibSVM libSVM = new LibSVM();
    System.out.println("==========================Naive Bayes Evaluation===========================");
    Evaluation eval = classify.runClassifier(bayes, dataTrain, dataTest);
    System.out.println(eval.toSummaryString() + "\n");
    System.out.println(eval.toClassDetailsString() + "\n");
    System.out.println(eval.toMatrixString() + "\n");
    System.out.println("===========================================================================");
    //
    //        ====System.out.println("==============================Random Forest================================");
    //        Evaluation eval2 = classify.runClassifier(rf, dataTrain, dataTest);
    //        System.out.println(eval2.toSummaryString() + "\n");
    //        System.out.println(eval2.toClassDetailsString() + "\n");
    //        System.out.println(eval2.toMatrixString() + "\n");
    //        System.out.println("=======================================================================");
    //
    //        System.out.println("==============================Bayesian Network================================");
    //        Evaluation eval3 = classify.runClassifier(bayesNet, dataTrain, dataTest);
    //        System.out.println(eval3.toSummaryString() + "\n");
    //        System.out.println(eval3.toClassDetailsString() + "\n");
    //        System.out.println(eval3.toMatrixString() + "\n");
    //        System.out.println("===========================================================================");

    System.out.println("==============================LibSVM================================");
    libSVM.setCacheSize(512); // MB
    libSVM.setNormalize(true);
    libSVM.setShrinking(true);
    libSVM.setKernelType(new SelectedTag(LibSVM.KERNELTYPE_LINEAR, LibSVM.TAGS_KERNELTYPE));
    libSVM.setDegree(3);
    libSVM.setSVMType(new SelectedTag(LibSVM.SVMTYPE_C_SVC, LibSVM.TAGS_SVMTYPE));
    Evaluation eval4 = classify.runClassifier(libSVM, dataTrain, dataTest);
    System.out.println(eval4.toSummaryString() + "\n");
    System.out.println(eval4.toClassDetailsString() + "\n");
    System.out.println(eval4.toMatrixString() + "\n");
    System.out.println("===========================================================================");
}