Weka classifier

Classification algorithms from Weka can be accessed from within Java-ML and used the same way as the native algorithms by using the WekaClassification bridge. This class can be wrapped around Weka classifiers and makes them transparently available to Java-ML based programs.

In the example below, we first load the iris data set. Next, we create a SMO support vector machine from Weka with default settings. Then, we wrap the SMO in the WekaClassifier bridge. Finally, we perform cross-validation on the classifier and write out the results.

  1. /* Load data */
  2. Dataset data = FileHandler.loadDataset(new File("iris.data"), 4, ",");
  3. /* Create Weka classifier */
  4. SMO smo = new SMO();
  5. /* Wrap Weka classifier in bridge */
  6. Classifier javamlsmo = new WekaClassifier(smo);
  7. /* Initialize cross-validation */
  8. CrossValidation cv = new CrossValidation(javamlsmo);
  9. /* Perform cross-validation */
  10. Map<Object, PerformanceMeasure> pm = cv.crossValidation(data);
  11. /* Output results */
  12. System.out.println(pm);

[Documented source code]