"how to write my JAVA application by learning the XML from RM"

gfyang
gfyang New Altair Community Member
edited November 5 in Community Q&A
Hi, I am beginning to integrate RM into my own application.
First of all,  I want to implement the following by  java codes,

<operator name="Root" class="Process" expanded="yes">
    <operator name="ArffExampleSource" class="ArffExampleSource">
        <parameter key="data_file" value="../data/iris.arff"/>
        <parameter key="label_attribute" value="class"/>
    </operator>
    <operator name="SimpleValidation" class="SimpleValidation" expanded="yes">
        <operator name="NaiveBayes" class="NaiveBayes">
        </operator>
        <operator name="ApplierChain" class="OperatorChain" expanded="yes">
            <operator name="Test" class="ModelApplier">
                <list key="application_parameters">
                </list>
            </operator>
            <operator name="Performance" class="Performance">
            </operator>
        </operator>
    </operator>
</operator>
This is what I know:

RapidMiner.init();

//read the data
Operator inputData = OperatorService.createOperator(ArffExampleSource.class);
inputData.setParameter("data_file", "C:/data/iris.arff");
inputData.setParameter("label_attribute", "class");
IOContainer container = inputData.apply(new IOContainer());

//build the model
OperatorChain simpleValidate =
(OperatorChain) OperatorService.createOperator("SimpleValidation");
OperatorChain applierChain =
(OperatorChain) OperatorService.createOperator("ApplierChain");

Operator naiveBayes = OperatorService.createOperator("NaiveBayes");
Operator test = OperatorService.createOperator("ModelApplier");
Operator performance = OperatorService.createOperator("Performance");

applierChain.addOperator(test);
applierChain.addOperator(performance);
simpleValidate.addOperator(naiveBayes);
simpleValidate.addOperator(applierChain);
Of course, it does not work. How could I really make the application run? That is, inputting data, validating naive bayes, and then outputting the accuracy?

Thank you very much.

Answers

  • steffen
    steffen New Altair Community Member
    Hello gfyang

    There is a file called "rapidminer-<version>-tutorial.pdf" which you download from the rapidminer page at sourceforge (http://sourceforge.net/projects/yale/files/). In this you can find a chapter "Integrating RapidMiner into your application" where everything is explained.

    If you have further questions, do not hesitate to ask.

    regards,

    Steffen
  • gfyang
    gfyang New Altair Community Member
    Hi, Steffen,

    Thanks a lot for the reply. I have found the tutorial, and it is very helpful.

    I build a complete process. However, I do not know how to get the value of the testing result (not from the console).
    For example,

    RapidMiner.init();

    Process process = new Process();

    //read the data
    Operator inputData = OperatorService.createOperator(ArffExampleSource.class);
    inputData.setParameter("data_file", "C:/data/iris.arff");
    inputData.setParameter("label_attribute", "class");

    //build the model
    OperatorChain simpleValidate =
    (OperatorChain) OperatorService.createOperator("SimpleValidation");
    Operator naiveBayes = OperatorService.createOperator("NaiveBayes");
    OperatorChain applierChain =
    (OperatorChain) OperatorService.createOperator("OperatorChain");
    Operator test = OperatorService.createOperator("ModelApplier");
    Operator performance = OperatorService.createOperator("Performance");
    applierChain.addOperator(test);
    applierChain.addOperator(performance);
    simpleValidate.addOperator(naiveBayes);
    simpleValidate.addOperator(applierChain);

    process.getRootOperator().addOperator(inputData);
    process.getRootOperator().addOperator(simpleValidate);

    // how to get the accuracy?
    // double accuracy = ???

    return process;
    The accuracy is stored in PerformanceVector, but how to println this double value?

    Sincerely yours,
    gfyang
  • steffen
    steffen New Altair Community Member
    Hello gfyang

    process.run().get(PerformanceVector.class).getCriterion("accuracy").getAverage();
    I you want to use the accuracy within the process, you have to implement your own operator (for this task there is also a chapter in the tutorial) and retrieve the performancevector from this operator's input.

    regards,

    Steffen
  • gfyang
    gfyang New Altair Community Member
    Thank you very much  :)