【问题标题】:Decision tree in JSON - return leaf to root path for a given leafJSON 中的决策树 - 将叶返回给给定叶的根路径
【发布时间】:2019-05-17 23:18:57
【问题描述】:

我有一个 json 格式决策树(大约 11k 个节点)并且需要一个返回 的函数从给定叶子到根的路径。 在从头开始编码之前,您是否知道是否存在任何基于 python json 格式的返回此类路径的代码? 例如,如果 "Predict: 59.0" 是我的叶子,当我运行 getMyPath("Predict: 59.0") 时,我希望收到如下内容:

{
  "name": "Root",
  "children": [
    {
      "name": "x<= 0.09",
      "children": [
        {
          "name": "y<= 281.0",
          "children": [
            {
              "name": "z<= 217.75400000000002",
              "children": [
                {
                  "name": "z<= -0.01",
                  "children": [
                    {
                      "name": "z<= -64.83",
                      "children": [
                        {
                          "name": "Predict: 59.0"

谢谢,米哈尔

【问题讨论】:

    标签: python json decision-tree


    【解决方案1】:

    不,您必须编写一个递归函数来查看决策树结构的每条路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 1970-01-01
      • 2018-06-11
      • 2016-07-23
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多