Mulitlayer Perceptron prediction result not only as a double, also as String (using Weka (Java))

27 views Asked by At

I would like to make a prediction using multilayer perceptron. For this purpose, I have created test data to be predicted. Now I go through all records in a for loop and want to append the prediction:

for (int i1 = 0; i1 < datapredict1.numInstances(); i1++) {      
            double clsLabel1 = mlp.classifyInstance(datapredict1.instance(i1));
            datapredict1.instance(i1).setClassValue(clsLabel1); 
            String s = datapredict1.instance(i1) + "," + clsLabel1;
            writer11.write(s.toString());
            writer11.newLine();
            System.out.println(datapredict1.instance(i1) + "," + clsLabel1);
        }

The result output is as follows:
0.178571,0.2,0.181818,0.333333,0,09:15,0.849899,0.8498991728827364 0.414835,0,0.454545,0.666667,0,16:15,0.850662,0.85066198399766

How is it possible that here, not only the probability is displayed, but also the string value As for example: 0.178571,0.2,0.181818,0.333333,0,09:15,"Value2",0.8498991728827364 0.414835,0,0.454545,0.666667,0,16:15,"Value4",0.85066198399766

1

There are 1 answers

0
fracpete On

The classifyInstance method of a classifier returns the regression value for numeric class attributes or the index of the most likely class label for nominal ones.

In the latter case, cast the returned double to an int and use the value(int) method of the class attribute of your dataset to obtain the label string.