The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

Applying a saved model to real time data in JAVA [SOLVED]

awsaws Member Posts: 10 Contributor II
edited November 2018 in Help
Good afternoon,

I am trying to understand how to use the RM JAVA API. My example is quite easy: I trained a classification model in the RM GUI and saved it to disk.

Now, I would like to load the model and apply it to some data stored in an array in JAVA. I was able to create an ExampleSet from the array and to create operators of the classes ModelLoader and ModelApplier. Also the connection from the ML output port to the MA model port is established.

1.) How do I connect the ExampleSet to the ModelApplier?
2.) When looking through the forum, I have already learned that building processes is no more state of the art. One can load the complete XML code and run it in JAVA. However, the descriptions of how to do this were to vague for me to turn them into JAVA code.
3.) Even if I am able to let the XML code run, how can I connect my data from the array to the XML code?

I am looking forward to your answers.

Best regards,
 Alex

Tagged:

Answers

  • Marco_BoeckMarco_Boeck Administrator, Moderator, Employee-RapidMiner, Member, University Professor Posts: 1,996 RM Engineering
    Hi,

    I have posted the information you seek more than once before, but here we go again:

    1) Build your process in RapidMiner via the GUI. Save it to your repository (or don't and just save the XML somewhere).
    2) Load the process via java
    3) give the process input IOObjects (e.g. your model, your data, etc (note that the process input ports have to be connected to the appropriate operators!)
    4) run the process and store the result

    RepositoryLocation location;
    RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
    RapidMiner.init();
    try {
    location = new RepositoryLocation("//LocalRepository/Test/MyProcessName");
    Entry entry = location.locateEntry();
    if (entry instanceof ProcessEntry) {
    Process process = new RepositoryProcessLocation(location).load(null);
    IOContainer resultContainer = process.run(new IOContainer(new LinkedList<IOObject>())); // instead of creating an empty list with IOObjects here, you need to create the list before and fill it with the stuff you need
    }
    }
    Alternatively, if you don't want to use the repository:

    InputStream is = myClassObject.getClass().getResourceAsStream("/myProcess.rmp");
    String xML = Tools.readTextFile(is);
    Process process = new Process(xML);

    Regards,
    Marco
  • awsaws Member Posts: 10 Contributor II
    Thanks for your reply. It's working fine.
Sign In or Register to comment.