@@ -0,0 +1,1814 @@
+package algorithms;%0A%0Aimport java.math.BigDecimal;%0Aimport java.math.RoundingMode;%0A%0Aimport data.management.Set;%0Aimport elements.Attribute;%0Aimport elements.Value;%0Aimport exception.ImpossibleException;%0A%0Apublic class ID3 extends DecisionTreeLearning%7B%0A%0A%09public ID3(Set s, String goal) throws ImpossibleException%7B%0A%09%09super(s, goal);%0A%09%09// TODO Auto-generated constructor stub%0A%09%7D%0A%0A%09@Override%0A%09public void execute() %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09//If all instances in C are positive %7C negative -%3E halt algo and create node%0A%09%09if(set.sameValuesInstance(obj))%7B%0A%09%09%09Value value = set.getOnlyValue(obj);%0A%09%09%09// create unique node : TODO%0A%09%09%09return; %0A%09%09%7Delse%7B%0A%09%09%09double S = entropyObjective();%0A%09%09%09System.out.println(%22Entropy of S = %22 + S);%0A%09%09%09// need to choose which is the best attribute to be the root node%0A%09%09%09double gain = 0.0;%0A%09%09%09for(Attribute a : attributes)%7B%0A%09%09%09%09gain = entropy(a,obj);%0A%09%09%09%09gain = round(S - gain);%0A%09%09%09%09System.out.println(%22gain of%22 + a.getName() + %22 = %22 + gain);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09protected double gain(Attribute S, Attribute attribute) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09return round(entropy(S, obj) - entropy(attribute, obj));%0A%09%7D%0A%0A%09@Override%0A%09protected double entropy(Attribute a, Attribute S) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09return round(a.entropy(S));%0A%09%7D%0A%09%0A%09protected double entropyObjective()%7B%0A%09%09double res = 0.0;%0A%09%09double stat = 0.0;%0A%09%09for(Value v : obj.getAttributes())%7B%0A%09%09%09stat = (v.getOccurences() / set.getSamples());%0A%09%09%09res -= stat * log2(stat);%0A%09%09%7D%0A%09%09return round(res);%0A%09%7D%0A%09%0A%09private double log2(double val)%7B%0A%09%09if(val == 0)%7B%0A%09%09%09return 0.0;%0A%09%09%7Delse%7B%0A%09%09%09return (Math.log(val) / Math.log(2));%0A%09%09%7D%0A%09%7D%0A%09%0A%09private double round(double toRound)%7B%0A%09    BigDecimal bd = new BigDecimal(toRound);%0A%09    bd = bd.setScale(3, RoundingMode.HALF_UP);%0A%09    return bd.doubleValue();%0A%09%7D%0A%0A%7D%0A

Add ID3 algorithm in java