(self)
Update the node color for regression trees
Update the node color for regression trees
Update the node color for regression trees
def toggle_node_color_reg(self):
        """Update the node color for regression trees"""
        def_color = QColor(192, 192, 255)
        if self.regression_colors == self.COL_DEFAULT:
            brush = QBrush(def_color.lighter(100))
            for node in self.scene.nodes():
                node.backgroundBrush = brush
        elif self.regression_colors == self.COL_INSTANCE:
            max_insts = len(self.tree_adapter.get_instances_in_nodes(
                [self.tree_adapter.root]))
            for node in self.scene.nodes():
                node_insts = len(self.tree_adapter.get_instances_in_nodes(
                    [node.node_inst]))
                node.backgroundBrush = QBrush(def_color.lighter(
                    120 - 20 * node_insts / max_insts))
        elif self.regression_colors == self.COL_MEAN:
            minv = np.nanmin(self.dataset.Y)
            maxv = np.nanmax(self.dataset.Y)
            colors = self.scene.colors
            for node in self.scene.nodes():
                node_mean = self.tree_adapter.get_distribution(node.node_inst)[0][0]
                color = colors.value_to_qcolor(node_mean, minv, maxv)
                node.backgroundBrush = QBrush(color)
        else:
            nodes = list(self.scene.nodes())
            variances = [self.tree_adapter.get_distribution(node.node_inst)[0][1]
                         for node in nodes]
            max_var = max(variances)
            for node, var in zip(nodes, variances):
                node.backgroundBrush = QBrush(def_color.lighter(
                    120 - 20 * var / max_var))
        self.scene.update()
def toggle_node_color_reg ( self ) : def_color = QColor ( 192 , 192 , 255 ) if self . regression_colors == self . COL_DEFAULT : brush = QBrush ( def_color . lighter ( 100 ) ) for node in self . scene . nodes ( ) : node . backgroundBrush = brush elif self . regression_colors == self . COL_INSTANCE : max_insts = len ( self . tree_adapter . get_instances_in_nodes ( [ self . tree_adapter . root ] ) ) for node in self . scene . nodes ( ) : node_insts = len ( self . tree_adapter . get_instances_in_nodes ( [ node . node_inst ] ) ) node . backgroundBrush = QBrush ( def_color . lighter ( 120 - 20 * node_insts / max_insts ) ) elif self . regression_colors == self . COL_MEAN : minv = np . nanmin ( self . dataset . Y ) maxv = np . nanmax ( self . dataset . Y ) colors = self . scene . colors for node in self . scene . nodes ( ) : node_mean = self . tree_adapter . get_distribution ( node . node_inst ) [ 0 ] [ 0 ] color = colors . value_to_qcolor ( node_mean , minv , maxv ) node . backgroundBrush = QBrush ( color ) else : nodes = list ( self . scene . nodes ( ) ) variances = [ self . tree_adapter . get_distribution ( node . node_inst ) [ 0 ] [ 1 ] for node in nodes ] max_var = max ( variances ) for node , var in zip ( nodes , variances ) : node . backgroundBrush = QBrush ( def_color . lighter ( 120 - 20 * var / max_var ) ) self . scene . update ( )