基于决策树网络的python深度优先搜索到bread-first搜索的转换

2024-04-23 14:41:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我被指派去实现决策树算法。到目前为止,我已经找到了所有的节点/叶,但是我把它们放在一个平面的1d数组中。如何给它们加上标签,以便提取视觉表现? 我有最左边的部门第一次搜索后的节点列表,参考图片:[喜剧,枪支,树叶,律师,叶子,叶子,枪,叶子,叶子]

我需要的是像喜剧这样的标签:1枪:1.1叶1.1.1律师:1.1.2等

我的代码基本上与此方案中的代码类似:

    track=0
    def create node(dataset):
       select best attribute
       save attribute with track #
       track+=1

       if this attribute has sub-options:
          track*=10 #to indicate new depth level
          create appropriate decision set
          create_node(newdataset)
       else:
          pass #interestingly this bottom part called multiple times

轨道metohd没有帮助我,我认为它可以保持跟踪内部环路等,但它失败了。任何建议都非常感谢

enter image description here


Tags: 代码算法node决策树节点createattributetrack