【问题标题】:How to force decision trees to use just integer numbers while evaluating如何在评估时强制决策树仅使用整数
【发布时间】:2020-03-05 01:28:16
【问题描述】:

我正在做一个决策树,我想强制算法仅以整数评估条件。我使用的特征是离散和整数,所以树显示 "X 是没有意义的,所以在这个例子中,我希望树显示在 "X 或 "X 中的等效项之一的框中。

我需要这个来让非技术人员更容易理解树。显示“少于 15.5 首歌曲” 是没有意义的,应该是 少于 43 小于等于42.

我尝试改变源表的列类型,都是int64,问题依旧。

我正在使用的代码:

clf = tree.DecisionTreeClassifier(criterion='gini',
                                  max_depth=2,
                                  splitter='best')

clf = clf.fit(users_data, users_target)

到目前为止,我没有在文档中找到任何参数或类似内容。

谢谢!

【问题讨论】:

    标签: python machine-learning scikit-learn decision-tree


    【解决方案1】:

    首先,我不会自己调整树的规则,我会调整情节。

    还有一个来自 sklearn 的额外 tree ploting package 。 通过此调整:

    precision : int, optional (default=3)
    
        Number of digits of precision for floating point in the values of impurity, threshold and value attributes of each node.
    

    你可以改变它,例如:

    tree.plot_tree(clf, precision=0)
    

    应该给你四舍五入的数字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-29
      • 2019-09-22
      • 2020-12-30
      • 2021-08-24
      • 2018-08-26
      • 1970-01-01
      • 2016-07-23
      • 2012-12-19
      相关资源
      最近更新 更多