Friday, January 31, 2014

Decision Tree Generator (Implementation in Javascript)

Recently I tried making a simple Decision Tree Generator not because it wasn't there before but as a fun project to engage myself and learn abit of Javascript and also to know HTML5 Canvas a little more :)

fig: Output of Decision Tree Generator

What's so good about it?

Well there's not much to say, but hear it out anyway :D

1. Automatic Generator:
It gathers data, and automatically generates tree based on the data. Though I haven't tested it thoroughly, it worked for two of my example sets (that's good enough right ;) ? )

2. Interactive:
I have tried my best to make it as interactive as possible. I have added a bit of Jquery to make it more interesting :D

3. ID3 Algorithm Implementation:
It implements ID3 Algorithm for Decision Tree generation. More on the algorithm? Follow the link : Wikipedia

4. Source Code:
I have uploaded the project in github, so feel free to browse and help me with updates and suggestion. Here is the link: Project Source

How does it work?

Well, it takes your data as input. The data must be discrete and must contain a  class ( outcome ). The algorithm begins with data set 'S' as the root node. On each iteration of the algorithm, it loops through every unused attribute of 'S' and calculates the entropy H(S) (or information gain IG(A)) for that attribute.

Then selects the attribute which has the smallest entropy (or largest information gain) value. The set 'S' is then split by the selected attribute to produce subsets of the data. The algorithm continues to recurse on each subset, considering only attributes never selected before.

Wanna see it live?

Decision Tree Generator is live, here is the link: DecisionTree Generator


Post a Comment