def compute_class_averages(self):
"""
Computes the class average of each node in the tree.
Class average is the mode of training data that partitions to the node.
"""
for i in range(2, self.nodes + 1):
parent = self.graph.predecessors(i)[0]
if self.graph.node[parent]['cutoff'] is None:
self.graph.node[i]['classval'] = self.graph.node[parent]['classval']
else:
node_indices = self.partition_data(i)
classval = mode(self.y[node_indices]).mode[0]
self.graph.node[i]['classval'] = classval
评论列表
文章目录