(inputTree, featLabels, testVec)
| 356 | 2017-07-25 |
| 357 | """ |
| 358 | def classify(inputTree, featLabels, testVec): |
| 359 | firstStr = next(iter(inputTree)) #获取决策树结点 |
| 360 | secondDict = inputTree[firstStr] #下一个字典 |
| 361 | featIndex = featLabels.index(firstStr) |
| 362 | for key in secondDict.keys(): |
| 363 | if testVec[featIndex] == key: |
| 364 | if type(secondDict[key]).__name__ == 'dict': |
| 365 | classLabel = classify(secondDict[key], featLabels, testVec) |
| 366 | else: classLabel = secondDict[key] |
| 367 | return classLabel |
| 368 | |
| 369 | """ |
| 370 | 函数说明:存储决策树 |