def storeTree(inputTree,filename): import pickle; fw=open(filename,'w'); pickle.dump(inputTree,fw); fw.close(); def grabTree(filename): import pickle; fr = open(filename); return pickle.load(fr); def classify(inputTree,featLabels,testVec): firstStr=inputTree.keys()[0]; secondDict=inputTree[firstStr]; featIndex=featLabels.index(firstStr); key=testVec[featIndex]; valueOfFeat=secondDict[key]; if isinstance(valueOfFeat,dict): classLabel=classify(valueOfFeat,featLabels,testVec); else: classLabel=valueOfFeat; return classLabel;