How to show confidence attribute wit Naive Bayes operator

giannidiorio
giannidiorio New Altair Community Member
edited November 5 in Community Q&A
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.

Answers

  • land
    land New Altair Community Member
    Hi,
    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
  • tonio6
    tonio6 New Altair Community Member
    Ok so i didn't really understand what you were talking about...But i tried to get some results of the simple example set in the console of netbeans by using this command:

    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??
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    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