【问题标题】:Is it possible to set the precision of the split values in scikit-learn decision trees?是否可以在 scikit-learn 决策树中设置分割值的精度?
【发布时间】:2017-11-16 21:09:48
【问题描述】:

访问决策树中节点的tree_.threshold 时,类型似乎是float。有没有办法将阈值的“精度”设置为整数? 在我的例子中,这些特征都是整数值,所以没有必要对以这种精度定义的值进行拆分。

【问题讨论】:

    标签: scikit-learn random-forest decision-tree


    【解决方案1】:

    不,scikit-learn 树在编译时使用double 类型作为阈值(请参阅https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_tree.pyx)。固定数据类型允许生成高效的 C 代码。您必须更改 scikit-learn 源代码,从 Cython .pyx 文件重建 C 扩展,然后安装修改后的 scikit-learn 以使用整数阈值。

    【讨论】:

    • 在引用的 _tree.pyx 文件中:from numpy import float32 as DTYPE。所以它目前是float 而不是double
    • DTYPE 是内部用于输入数据的类型,而不是用于阈值的类型;如果您在此文件中搜索“阈值”,您会看到它使用双精度。可能更好的链接可能是github.com/scikit-learn/scikit-learn/blob/…
    猜你喜欢
    • 2014-10-06
    • 2019-07-01
    • 2020-05-13
    • 2015-09-18
    • 2017-12-14
    • 2015-03-05
    • 2017-01-21
    • 2017-02-23
    相关资源
    最近更新 更多