///////////////////////////////////////////////////////////////////////
// HOWTO: read ARFF file
//
Cell arff = new ArffReader();
System.out.println("Parameters available in ArffReader [default value]:");
System.out.print(arff.getAvailableParams());
arff.set("filename", "data/glass.arff");
arff.set("decisionAttr", "last"); // instead of "last" you can give attribute index, like "0", "1", ...
System.out.println("\nFirst 3 samples from ARFF file:");
arff.open();
System.out.println(arff.next());
System.out.println(arff.next());
System.out.println(arff.next());
arff.close();
///////////////////////////////////////////////////////////////////////
// HOWTO: train and use Rseslib classifier
//
Cell learner = new RseslibClassifier("C45");
learner.set("pruning", "true");
learner.setSource(arff);
learner.learn();
System.out.println("\nFirst sample classified by C45 from Rseslib:");
learner.open();
System.out.println(learner.next());
learner.close();
///////////////////////////////////////////////////////////////////////
// HOWTO: train and use Weka classifier
//
learner = new WekaClassifier("J48");
System.out.println("\nParameters available in J48 from Weka [default value]:");
System.out.print(learner.getAvailableParams());
learner.set("minNumObj", "2");
learner.setSource(arff);
learner.learn();
System.out.println("\nFirst sample classified by J48:");
learner.open();
System.out.println(learner.next());
learner.close();
///////////////////////////////////////////////////////////////////////
// HOWTO: apply Weka filter
//
Cell filter = new WekaFilter("attribute.Remove");
filter.set("attributeIndices", "2-6");
filter.setSource(arff);
System.out.println("\nFirst 3 samples from ARFF file after filtering:");
filter.open();
System.out.println(filter.next());
System.out.println(filter.next());
System.out.println(filter.next());
filter.close();
///////////////////////////////////////////////////////////////////////
// HOWTO: set and get parameters (2 methods)
//
// 1st method:
arff.set("filename", "data/glass.arff");
arff.set("decisionAttr", "last");
// 2nd method:
Parameters par = new Parameters();
par.set("filename", "data/glass.arff");
par.set("decisionAttr", "last");
arff.setParameters(par);
System.out.println("\nParameters of the ARFF reader:");
System.out.println(arff.getParameters());
///////////////////////////////////////////////////////////////////////
// HOWTO: evaluate a classifier through train & test
//
learner = new WekaClassifier("J48");
learner.set("confidenceFactor", "0.45");
EvaluatorCell tt = new TrainAndTest(learner);
tt.setSource(filter);
tt.set("repetitions", "10"); // run 10 independent trials of train & test
tt.set("trainPercent", "70"); // in each trial, use randomly selected 70% of data for training
tt.setRandomSeed(123); // fix random seed to use the same data splits in every run of tt.learn()
tt.learn(); // go!
System.out.println("\nResult of Train+Test:\n" + tt.report());
///////////////////////////////////////////////////////////////////////
// HOWTO: run cross-validation for a regression problem
//
// already done: Cell arff = new ArffReader();
arff.set("filename", "data/cloud.arff"); // decision attribute in cloud.arff is real-valued
arff.set("decisionAttr", "last");
learner = new WekaClassifier("SMOreg");
EvaluatorCell cv = new CrossValidation(learner);
cv.setSource(arff);
cv.set("folds", "5"); // 5-fold cross-validation
cv.set("score", "RMSE"); // use Root Mean Squared Error to measure quality
cv.learn();
System.out.println("\nResult of Cross-Validation: RMSE = " + cv.result()[0]);