juliardi / C45

C4.5 Implementation in PHP
MIT License
20 stars 8 forks source link

Retrieve the entropy and gain #2

Closed fanboykun closed 1 year ago

fanboykun commented 2 years ago

Hiii, i found this package really helpfull, but i need to get the value of entropy and gain. Is there any way to retrieve the entropy and gain? Thank you

juliardi commented 2 years ago

From the current code, no. The method to calculate entropy and gain is available at https://github.com/juliardi/C45/blob/master/src/Calculator/GainCalculator.php. But, they are private methods, so it can't be called from outside that class. Do you have any suggestion on how to retrieve them? Maybe save it to array first so it can be retrieved later, but I have not think of the concrete strategy.

fanboykun commented 2 years ago

As i follow from the manual calculation of the algorithm, i think we need to separate each node's calculation in order to retrieve the entropy and gain. I mean instead of just returning the tree, how about returning what's inside each node.

I don't know if it is a good idea, but this is the best i can say

juliardi commented 2 years ago

The C45\C45::buildTree() method actually returns an instance of C45\TreeNode class, which basically is a root node of the whole tree. So you can traverse to every node from that instance. But, currently, it doesn't store the gain and entropy value for each calculation.