Options

Loading models in Java using RapidMiner 9.7

philipp_ginselphilipp_ginsel Member Posts: 2 Contributor I
Hello,

we are using RapidMiner in our Java-project (https://github.com/igorvatolkin/AMUSE). We are currently using version 5.3 and are trying to update to the latest version (9.7).
At one point in the project we load a previously trained ".mod"-model-file in order to classify new data with it. In order to do that we use the class "com.rapidminer.operator.io.ModelLoader". When I downloaded the new Rapidminer version I noticed that this class no longer exists. Is there a way to do the same thing using another class with Rapidminer 9.7? Unfortunately I was no able to find anything about this problem and I am hoping that you can help me.

Our code looks like this (I excluded the parts that don't have anything to do with the problem and are specific to our project):


import com.rapidminer.Process;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.ModelApplier;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.io.ModelLoader;
import com.rapidminer.operator.ports.InputPort;
import com.rapidminer.operator.ports.OutputPort;
import com.rapidminer.tools.OperatorService;

    .
    .
    .
   
Process process = new Process();

// (1) Create ExampleSet

    .
    .    //code that creates the ExampleSet exampleSet that should be classified
    .

           
// (2) Load the model
Operator modelLoader = OperatorService.createOperator(ModelLoader.class);
modelLoader.setParameter(ModelLoader.PARAMETER_MODEL_FILE, pathToModelFile);
process.getRootOperator().getSubprocess(0).addOperator(modelLoader);

// (3) Apply the model
Operator modelApplier = OperatorService.createOperator(ModelApplier.class);
process.getRootOperator().getSubprocess(0).addOperator(modelApplier);

// (4) Connect the ports
InputPort modelApplierModelInputPort = modelApplier.getInputPorts().getPortByName("model");
InputPort modelApplierUnlabelledDataInputPort = modelApplier.getInputPorts().getPortByName("unlabelled data");
OutputPort modelLoaderOutputPort = modelLoader.getOutputPorts().getPortByName("output");
OutputPort processOutputPort = process.getRootOperator().getSubprocess(0).getInnerSources().getPortByIndex(0);

modelLoaderOutputPort.connectTo(modelApplierModelInputPort);
processOutputPort.connectTo(modelApplierUnlabelledDataInputPort);

// (5) Run the process
process.run(new IOContainer(exampleSet));


Thank you very much for your help.
Philipp

Tagged:

Best Answer

Answers

  • Options
    philipp_ginselphilipp_ginsel Member Posts: 2 Contributor I
    Thank you very much for your answer. That seems to be exactly what I was looking for. I'm sorry that it took so long for me to answer. I wanted to test the solution before answering. But unfortunately I'm still having some other problems (that have nothing to do with this particular question), which is why I couldn't really test it yet.
  • Options
    jczogallajczogalla Employee, Member Posts: 144 RM Engineering
    Hi Philipp,
    glad to hear that this already helped. Good luck with the rest of the project!

    Cheers
    Jan
  • Options
    mertcatarmertcatar Member Posts: 7 Contributor I
    Hello, I am taking this same error, how can i get rid of this? @jczogalla
Sign In or Register to comment.