Options

Getting a null pointer while trying to write a model using ModelWriter

Legacy UserLegacy User Member Posts: 0 Newbie
edited November 2018 in Help
Hello,

I am trying to use rapidminer as a library. I'm trying something very simple to begin with. I read in a training data set, generate a model, and write the model out. I have been successful in doing this in the GUI, but it seems to fail when I try to do it progmatically. Here is my code:

public class Collect
{
public static void main(String[] args)
{
RapidMiner.init();
try
{
Operator input = OperatorService.createOperator(ArffExampleSource.class);
input.setParameter("data_file", "/home/vahid/Desktop/c_training.arff");
input.setParameter("label_attribute", "change");

IOContainer io = input.apply(new IOContainer());
ExampleSet exampleSet = io.get(ExampleSet.class);

Learner learner = (Learner) OperatorService.createOperator(NaiveBayes.class);
Model model = learner.learn(exampleSet);

ModelWriter writer = (ModelWriter) OperatorService.createOperator(ModelWriter.class);
writer.setParameter("model_file", "/home/model.mod");
writer.setParameter("overwrite_existing_file", "true");
writer.setParameter("output_type", "XML");

writer.apply();
}
catch (OperatorCreationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperatorException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I tried to follow the manual when writing that code. Here is the error produced

Exception in thread "main" java.lang.NullPointerException
at com.rapidminer.operator.Operator.getInput(Operator.java:821)
at com.rapidminer.operator.Operator.getInput(Operator.java:802)
at com.rapidminer.operator.io.ModelWriter.apply(ModelWriter.java:96)
at Collect.main(Collect.java:33)

Any help is appreciated

Answers

  • Options
    steffensteffen Member Posts: 347 Maven
    Jumping by...

    I think you forgot to tell the ModelWriter what to write out. Try this (not tested):

    model.apply(new IOContainer(new IOObject[]{model}));
    regards,

    Steffen
  • Options
    Legacy UserLegacy User Member Posts: 0 Newbie
    Yes i thought about that. The problem is model is a Model object and Model.apply takes an ExampleSource as a parameter, not an IOContainer.  I think model.apply(ExampleSource) will be used when I load the model and want to aplly it to some data.

    Thanks for the help though!
  • Options
    steffensteffen Member Posts: 347 Maven
    AAhhhhhhhhhh typo, me sorry

    What I meant was:

    writer.apply(new IOContainer(new IOObject[]{model}));
    It is no good idea to think about this stuff so late in the evening.  :(

    regards,

    Steffen
Sign In or Register to comment.