Search code examples
javawekamoa

Sample code use for (moa PairedLearners)


Hello I am new into using MOA and WEKA,

I need to test paired learners concept using this code and I have been able to locate the code but I cannot find any example online and I am having a hard time figuring how to pas my data into the code and run a test and see my results. Pls can anyone point my in a right direction or give me a few pointers that I could follow to implement this.

moa/moa/src/main/java/moa/classifiers/meta/PairedLearners.java

Trying to use a similar code like this: https://groups.google.com/forum/#!topic/moa-development/3IKcguR2kOk

Best Regards. //Sample code below

import moa.classifiers.meta.pairedLearner;

Public class SamplePairedlearner{
public static void main(String[] args) {
    FileStream fStream = new FileStream();
    fStream.arffFileOption.setValue("test.arff");// set the ARFF file name
    fStream.normalizeOption.setValue(false);// set normalized to be true or false
    fStream.prepareForUse();
int numLines = 0;
PairedLearner learners = PairedLearners();
learners.resetLearning();
learners.resetLearningImpl(); //this is where i get an error message
ClusteringStream stream = fStream;
    while (stream.hasMoreInstances()) {
        Instance curr = stream.nextInstance().getData();
        learners.trainOnInstanceImpl(curr)//this line also generates an error
        numLines++;
    }
    Clustering resDstream = dstream.getClusteringResult();
    dstream.getMicroClusteringResult();
    System.out.println("Size of result from Dstream: " + resDstream.size());
    System.out.println(numLines + " lines have been read");
}
}

Solution

  • I could fix the code that you have there, but it wouldn't do you much good. MOA has it's own selection of tasks and evaluators for running these experiments at a much higher level. This is how to run evaluations properly and not dive too deeply into the code. I'll assume a few things:

    1. We use PairedLearners as our classifier.
    2. We evaluate stream classification performance.
    3. We evaluate in predictive sequential (prequential) fashion, i.e. train, then test on each example in the sequence.

    Therefore, we can define our task quite simply, as follows.

    public class PairedLearnersExample {
    
        public static void main(String[] args) {
    
            ArffFileStream fs = new ArffFileStream(PairedLearnersExample.class.getResource("abalone.arff").getFile(), -1);
            fs.prepareForUse();
    
            PairedLearners learners = new PairedLearners();
    
            BasicClassificationPerformanceEvaluator evaluator = new BasicClassificationPerformanceEvaluator();
    
            EvaluatePrequential task = new EvaluatePrequential();
            task.learnerOption.setCurrentObject(learners);
            task.streamOption.setCurrentObject(fs);
            task.evaluatorOption.setCurrentObject(evaluator);
    
            task.prepareForUse();
    
            LearningCurve le = (LearningCurve) task.doTask();
    
            System.out.println(le);
    
        }
    
    }
    

    If you want to do other tasks, you can quite happily swap out the evaluator, stream and learner to achieve whatever it is you want to do.

    If you refer to the MOA Manual you'll see that all I'm doing is imitating the command line commands - you could equally perform this evaluation at the command line if you wished.

    For example,

    java -cp .:moa.jar:weka.jar -javaagent:sizeofag.jar moa.DoTask \
    "EvaluatePrequential -l PairedLearners \
    -e BasicClassificationPerformanceEvaluator \
    -s (ArffFileStream -f abalone.arff) \
    -i 100000000 -f 1000000" > plresult_abalone.csv