Developed in Python Code can be run from command line Python Libraries numpy, copy, random, pickle, graphviz, argparse, sys, string.
All scripts should be in the same folder. Tree is populated with samples of positive and negative class while training. For pruning tree should already exist in a pickle file in same folder.
See 'python tdidt.py --help' for further options
arguments:
-h, --help show the help message
--data_file : File name. Depends on mode. If mode is ‘train’ then training file name else test file name
--max_depth : Maximum depth for tree growth.
--mode : String can take one of two values: ‘train’ or ‘test’, ‘train’ mode is for training decision tree and test mode is for evaluating trained tree on test data.
--dot_file_name: Name of file to store dot format of decision tree.
python tdidt.py --data_file gene_expression_training.csv --max_depth 3 --mode train --dot_file_name tree.dot --pickle_file_name tree.pickle
dot -Tpng tree.dot -o tree.png
python tdidt.py --data_file gene_expression_test.csv --mode test
Arguements
--mode : String to specify pruning mode: ‘heuristic’ or ‘pessimistic’.
--dot_file_name: If training mode name of file to store dot format of decision tree.
--pickle_file_name: Pickle file for tree
(A) Heuristic Pruning Steps
- First train the tree on training set.
- Prune the tree on validation set (this implementation uses training).
- Test the tree on test set.
(B) Pessimistic Pruning Steps
- First train the tree on training set.
- Prune the tree on training set.
- Test the tree on test set.
python prune_tree.py --mode heuristic --dot_file_name prune_heuristic.dot --pickle_file_input tree.pickle --pickle_file_output heuristic_prune_tree.pickle
To extract rules from a trainded decision tree:
python rule_extraction.py --pickle_file_name tree.pickle
- Python 3.0+
- Graphviz