【问题标题】:Prediction error of a decision tree决策树的预测误差
【发布时间】:2018-06-29 13:13:44
【问题描述】:

我正在使用决策树学习器algorithm 来构建我的决策树并在数据集上对其进行测试。

我也在尝试计算我的树的预测错误率,所以我可以用我的测试和训练集的学习曲线绘制一个图表。我做了一个循环,我的算法被应用 n 次(n 任意)。我的变量 internal_nodes 存储生成的内部节点的数量(这将是我在学习曲线图中的横坐标),我在每次调用时都返回它。

我创建 count_error() 来测量预测值和期望值之间的差异。

def count_errors(examples, target, tree):
    counter = 0
    for ex in examples: # examples is a list that contains list of example
        desired = ex[target]
        predicted = tree(ex) # use __call__(self,example) to obtain leaf value
        if desired != predicted:
            counter += 1
    return float(counter / len(examples)) * float(100)`

def __call__(self, example):
    """Given an example, classify it using the attribute and the branches."""
    attrvalue = example[self.attr] #attr is a list of integers that index into an example
    return self.branches[attrvalue](example)

发生的错误总是 0。我已经用一次迭代测试了我的算法,并且似乎它有效。我认为错误在于我计算错误的方式。 完整的存储库在我的github

感谢您的帮助。

【问题讨论】:

    标签: algorithm python-2.7 decision-tree supervised-learning


    【解决方案1】:

    在计算错误率时,您似乎有整数除法。试试这个:

    return float(counter) / len(examples) * float(100)
    

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 2016-07-12
      • 2017-04-11
      • 1970-01-01
      • 2020-08-11
      • 2013-07-11
      • 1970-01-01
      • 2017-05-31
      • 2016-09-23
      相关资源
      最近更新 更多