【问题标题】:How to know the size (Number of nodes) of the tree built using Scikit-learn?如何知道使用 Scikit-learn 构建的树的大小(节点数)?
【发布时间】:2015-02-08 10:45:16
【问题描述】:

decReg = DecisionTreeRegressor() clf = decReg.fit(X, Y)

直觉上,任何人都会期望 decReg 或 calf 应该有一个函数,该函数将返回树中增长的节点数。但是,我看不到任何这样的功能。还有什么要知道树的大小吗?

【问题讨论】:

    标签: python machine-learning scikit-learn regression decision-tree


    【解决方案1】:
    # Instantiate a decision tree
    clf = tree.DecisionTreeClassifier()
    
    # Fit the decision tree
    ...
    
    # Print node count
    print(clf.tree_.node_count)
    

    【讨论】:

      【解决方案2】:

      根据documentation,有tree_ 属性,您可以遍历该树以查找任何感兴趣的属性。特别是,children_rightchildren_left 属性似乎很有用。

      【讨论】:

      • 感谢您的指点。但是,你能告诉我你从哪里得到 children_left、children_right 的信息吗?我认为您引用的页面不包含该内容。
      • @happy_coder,我是从解释器那里得到的。我相信在tree_ 上调用dir 会有所帮助。
      • 再次感谢!我可以知道您使用的是哪种口译员吗?
      • @happy_coder,当然。我使用 ipython——它有一些语法高亮和自动完成(在选项卡上)。
      猜你喜欢
      • 2017-03-26
      • 2015-12-07
      • 2017-01-21
      • 2019-12-11
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2020-04-05
      相关资源
      最近更新 更多