"[SOLVED] Integrating RapidMiner into Java Application - Beginner's Questions"

MerlotMerlot Member Posts: 12 Contributor II
edited June 2019 in Help
Dear all,

i just started to work with RapidMiner some days ago. I'd like to integrate RM into an existing Java Application, which offers all data I need for the classification task in RM. So, I created an ExampleSet within my Java Application according to the last section in http://rapid-i.com/wiki/index.php?title=Integrating_RapidMiner_into_your_application.

I know that I have to model my process within the RM GUI and export it as XML file which can be passed to RM later in my Java Application. My question is how to model the data import in RM GUI. What should I insert instead of my Retrieve Operator (from repository), so that I can add my ExampleSets directly from my Java Application into the operators.

Thanks in advance.

Best regards
Merlot
Tagged:

Answers

  • Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,993 RM Engineering
    Hi,

    you can draw a line (or several) from the input port(s) to your data. Then you can just hand over these IOObjects when you execute the process. See here for details.

    Regards,
    Marco
  • MerlotMerlot Member Posts: 12 Contributor II
    Hi Marco,

    sometimes, it can be so simple.

    Thank you!

    Regards
    Merlot
  • MerlotMerlot Member Posts: 12 Contributor II
    Hi again,

    i got my next problem.Β  ;D

    I managed to get my code working with an ExampleSet which uses double values only:
    public class RapidMinerCreateExample {

    static ExampleSet exampleSet;

    public RapidMinerCreateExample(RapidMinerCreateExampleTest example) {

    List<Attribute> attributes = new LinkedList<Attribute>();

    for(int i = 0; i < example.getNumOfAttributes(); i++) {

    attributes.add(AttributeFactory.createAttribute("att" + i, Ontology.STRING));

    }

    Attribute label = AttributeFactory.createAttribute("label", Ontology.BINOMINAL);
    attributes.add(label);

    MemoryExampleTable table = new MemoryExampleTable(attributes);

    for(int i = 0; i < example.getNumOfDataRows(); i++) {

    double[] data = new double[attributes.size()];

    for(int j = 0; j < example.getNumOfAttributes(); j++) {

    data = example.getValue(i, j);

    }

    data[data.length - 1] = label.getMapping().mapString(example.getClassification(i));
    table.addDataRow(new DoubleArrayDataRow(data));

    }

    exampleSet = table.createExampleSet(label);

    }

    public ExampleSet getExampleSet() {

    return exampleSet;

    }

    }
    Now, I want to use a String attribute instead of a double attribute, but there seems to be no DataRow implementation for String attributes.

    The solution might be as simple as the solution for my first beginner's question. It would be very nice if you could help me again.

    Regards
    Merlot
  • StaryVenaStaryVena Member Posts: 126 Contributor II
    Hi,
    use DataRowFactory class http://rapid-i.com/api/rapidminer-5.1/com/rapidminer/example/table/DataRowFactory.html it can handle Object array, so it can be combined - number and string together.

    Cheers,
    Vaclav
  • MerlotMerlot Member Posts: 12 Contributor II
    Hi StaryVena,

    thank you very much.

    Now, I got managed to make RapidMiner working in my own Java Application. My next step was to separate the steps "generate model" and "apply model". Using a ModelWriter, I am able to store a model learned with labeled training data on my hard disk. Now I want to apply this stored model to unlabeled test data. So I created another process within the GUI and stored it as xml File.

    I assume that I have to connect the model input port of my "Apply Model" operator to the second Main process input port in RM GUI to access the stored model. Is it right?

    image

    How do I load the model into RM within my Java Source Code? I found a ModelLoader, but don't know how to use it properly.* Are there any source code examples available? (More generelly, are there tutorials or instructions on how to integrate RM in Java Applications as I had to do quite a lot of research to find all pieces I needed to integrate RM.)

    * All Google results I found on this topic refer to RapidMiner 4. I am looking for a code example working with RM 5's API.

    Thanks to all of you having a look at my beginner's questions.

    Regards
    Merlot

    EDIT: I found another way to realize the model import. I created a "read model" operator in RM GUI and set the model's filename as fixed parameter. So I don't need to set the filename in my Java source code. Nevertheless, I'm interested on how to set the model's filename directly in the Java source code.
  • StaryVenaStaryVena Member Posts: 126 Contributor II
    Hi,
    if you have model in some file, first read it:

    IOObject model = (IOObject) IOObjectSerializer
    .getInstance().deserialize(
    RecommenderService.class
    .getResourceAsStream("path/to/file/model.ioo"));
    than you can pass it to RM - http://rapid-i.com/rapidforum/index.php/topic,4312.0.html

    Some more codes are here - http://rapid-i.com/rapidforum/index.php/topic,3596.msg13398.html

    Cheers
    Vaclav
  • MerlotMerlot Member Posts: 12 Contributor II
    Hi,

    I didn't try your solution as I save my model in the respository now. Nervertheless, thank you very much!

    Cheers
    Merlot
Sign In or Register to comment.