【问题标题】:DecisionTree Classifier in scikit learn features return the value -2, what does it meanscikit learn features中的DecisionTree Classifier返回值-2,是什么意思
【发布时间】:2020-07-13 09:20:27
【问题描述】:

DecisionTreeClassifier 和 DecisionTreeRegressor 的 tree._feature 最后几次返回值 -2。这是因为它们是叶节点吗?我可以假设任何 -2 值作为叶节点特征吗?

【问题讨论】:

    标签: python-3.x machine-learning scikit-learn data-science decision-tree


    【解决方案1】:

    一般来说,是的。对象变量.tree_.feature 在该节点上没有分裂时返回-2,当且仅当该节点是叶子时才会发生这种情况(当树在没有修剪的情况下生长时,即fit(..., ccp_alpha=0))。

    虽然在 help() 文档中并没有 100% 清楚,但可以在此处的代码中找到对此的引用: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_tree.pyx

    其中feature 值设置为静态变量TREE_UNDEFINED = -2。

    【讨论】:

    • 在 sciki-learn 网站上的这个例子中有一个更“官方”的方法:scikit-learn.org/stable/auto_examples/tree/… 查找子节点是检查是否tree_. children_left == tree_.children_right。如果是,则该节点没有两个不同的子节点,因此无法拆分,因此必须是叶节点。
    猜你喜欢
    • 2014-11-12
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 2013-04-25
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多