Example usage for weka.classifiers CostMatrix toMatlab

List of usage examples for weka.classifiers CostMatrix toMatlab

Introduction

In this page you can find the example usage for weka.classifiers CostMatrix toMatlab.

Prototype

public String toMatlab() 

Source Link

Document

converts the Matrix into a single line Matlab string: matrix is enclosed by parentheses, rows are separated by semicolon and single cells by blanks, e.g., [1 2; 3 4].

Usage

From source file:etc.aloe.cscw2013.TrainingImpl.java

License:Open Source License

@Override
public WekaModel train(ExampleSet examples) {
    System.out.println("SMO Options: " + SMO_OPTIONS);
    SMO smo = new SMO();
    try {//from  w w  w  .j a  v a2s .  c  o  m
        smo.setOptions(Utils.splitOptions(SMO_OPTIONS));
    } catch (Exception ex) {
        System.err.println("Unable to configure SMO.");
        System.err.println("\t" + ex.getMessage());
        return null;
    }

    //Build logistic models if desired
    smo.setBuildLogisticModels(isBuildLogisticModel());

    Classifier classifier = smo;

    if (useCostTraining) {
        CostSensitiveClassifier cost = new CostSensitiveClassifier();
        cost.setClassifier(smo);
        CostMatrix matrix = new CostMatrix(2);
        matrix.setElement(0, 0, 0);
        matrix.setElement(0, 1, falsePositiveCost);
        matrix.setElement(1, 0, falseNegativeCost);
        matrix.setElement(1, 1, 0);
        cost.setCostMatrix(matrix);

        classifier = cost;

        System.out.print("Wrapping SMO in CostSensitiveClassifier " + matrix.toMatlab());

        if (useReweighting) {
            cost.setMinimizeExpectedCost(false);
            System.out.println(" using re-weighting.");
        } else {
            cost.setMinimizeExpectedCost(true);
            System.out.println(" using min-cost criterion.");
        }
    }

    try {
        System.out.print("Training SMO on " + examples.size() + " examples... ");
        classifier.buildClassifier(examples.getInstances());
        System.out.println("done.");

        WekaModel model = new WekaModel(classifier);
        return model;
    } catch (Exception ex) {
        System.err.println("Unable to train SMO.");
        System.err.println("\t" + ex.getMessage());
        return null;
    }
}