Answering exactly the question,
You can use the embedded method toSource() to parse the tree structure to the rule.
Answering your subquestion, if I understood it, there is two methods that can get the result's components: prefix() and graph().
Another possibility is to extend the class or change the sources
to access the internal data structures.
Yet another option is to use a third party library like this:
J48Parser
Output from each method:
graph --------------
digraph J48Tree {
N0 [label="V2" ]
N0->N1 [label="<= 0.561"]
N1 [label="V2" ]
N1->N2 [label="<= -0.857"]
N2 [label="1 (1426.0/427.0)" shape=box style=filled ]
N1->N3 [label="> -0.857"]
N3 [label="V1" ]
N3->N4 [label="<= 0.155"]
N4 [label="2 (1149.0/180.0)" shape=box style=filled ]
N3->N5 [label="> 0.155"]
N5 [label="1 (1000.0/490.0)" shape=box style=filled ]
N0->N6 [label="> 0.561"]
N6 [label="1 (1716.0/487.0)" shape=box style=filled ]
}
prefix ---------------
[V2: <= 0.561,
> 0.561[V2: <= -0.857,
> -0.857[1 (1426.0/427.0)][V1: <= 0.155,
> 0.155[2 (1149.0/180.0)][1 (1000.0/490.0)]]][1 (1716.0/487.0)]]
toSource ---------------
class bla {
public static double classify(Object[] i)
throws Exception {
double p = Double.NaN;
p = bla.N37374a5e0(i);
return p;
}
static double N37374a5e0(Object []i) {
double p = Double.NaN;
if (i[1] == null) {
p = 1;
} else if (((Double) i[1]).doubleValue() <= 0.561) {
p = bla.N4671e53b1(i);
} else if (((Double) i[1]).doubleValue() > 0.561) {
p = 0;
}
return p;
}
static double N4671e53b1(Object []i) {
double p = Double.NaN;
if (i[1] == null) {
p = 0;
} else if (((Double) i[1]).doubleValue() <= -0.857) {
p = 0;
} else if (((Double) i[1]).doubleValue() > -0.857) {
p = bla.N2db7a79b2(i);
}
return p;
}
static double N2db7a79b2(Object []i) {
double p = Double.NaN;
if (i[0] == null) {
p = 1;
} else if (((Double) i[0]).doubleValue() <= 0.155) {
p = 1;
} else if (((Double) i[0]).doubleValue() > 0.155) {
p = 0;
}
return p;
}
}
classifier.toString()return? - Smutje