Getting a null pointer while trying to write a model using ModelWriter
Legacy User
New Altair Community Member
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:
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:
I tried to follow the manual when writing that code. Here is the error produced
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();
}
}
}
Any help is appreciated
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)
Tagged:
0
Answers
-
Jumping by...
I think you forgot to tell the ModelWriter what to write out. Try this (not tested):
regards,
model.apply(new IOContainer(new IOObject[]{model}));
Steffen
0 -
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!0 -
AAhhhhhhhhhh typo, me sorry
What I meant was:
It is no good idea to think about this stuff so late in the evening.
writer.apply(new IOContainer(new IOObject[]{model}));
regards,
Steffen0