我有dict属性来建立一个树状结构。 我有一个预测函数,它根据属性子关系预测决策树的准确性
我想推广这个函数,这样我就可以根据dict属性预测我的精确度
def __init__(self, _d):
self.__dict__ = {a:DecisionNode(b) if isinstance(b, dict) else b for a, b in _d.items()}
def predicts(self, x):
if self.children == {}: # reached leaf level
return self.attribute
value = x[self.attribute]
subtree = self.children[value]
return subtree.predicts(x)
for i in range(0,len(test)):
if str(class_tree.predicts(test.loc[i])) == str(test.loc[1,target]):
correct += 1
print("\nThe accuracy is: ", correct/len(test))
这就是我的dict属性-
class_tree.outlook.sunny.temperature.hot
Out[85]: 'no'
目前没有回答
相关问题 更多 >
编程相关推荐