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.
- /* Load data */
- Dataset data = FileHandler.loadDataset(new File("iris.data"), 4, ",");
- /* Create Weka classifier */
- SMO smo = new SMO();
- /* Wrap Weka classifier in bridge */
- Classifier javamlsmo = new WekaClassifier(smo);
- /* Initialize cross-validation */
- CrossValidation cv = new CrossValidation(javamlsmo);
- /* Perform cross-validation */
- Map<Object, PerformanceMeasure> pm = cv.crossValidation(data);
- /* Output results */