Example usage for weka.core.converters LibSVMLoader setSource

List of usage examples for weka.core.converters LibSVMLoader setSource

Introduction

In this page you can find the example usage for weka.core.converters LibSVMLoader setSource.

Prototype

@Override
public void setSource(InputStream in) throws IOException 

Source Link

Document

Resets the Loader object and sets the source of the data set to be the supplied InputStream.

Usage

From source file:cish.CISH.java

private void trainClassifier() {
    try {//w  w  w .j  a v a 2  s .  c om
        LibSVMLoader loader = new LibSVMLoader();
        loader.setSource(getClass().getResource("/cish/traindata.libsvm"));
        Instances traindata = loader.getDataSet();

        // Set the class attribute as nominal
        NumericToNominal filter = new NumericToNominal();
        filter.setAttributeIndices("last");
        filter.setInputFormat(traindata);
        dataset = Filter.useFilter(traindata, filter);

        // Train the LibSVM
        classifier = new LibSVM();
        classifier.setOptions(new String[] { "-C", "8", "-G", "0.0625" });

        System.out.println("CISH classifier has options");
        for (String o : classifier.getOptions()) {
            System.out.print(o + " ");
        }
        System.out.println();

        classifier.buildClassifier(dataset);

    } catch (IOException ex) {
        Logger.getLogger(CISH.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(CISH.class.getName()).log(Level.SEVERE, null, ex);
    }
}