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

Decision tree classification without process in JAVA

justinkrausejustinkrause Member Posts: 3 Contributor I
edited June 2019 in Help

Hi,

I don't know why my previous post has been deleted.

 

Using Java I want to load a trained model (decision tree) via ModelLoader and ModelApplier. Once loaded

I want to classify data without using a process because using a process means having to reload the model,

but I need a funtion like this:

 

private String classify(double[] data){

//Classification

return classification;

}

 

Right now I created two Operators (ModelLoader and ModelApplier) and connected the input to the output port.

But which operator do I have to use for my example data? I thought I can then connect the example data's operator's

output port to the ModelApplier input port and then just call modelApplier.execute().

 

Does it work like this? And how can I display the classification string?

 

Thanks in advance.

 

Answers

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    Let me try to understand, you want to score your data using the java code for the operators without running Studio? Why not just use the Server? Build your processes in Studio and off load them there. 

  • justinkrausejustinkrause Member Posts: 3 Contributor I

    Hey, thank you for your answer.

    We want to keep it as easy as possible and don't want to use the server edition. Later we want to train any model and load it into our application.

    And we want to classify our data in our application given this model.

     

    This is what I have right now:

     

    RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
    RapidMiner.init();

     

    Operator modelReader = OperatorService.createOperator(ModelLoader.class);
    modelReader.setParameter("model_file", "C:/Users/birdman/Desktop/TreeModel.mod");

    Operator modelApplier = OperatorService.createOperator(ModelApplier.class);
    InputPort inApply = modelApplier.getInputPorts().getAllPorts().get(0);
    modelReader.getOutputPorts().getAllPorts().get(0).connectTo(inApply);

    modelReader.execute();

    modelApplier.execute();

     

    Now I need an operator which has an output linking to the modelApplier's input to generate a classification.

     

    How is this possible? Any ideas?

     

     

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    Ok, maybe someone else can chime in here ( @land ) because I'm not the command line expert but it appears you are loading your model and using a model applier (Apply Model) for scoring. You are 2/3's of the way there in a basic scoring scenario. You will need an operator to load your scoring data and then connect it to the model applier.   The data could from a local RapidMiner data source like a Store operator or you can get it from a database via the Read Database operator, or even via an XLS file using the Read XLS operator. You can't score with our some input data, a model appliear, and of course your trainined model.

     

    PS: this all assumes that you're scoring data set is pre-processed in the same way as your training set (i.e. normalizations, same # and type of attributes, etc).

  • bhupendra_patilbhupendra_patil Employee-RapidMiner, Member Posts: 168 RM Data Scientist

    Too late and I am not sure if I understand the whole setup correctly,

     

    but your simplest option will be 

    1) Build a process that trains and saves a model file

    2) Build another process that uses the model saved by process 1 and applies it to whatever data set

     

    Now rather than creating modelbuilder and modelapplier as two sepeate java classes, you just create a process exector class.

    It wil be some sort of wrapper to call RM process using java code or command line,

     

    This will be most generic way to integrate, you can now obviously create process for anything and and call it from your java code.

     

    BTW there is a free version of server now, so definitely worth checking.

     

Sign In or Register to comment.