import data instance matches tree traversing if(exampleCheck){ positiveExamples++; }

import java.util.ArrayList;import java.util.HashMap;
public class BuildTree {

public Node buildTree(ArrayList> dataSet, ArrayList attributeList) { Utilities uti = new Utilities(); HashMap>> reduceMap = new HashMap>>(); double positiveCount = 0; double negativeCount = 0; for(int i=1; i newAttList = new ArrayList(); for(String val: attributeList){ if(!val.equalsIgnoreCase(bestAttribute)){ newAttList.add(val); } }

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

if (reduceMap.size() negativeCount){ value = “1”; }
return new Node(value); }
return new Node(bestAttribute,buildTree(reduceMap.get(“0”),newAttList),buildTree(reduceMap.get(“1”),newAttList)); }
}
public double accuracyOfTree(Node treeNode, ArrayList> list) { double accuracy = 0; int positiveExamples = 0;
ArrayList attributes = list.get(0); for(ArrayList row : list.subList(1, list.size())){ //looping over each row boolean exampleCheck = treeOutputCheck(treeNode, row, attributes); //passing each row to check if the output of each data instance matches tree traversing if(exampleCheck){ positiveExamples++; } } accuracy = (((double) positiveExamples / (double) (list.size()-1)) * 100.00);
return accuracy; } public boolean treeOutputCheck(Node root, ArrayList row, ArrayList attributeList){ Node nodeCopy = root; while(true){ if(nodeCopy.isLeafNode()){ if(nodeCopy.getLeafValue().equalsIgnoreCase(row.get(row.size()-1))){ return true; } else{ return false; } }
int index = attributeList.indexOf(nodeCopy.getName()); String value = row.get(index); if(value.equalsIgnoreCase(“0”)){ nodeCopy = nodeCopy.getLeft(); } else{ nodeCopy = nodeCopy.getRight(); } } }
}