Example usage for weka.classifiers.functions SMO setOptions

List of usage examples for weka.classifiers.functions SMO setOptions

Introduction

In this page you can find the example usage for weka.classifiers.functions SMO setOptions.

Prototype

public void setOptions(String[] options) throws Exception 

Source Link

Document

Parses a given list of options.

Usage

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.featureextraction.AllFeaturesExtractor.java

License:Apache License

private Classifier getClassifier() throws Exception {
    Classifier cl = null;/*from   w  w w  . j  a  v  a  2s. c o m*/
    // Build and evaluate classifier
    // The options given correspond to the default settings in the WEKA GUI
    if (classifier.equals("smo")) {
        SMO smo = new SMO();
        smo.setOptions(Utils.splitOptions(
                "-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
        cl = smo;
    } else if (classifier.equals("j48")) {
        J48 j48 = new J48();
        j48.setOptions(new String[] { "-C", "0.25", "-M", "2" });
        cl = j48;
    } else if (classifier.equals("naivebayes")) {
        cl = new NaiveBayes();
    } else if (classifier.equals("randomforest")) {
        RandomForest rf = new RandomForest();
        rf.setOptions(Utils.splitOptions("-I 10 -K 0 -S 1"));
        cl = rf;
    }
    return cl;
}

From source file:elh.eus.absa.WekaWrapper.java

License:Open Source License

/**
 * @param traindata/*from w w w. j av  a 2  s. c  om*/
 * @param testdata
 * @param id : whether the first attribute represents de instance id and should be filtered out for classifying
 * @throws Exception
 */
public WekaWrapper(Instances traindata, Instances testdata, boolean id) throws Exception {

    // classifier
    weka.classifiers.functions.SMO SVM = new weka.classifiers.functions.SMO();
    SVM.setOptions(weka.core.Utils.splitOptions("-C 1.0 -L 0.0010 -P 1.0E-12 -N 0 -V -1 -W 1 "
            + "-K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
    setTraindata(traindata);
    setTestdata(testdata);

    // first attribute reflects instance id, delete it when building the classifier
    if (id) {
        //filter
        Remove rm = new Remove();
        rm.setAttributeIndices("1"); // remove 1st attribute
        // meta-classifier
        FilteredClassifier fc = new FilteredClassifier();
        fc.setFilter(rm);
        fc.setClassifier(SVM);
        setMLclass(fc);
    } else {
        setMLclass(SVM);
    }
}

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 a  2s  .com*/
        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;
    }
}

From source file:farm_ads.MyClassifier.java

public Classifier classifierSMO(Instances instances) throws Exception {
    SMO classifier = new SMO();
    classifier.setOptions(weka.core.Utils.splitOptions(
            "-C 1.0 -L 0.0010 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
    classifier.buildClassifier(instances);
    return classifier;
}

From source file:org.dkpro.similarity.algorithms.ml.ClassifierSimilarityMeasure.java

License:Open Source License

public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException {
    try {/*from  w w w.  j  ava 2s  .c o m*/
        switch (classifier) {
        case NAIVE_BAYES:
            return new NaiveBayes();
        case J48:
            J48 j48 = new J48();
            j48.setOptions(new String[] { "-C", "0.25", "-M", "2" });
            return j48;
        case SMO:
            SMO smo = new SMO();
            smo.setOptions(Utils.splitOptions(
                    "-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
            return smo;
        case LOGISTIC:
            Logistic logistic = new Logistic();
            logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1"));
            return logistic;
        default:
            throw new IllegalArgumentException("Classifier " + classifier + " not found!");
        }
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }

}

From source file:org.uclab.mm.icl.llc.config.RecognizerType.java

License:Apache License

/**
 * Returns the corresponding recognizer//from  www.j  a va 2s.c o  m
 * @param rec recognizer type to return
 * @param userID user ID to set
 * @return instance of the corresponding recognizer
 */
public LLCRecognizer getRecognizer(long userID) {

    RecognizerType rec = this.values()[value];
    switch (rec) {
    case SER:
        String[] labels = { "Anger", "Happiness", "Sadness" };
        String path = FileUtil.getRootPath() + "/training/modeldataV2.7.txt";
        SMO svm = new SMO(); // Define Classifier with Weka
        try {
            svm.setOptions(weka.core.Utils.splitOptions(
                    "-C 1.0 -L 0.0010 -P 1.0E-12 -N 1 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.RBFKernel -C 250007 -G 0.01\""));
            svm.setFilterType(new SelectedTag(SMO.FILTER_STANDARDIZE, SMO.TAGS_FILTER));
        } catch (Exception e) {
            e.printStackTrace();
        }
        ExtClassification classifier = new ExtClassification(path, 78 * 2, labels, svm);
        AudioEmotionRecognizer aer = new AudioEmotionRecognizer(classifier, path, userID);

        return aer;
    case ER:
        return new AudioEmotionRecognizerV(userID);
    case IAR:
        return new InertialActivityRecognizer(userID);
    case VAR:
        return new VideoActivityRecognizer(userID);
    case LR:
        //get user loc coord / label with userID by restful service
        return new GPSLocationRecognizer(userID);
    case FR:
        return new FoodRecognizer(userID);
    }
    return null;
}