【问题标题】:Random Forest implementation in PythonPython中的随机森林实现
【发布时间】:2013-06-26 02:25:45
【问题描述】:

全部!

谁能给我一个关于在 Python 中实现随机森林的建议?理想情况下,我需要输出尽可能多的分类器信息,尤其是:

  1. 训练集中的哪些向量用于训练每个决策 树木
  2. 在每个节点的每个节点中随机选择哪些特征 树,来自训练集的样本最终在这个节点中, 选择特征进行拆分以及使用哪个阈值 拆分

我发现了很多实现,最著名的可能来自 scikit,但不清楚如何在其中执行 (1) 和 (2)(请参阅this 问题)。其他实现似乎也有同样的问题,除了来自 openCV 的那个,但它是用 C++ 编写的(python 接口不涵盖随机森林的所有方法)。

有人知道满足 (1) 和 (2) 的东西吗?或者,知道如何改进 scikit 实现以获得功能 (1) 和 (2)?

已解决:查看了sklearn.tree._tree.Tree的源码。它有很好的 cmets(完全描述了树):

 children_left : int*
    children_left[i] holds the node id of the left child of node i.
    For leaves, children_left[i] == TREE_LEAF. Otherwise,
    children_left[i] > i. This child handles the case where
    X[:, feature[i]] <= threshold[i].

children_right : int*
    children_right[i] holds the node id of the right child of node i.
    For leaves, children_right[i] == TREE_LEAF. Otherwise,
    children_right[i] > i. This child handles the case where
    X[:, feature[i]] > threshold[i].

feature : int*
    feature[i] holds the feature to split on, for the internal node i.

threshold : double*
    threshold[i] holds the threshold for the internal node i.

【问题讨论】:

    标签: python scikit-learn random-forest


    【解决方案1】:

    您几乎可以在 scikit-learn 中获得所有信息。究竟是什么问题?您甚至可以使用点来可视化树木。 我认为您无法找出随机抽样的拆分候选人,但您可以找出最终选择了哪些。 编辑:查看the decision treetree_ 属性。我同意,它没有很好的记录。确实应该有一个示例来可视化叶子分布等。您可以查看可视化功能以了解如何获取属性。

    【讨论】:

    • 是的,我对树进行了可视化并检查了 tree_ 结构,希望从中得到一些东西,但是例如,我无法获得每个子树上的训练示例的索引(只是没有与训练示例相对应的索引)
    • 这些索引在随机森林 afaik 中。看看 OOB 分数是如何计算的。
    猜你喜欢
    • 1970-01-01
    • 2019-08-25
    • 2016-05-15
    • 2018-04-10
    • 2014-10-26
    • 2021-05-29
    • 2017-12-24
    • 2014-04-01
    • 2012-12-10
    相关资源
    最近更新 更多