/* -------------------------------------------------------------------------- */ /* */ /* DEISSION TREE (INFORMATION GAIN) */ /* */ /* Frans Coenen */ /* */ /* Tuesday 20 November 2007 */ /* */ /* Department of Computer Science */ /* The University of Liverpool */ /* */ /* -------------------------------------------------------------------------- */ /* Generates a decision tree using information gain as a the splitting criteria. */ //package lucsKDD_ARM; /** decision tree classifier generator (inforamtion gain). @author Frans Coenen @version 20 November 2007 */ public class DecTreeInfoGain extends DecisionTree { /* ------ CONSTRUCTORS ------ */ /** Constructor with command line arguments to be process. @param args the command line arguments (array of String instances). */ public DecTreeInfoGain(String[] args) { super(args); } /* ------ METHODS ------ */ /** Selects attribute from attribute list on which to split (stub). @param attributeList the cuttent list of attrbutes. @param exampleList the currebt list of examples. @return the attribute index of the selected attribute. */ protected int selectAttribute(short[] attributeList, int[] exampleList) { // Calculate the entropy in the attribute list double entropy = calcEntropy(exampleList); // Get index of attribute that delivers the highest information gain int bestIndex = maximiseInfoGain(attributeList,exampleList,entropy); //System.out.println("bestIndex = " + bestIndex + "\n----------------------"); // Return return(bestIndex); } /* ------ CALCULATE ENTROPY ------ */ /** Calculates the entropy represented by the set of examples. @param exampleList the currebt list of examples. @return the entropy in the exampleList with respect to the class attribute. */ private double calcEntropy(int[] exampleList) { // Create class array double[] classArray = new double[numClasses]; //System.out.println("numAttributes = " + numAttributes); for (int i=0;i