eFeatures = copy.deepcopy(features) # Build dictionary of feature values c = 0 for key in eFeatures.keys(): for line in newTrainData: attr = line[c] clss = line[-2] if attr not in eFeatures[key].keys(): eFeatures[key][attr] = {clss: line[-1]} else: if clss not in eFeatures[key][attr].keys(): eFeatures[key][attr][clss] = line[-1] else: eFeatures[key][attr][clss] += line[-1] c += 1 newTrainData, stump, stumpWeight = AdaBoost.adaBoost( newTrainData, eFeatures, features) stumps.append(stump) stumpWeights.append(stumpWeight) #Test total = 0 correct = 0 incorrct = 0 for sample in testData: total += 1 votes = {'yes': 0, 'no': 0} # Run test sample through all trees and tally votes for i in range(len(stumps)): result = DecisionTree.test(sample, stumps[i], features) votes[result] += stumpWeights[i] predict = max(votes, key=votes.get)