Skip to content

ilimugur/dectree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Important Note: If you intend to use DecTree.py for any purposes, you should keep in mind that it was implemented as part of an assignment given in course CENG562 of METU. Consequently, due to certain requirements in the assignment specifications, this implementation is known to be quite inefficient. Some of its problems include usage of redundant memory, usage of not-so-appropriate data structures, and handling certain operations in a suboptimal manner. I may try and update this code to solve the issues I mentioned, but until then, you are advised against using this code for anything critical.

Description

The DecTree.py file contains a Decision Tree implementation which can be used through terminal. It is an implementation of the ID3 algorithm described in Machine Leaning book by Tom Mitchell.

It can build the decision tree and output a .dot formatted file for further use. It uses the text version of the input format used by AIspace Decision Tree Tool, which is quite similar to CSV format, and can handle both training instances and test cases.

If any test cases are provided as part of the input, DecTree.py tries to correctly classify each test example and keeps a log of its effort, in which any failures in classification, such as a test example trying to get to a non-existing branch in the decision tree, are reecorded, along with the overall test performance. It can also print a text-based histogram for each node in the graph, as part of the label for the node.

Details regarding how to utilize DecTree.py are given below.

Execution

In order for any machine to be able to execute DecTree.py, an up-to-date version of Python 2 needs to be installed. (Tested in Python 2.7.6) If/When installed the program can simply be run on command line in the following fashion. (make sure DecTree.py is in your current/working directory if you intend to use the exact command below)

python DecTree.py 

This will execute the DecTree.py and once it is done, you will find the decision tree generated by it in the Output.dot file, within the working directory. You may test it using the sample input files in Samples/ directory, and can even visualize the decision tree generated using a command line tool such as dot, specifically a command like dot -Tgif Output.dot -o Output.gif)

You will also find a second output file in the working directory named log.txt, in which the overall test accuracy is printed, along with straightforward error messages for the test cases where the tree failed(i.e. could not even make a guess) to classify the test instance.

The test instances present in the input are run by default. If you wish to disable the execution of testing, you may simply add the argument --disable tests, as given below.

python DecTree.py --disable-tests 

As mentioned above, you can add a histogram to the label of each node. This behavior is disabled by default, but you can add the argument --hist if you wish to enable it.

The order of the file path as well as arguments --hist and --disable-tests are irrelevant. After you type python DecTree.py, you may write the rest in any order.

Finally, there is also a help argument you may call by -h or --help to view basically the same information mentioned in this section, if you feel like viewing a more concise version of it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages