Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecisionTree_Project2/DecisionTree.py 方法classify 使用有误 #8

Open
Inouyasha opened this issue Jan 5, 2022 · 0 comments
Open

Comments

@Inouyasha
Copy link

530行里 调用classify方法,给定的第二项输入应该是完整的数据labels,且顺序和数据集顺序应该一致

同时优化了classify方法的写法 更加直观

def classify(inputTree, featLabels, testVec):
    # 获取决策树结点
    # 当前树节点的key首项 表明选择的特征类型
    keyLabel = list(inputTree.keys())[0]
    # 对应类型的特征树
    currDict = inputTree[keyLabel]

    # 获取特征类型在特征中的index
    featIndex = featLabels.index(keyLabel)
    # 获取当前的特征叶子 或者是 特征树
    judgeValue = currDict.get(testVec[featIndex])

    # 如果是树就继续向下走 如果是叶子输出
    if type(judgeValue).__name__ == 'dict':
        return classify(judgeValue, featLabels, testVec)
    else:
        return judgeValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant