def main(): """Standalone test""" import sys from AnyQt.QtWidgets import QApplication from Orange.modelling.tree import TreeLearner a = QApplication(sys.argv) ow = OWTreeGraph() data = Table(sys.argv[1] if len(sys.argv) > 1 else "titanic") clf = TreeLearner()(data) clf.instances = data ow.ctree(clf) ow.show() ow.raise_() a.exec_() ow.saveSettings()
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 _get_tree_adapter(self, model): if isinstance(model, SklModel): return SklTreeAdapter(model) return TreeAdapter(model) if __name__ == "__main__": # pragma: no cover from Orange.modelling.tree import TreeLearner data = Table("titanic") # data = Table("housing") clf = TreeLearner()(data) clf.instances = data WidgetPreview(OWTreeGraph).run(clf)
elif self.regression_colors == self.COL_MEAN: minv = np.nanmin(self.dataset.Y) maxv = np.nanmax(self.dataset.Y) fact = 1 / (maxv - minv) if minv != maxv else 1 colors = self.scene.colors for node in self.scene.nodes(): node_mean = self.tree_adapter.get_distribution(node.node_inst)[0][0] node.backgroundBrush = QBrush(colors[fact * (node_mean - minv)]) 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 _get_tree_adapter(self, model): if isinstance(model, SklModel): return SklTreeAdapter(model) return TreeAdapter(model) if __name__ == "__main__": # pragma: no cover from Orange.modelling.tree import TreeLearner data = Table("titanic") clf = TreeLearner()(data) clf.instances = data WidgetPreview(OWTreeGraph).run(clf)