Programming Assignment 2 - Decision Trees and Random Forests

Please download to get full document.

View again

of 2
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Categories
Published
Programming Assignment 2 - Decision Trees and Random Forests
  Programming Assignment #2 : Decision Trees with Bagging The basic task is to build a complete working program in Python implementing the Decision Tree algorithm. You have to first develop the program and test it, using the Bank Note Authentication (BNA) Dataset   http://archive.ics.uci.edu/ml/datasets/banknote+authentication# from the UCI (Univ. California Irvine) Machine Learning Data Repository http://archive.ics.uci.edu/ml/datasets.html. The software that you develop should be independent of a specific dataset, and should be able to generate Decision Trees for any Classification data set. Hence you shall also apply the S/W developed above on the Sensorless Drive Diagnosis (SDD) Data Set, taken from the same repository http://archive.ics.uci.edu/ml/datasets/Dataset+for+Sensorless+Drive+Diagnosis#. Further, you are to use the K-fold approach for creating bagged decision trees and then use the statistical mode for class identification for the test data. You shall compare the accuracy of test data for both the datasets between the original decision trees and the bagged decision trees. You are to follow the step-by-step approach described below: 1. The Decision Tree algorithm addresses two levels of logic: the higher architectural level and the node level. Accordingly the algorithm that you design prior to actual coding should also map into these two levels. You must first work out the algorithm and only then start coding 2. The node level algorithm is the core set of operations of splitting the data arriving from above (assuming tree is top down) at each node based on the specific feature (i.e. parameter) and the specific (granulated) value of that feature that provides the max. information gain. The data is split into a right and left branch which then ends in corresponding nodes where the set of operations are repeated, till a terminal node (leaf) is reached. Most of these operations have been expressed as pseudo-code and provided in the slides that were sent to you last weekend, along with other slides that described different aspects of the DT algorithm 3. A node is identified to be a terminal one if any one of these 3 criteria are met: (a) the depth of the node exceeds a maximum value that is a hyper parameter you will set; depth can be defined as the number of branches to the root node, (b) the number of data at the node falls below some threshold that is another user-set hyper parameter, or (c) all the samples at that node belong to the same class (hence splitting is redundant). For both (a) and (b) the statistical mode of the samples is used to identify the class of the terminal node 4. Next we address the logical aspects of the DT architecture. It would be obvious that the enveloping function (containing other functions) for the node-level calculations as you set out to create the tree starting from the root node (where all the training data is presented) right up to all the terminal nodes, will call itself recursively as the nodes are traversed. The approach will be analogous to other established algorithms called depth first search  which you can see on the net, e.g. in https://en.wikipedia.org/wiki/Depth-first_search or in https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/tutorial/ (among others). It is advisable that you familiarise yourself well with the DFS algorithm before you work out the details of the DT architecture-creation algorithm.  5. As stressed in #1, start creating code only after you are sure about your algorithm. Download the BNA dataset and split it into (approx.) 90-10 for training-testing; use this as the base data set for developing and testing your S/W. Ideally you should extract the 10% intermittently from the total data rather than in any contiguous block from it 6. Your code should be able to work under both training (i.e. tree development) and testing (i.e. given the features of some data sample, pass it though the DT and extract its class) modes. You will need to modify your code to handle both these modes 7. Download the SDD dataset and use it to validate your program: its generality and capability to work with diverse data sets. Note that the tree structure will change with the dataset, but the tree-generation-program should be same. That would close the first phase of development of your own DT S/W 8. Next, modify your developed code to work with bagging. You split the BNA training dataset (90% of available data) randomly into K parts, choose K = 2 to start. Train two separate DTs and verify their accuracy individually for the 10% test data. Then repeat for another random partitioning of the 90% training data, where K could be different (and odd number as well). In this way extract anywhere above 8 DTs, but an odd number 9. Pass the 10% test data through all the created DT ’ s, and extract the final class of each testing sample using the stat. mode of the classification obtained from all the DT ’ s. Evaluate the accuracy of the bagged DTs and compare with accuracy obtained from the single DT. 10. Repeat steps 7-8 with the SDD dataset. This brings to an end the basic S/W development. 11. Your submission should be a folder containing your code, and a word doc containing comparison of your single- and bagged- DT accuracies for both the datasets. Importantly, you should provide information (in the doc) on the structure of your single DT for both the data sets, in terms of your selected hyper-parameters, tree depth, splitting feature and splitting-value-for-the-feature at each node, the class of each terminal node, the number of data sets at each terminal node, etc. An illustration would be ideal but not necessary. BONUS : Random Forests are the next stage onwards from bagged DTs. Here, for each DT development, instead of using the deterministic maximum information gain at each node to determine the splitting feature and its value, you have to play  –   automatically in your software  –   with the top 2 or 3 features and choose any one randomly. This will completely change your tree structure even for exactly the same k-th training dataset. Your bag of trees will be made using this approach. You will then compare, for each of the two datasets (BNA and SDD), accuracies between the single DT, the bagged DTs, and the Random Forest. Extra Marks : 25% above base marks for this assignment.
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks