List of usage examples for weka.core Instances classAttribute
publicAttribute classAttribute()
From source file:tubes1.myClassifiers.myID3.java
public TreeNode id3Node(Instances i) { TreeNode treeNode = new TreeNode(); int[] count = calculateCount(i); for (int j = 0; j < count.length; j++) { int c = count[j]; if (c == i.numInstances()) { treeNode.label = j;//w w w .ja v a2 s .co m return treeNode; } } if (i.numAttributes() <= 1) { int maxc = -1; int maxcj = -1; for (int j = 0; j < count.length; j++) { if (count[j] > maxc) { maxc = count[j]; maxcj = j; } } treeNode.label = maxcj; return treeNode; } Attribute bestA = null; double bestAIG = -1; double entropyOfSet = entropy(i); for (int j = 0; j < i.numAttributes(); j++) { Attribute a = i.attribute(j); if (a != i.classAttribute()) { double aIG = infoGain(i, a, entropyOfSet); if (aIG > bestAIG) { bestAIG = aIG; bestA = a; } } } treeNode.decision = bestA; Instances[] subSets = splitData(i, bestA); for (Instances subSet : subSets) { if (subSet.numInstances() > 0) { double attributeValue = subSet.firstInstance().value(bestA); subSet.deleteAttributeAt(bestA.index()); TreeNode newBranch = id3Node(subSet); newBranch.branchValue = attributeValue; treeNode.addBranch(newBranch); } else { } } return treeNode; }
From source file:tubes1.myClassifiers.myID3.java
public double calculateAttributeProportion(Instances instances, Attribute attribute) { int numClasses = instances.classAttribute().numValues(); return 0;//from ww w . j a v a 2s . c o m }
From source file:tubes1.myClassifiers.myID3.java
public double infoGain(Instances instances, Attribute attribute, double entropyOfSet) { int numClasses = instances.classAttribute().numValues(); int numInstances = instances.numInstances(); HashMap<String, Integer> values = getAttributeValues(instances, attribute); double zigma = 0; Set<String> keys = values.keySet(); for (int i = 0; i < keys.size(); i++) { String key = nthElement(keys, i); Instances instanceWithAttributeValue = filterInstanceWithAttributeValue(instances, attribute, key); zigma += (values.get(key) / numInstances) * entropy(instanceWithAttributeValue); }/*from w w w. j a va2 s. c o m*/ return entropyOfSet - zigma; }