Applying a saved model to real time data in JAVA [SOLVED]
aws
New Altair Community Member
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
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
0
Answers
-
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
Alternatively, if you don't want to use the repository:
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
}
}
InputStream is = myClassObject.getClass().getResourceAsStream("/myProcess.rmp");
String xML = Tools.readTextFile(is);
Process process = new Process(xML);
Regards,
Marco0 -
Thanks for your reply. It's working fine.0