python - Python 中的随机森林实现

标签 python scikit-learn random-forest

全部!

任何人都可以给我关于 Python 中随机森林实现的建议吗?理想情况下,我需要能够输出尽可能多的分类器信息的东西,尤其是:

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

我发现了很多实现,最著名的可能来自 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 treetree_ 属性.我同意,它没有很好的记录。确实应该有一个示例来可视化叶子分布等。您可以查看可视化函数以了解如何获取属性。

关于python - Python 中的随机森林实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17362576/

相关文章:

python - 从 scipy 导入 softmax 并在从 sklearn 导入后使用它时出现问题

python - Jupyter 笔记本不执行

python - Python 中的乘法表仅显示六列

python - 像 Blob 一样的图像是什么样的?

python - "Invalid Index to Scalar Variable"- 使用 Scikit Learn 时 "accuracy_score"

machine-learning - 随机森林分类器 class_weight

r - 提取与新观察相关的每棵树的终端节点

r - 随机森林中分割训练数据和测试数据的查询

python - 为什么 Python 的 json.dumps 拒绝序列化我的对象中的字符串?

python - 使用 Flask 创建 Web 服务器,输出可用于 GET 请求的内容