全部!
任何人都可以给我关于 Python 中随机森林实现的建议吗?理想情况下,我需要能够输出尽可能多的分类器信息的东西,尤其是:
- 训练集中的哪些向量用于训练每个决策 树木
- 在每个节点中随机选择哪些特征 树,训练集中的哪些样本最终出现在这个节点中, 选择要拆分的特征以及使用哪个阈值 拆分
我发现了很多实现,最著名的可能来自 scikit,但不清楚如何在那里执行 (1) 和 (2)(参见 this 问题)。其他实现似乎也有同样的问题,除了来自 openCV 的那个,但它是在 C++ 中(python 接口(interface)没有涵盖随机森林的所有方法)。
有人知道满足 (1) 和 (2) 的东西吗?或者,知道如何改进 scikit 实现以获得功能 (1) 和 (2) 吗?
已解决:检查了sklearn.tree._tree.Tree的源代码。它有很好的评论(充分描述了树):
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.
最佳答案
您几乎可以在 scikit-learn 中获取所有信息。究竟是什么问题?您甚至可以使用点可视化树。
我认为您无法找出随机抽取了哪些拆分候选人,但您可以找出最终选择了哪些。
编辑:查看 the decision tree 的 tree_
属性.我同意,它没有很好的记录。确实应该有一个示例来可视化叶子分布等。您可以查看可视化函数以了解如何获取属性。
关于python - Python 中的随机森林实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17362576/