Skip to content

Commit

Permalink
Decision trees modified
Browse files Browse the repository at this point in the history
  • Loading branch information
samridh90 committed Oct 21, 2012
1 parent 3a18cfc commit eb24aa9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dTree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,16 @@ def createTree(dataSet, labels):
subLabels = labels[:]
myTree[bestFeatLabel][value] = createTree(splitDataSet(dataSet, bestFeat, value), subLabels)
return myTree


def classify(inputTree, featlabels, testVec):
firstStr = inputTree.keys()[0]
secondDict = inputTree[firstStr]
featIndex = featlabels.index(firstStr)
for key in secondDict.keys():
if testVec[featIndex] == key:
if type(secondDict[key]).__name__ == "dict":
classLabel = classify(secondDict[key], featlabels, testVec)
else:
classLabel = secondDict[key]
return classLabel

0 comments on commit eb24aa9

Please sign in to comment.