Due to recent updates, all users are required to create an Altair One account to login to the RapidMiner community. Click the Register button to create your account using the same email that you have previously used to login to the RapidMiner community. This will ensure that any previously created content will be synced to your Altair One account. Once you login, you will be asked to provide a username that identifies you to other Community users. Email us at Community with questions.
How to show confidence attribute wit Naive Bayes operator
giannidiorio
Member Posts: 2 Contributor I
Hi to everyone,
I have a little problem, I'm trying to implement the learner operator Naive Bayes using the rapid miner API (in java using Net Beans). My code is:
MemoryExampleTable table = new MemoryExampleTable(attributes);
table.addDataRow(new DoubleArrayDataRow(context));
IOContainer container = new IOContainer(new IOObject[]{table.createExampleSet(label)});
container = container.append(model);
Operator applier = OperatorService.createOperator(ModelApplier.class);
container = applier.apply(container);
ExampleSet result = container.get(ExampleSet.class);
Attribute predictedLabel = result.getAttributes().getPredictedLabel();
double prediction = Double.parseDouble(result.iterator().next().getNominalValue(predictedLabel));
I'm trying to show the confidence attribute of the prediction but I don't know how to do it, I implemented this code:
double values[] = new double [100];
Iterator<Attribute> it = result.getAttributes().allAttributes();
int i = 0;
while(it.hasNext()) {
Example e = result.getExample(0);
values = e.getValue(it.next());
i++;
System.out.println(values);
}
but the output is all zeros;
Anyone know how can I take information about the confidence attribute? I tried also this method:
Attribute confidence = result.getAttributes().getSpecial("confidence(0)");
but the result is null.
Thank you for your help.
I have a little problem, I'm trying to implement the learner operator Naive Bayes using the rapid miner API (in java using Net Beans). My code is:
MemoryExampleTable table = new MemoryExampleTable(attributes);
table.addDataRow(new DoubleArrayDataRow(context));
IOContainer container = new IOContainer(new IOObject[]{table.createExampleSet(label)});
container = container.append(model);
Operator applier = OperatorService.createOperator(ModelApplier.class);
container = applier.apply(container);
ExampleSet result = container.get(ExampleSet.class);
Attribute predictedLabel = result.getAttributes().getPredictedLabel();
double prediction = Double.parseDouble(result.iterator().next().getNominalValue(predictedLabel));
I'm trying to show the confidence attribute of the prediction but I don't know how to do it, I implemented this code:
double values[] = new double [100];
Iterator<Attribute> it = result.getAttributes().allAttributes();
int i = 0;
while(it.hasNext()) {
Example e = result.getExample(0);
values = e.getValue(it.next());
i++;
System.out.println(values);
}
but the output is all zeros;
Anyone know how can I take information about the confidence attribute? I tried also this method:
Attribute confidence = result.getAttributes().getSpecial("confidence(0)");
but the result is null.
Thank you for your help.
Tagged:
0
Answers
the method exampleSet.getAttributes().getConfidence(labelValue) is your friend.
Of course it only delivers the attribute if such an attribute exists. It is created when applying a Prediction Model.
Greetings,
Sebastian
System.out.println(ioResult.getElementAt(2).toString());
and it worked.It just shows some data that i am not thaaaat interested into though.
Before that i had :
ExampleSet resultSet = (ExampleSet) ioResult.getElementAt(0);
ExampleTable mytable = resultSet.getExampleTable();
for (int i = 0; i < mytable.size() - 1; i++) {
Example example = resultSet.getExample(i);
Attribute predict = example.getAttributes().get("prediction(label)");//we ony get the prediction column
String resultString = example.getValueAsString(predict);
textArea1.setText(textArea1.getText() + "\nPrediction is : " + resultString + "\n");//we show the result in the window
}
I keep getting the "simpledistributionmodel cannot cast to example set" whenever i use example set somewhere.I just need to show the prediction label of the example set results in a text area...how can i do that??
the result of a process is an IOContainer. This container contains all the different results (the data objects which are connected to output ports of your process). Thus if for example your first output port contains an ExampleSet, you can cast the element at position 0 to (ExampleSet). If it is a model, you need to cast it to the given model, etc.
In your process you need to connect the example set output to a process result port and use that in your code. Currently you are looking at the location where you return the model, not the example set.
Regards,
Marco