def setClassificationTree(self, tree): self.closeContext() if tree and (not tree.classVar or tree.classVar.varType != orange.VarTypes.Discrete): self.error( "This viewer only shows trees with discrete classes.\nThere is another viewer for regression trees" ) self.tree = None else: self.error() self.tree = tree self.setTreeView() self.sliderChanged() self.targetCombo.clear() if tree: self.treeNodes, self.treeLeaves = orngTree.countNodes( tree), orngTree.countLeaves(tree) self.infoa.setText('Number of nodes: %i' % self.treeNodes) self.infob.setText('Number of leaves: %i' % self.treeLeaves) self.targetCombo.addItems( [name for name in tree.tree.examples.domain.classVar.values]) self.targetClass = 0 self.openContext("", tree.domain) else: self.treeNodes = self.treeLeaves = 0 self.infoa.setText('No tree on input.') self.infob.setText('') self.openContext("", None)
def ctree(self, tree=None): self.clear() if not tree: self.centerRootButton.setDisabled(1) self.centerNodeButton.setDisabled(0) self.infoa.setText('No tree.') self.infob.setText('') self.tree = None self.rootNode = None else: self.tree = tree.tree self.infoa.setText('Number of nodes: ' + str(orngTree.countNodes(tree))) self.infob.setText('Number of leaves: ' + str(orngTree.countLeaves(tree))) if hasattr(self.scene, "colorPalette"): self.scene.colorPalette.setNumberOfColors( len(self.tree.distribution)) # self.scene.setDataModel(GraphicsTree(self.tree)) self.rootNode = self.walkcreate(self.tree, None) # self.scene.addItem(self.rootNode) self.scene.fixPos(self.rootNode, self.HSpacing, self.VSpacing) self.activateLoadedSettings() self.sceneView.centerOn(self.rootNode.x(), self.rootNode.y()) self.updateNodeToolTips() self.centerRootButton.setDisabled(0) self.centerNodeButton.setDisabled(1) self.scene.update()
def ctree(self, tree=None): self.clear() if not tree: self.centerRootButton.setDisabled(1) self.centerNodeButton.setDisabled(0) self.infoa.setText('No tree.') self.infob.setText('') self.tree=None self.rootNode = None else: self.tree=tree.tree self.infoa.setText('Number of nodes: ' + str(orngTree.countNodes(tree))) self.infob.setText('Number of leaves: ' + str(orngTree.countLeaves(tree))) if hasattr(self.scene, "colorPalette"): self.scene.colorPalette.setNumberOfColors(len(self.tree.distribution)) # self.scene.setDataModel(GraphicsTree(self.tree)) self.rootNode=self.walkcreate(self.tree, None) # self.scene.addItem(self.rootNode) self.scene.fixPos(self.rootNode,self.HSpacing,self.VSpacing) self.activateLoadedSettings() self.sceneView.centerOn(self.rootNode.x(), self.rootNode.y()) self.updateNodeToolTips() self.centerRootButton.setDisabled(0) self.centerNodeButton.setDisabled(1) self.scene.update()
def setClassificationTree(self, tree): self.closeContext() if tree and (not tree.classVar or tree.classVar.varType != orange.VarTypes.Discrete): self.error("This viewer only shows trees with discrete classes.\nThere is another viewer for regression trees") self.tree = None else: self.error() self.tree = tree self.setTreeView() self.sliderChanged() self.targetCombo.clear() if tree: self.treeNodes, self.treeLeaves = orngTree.countNodes(tree), orngTree.countLeaves(tree) self.infoa.setText('Number of nodes: %i' % self.treeNodes) self.infob.setText('Number of leaves: %i' % self.treeLeaves) self.targetCombo.addItems([name for name in tree.tree.examples.domain.classVar.values]) self.targetClass = 0 self.openContext("", tree.domain) else: self.treeNodes = self.treeLeaves = 0 self.infoa.setText('No tree on input.') self.infob.setText('') self.openContext("", None)
def updateTree(self): self.setTreeView() self.learner = FixedTreeLearner(self.tree, self.captionTitle) self.infoa.setText("Number of nodes: %i" % orngTree.countNodes(self.tree)) self.infob.setText("Number of leaves: %i" % orngTree.countLeaves(self.tree)) # self.send("Data", self.tree) self.send("Classifier", self.tree) self.send("Tree Learner", self.learner)
# Description: Builds a classification tree, and prunes it using minimal error # prunning with different values of parameter m. Prints # out m and the size of the tree. # a tree in text and dot format # Category: modelling # Uses: iris # Referenced: orngTree.htm import orange, orngTree data = orange.ExampleTable("../datasets/adult_sample.tab") tree = orange.TreeLearner(data) prunner = orange.TreePruner_m() trees = [(0, tree.tree)] for m in [0.0, 0.1, 0.5, 1, 5, 10, 50, 100]: prunner.m = m trees.append((m, prunner(tree))) for m, t in trees: print "m = %5.3f: %i nodes, %i leaves" % (m, t.treesize(), orngTree.countLeaves(t))
def sendReport(self): self.reportData(self.data) self.treeNodes, self.treeLeaves = orngTree.countNodes( self.tree), orngTree.countLeaves(self.tree) super(OWITree, self).sendReport()
def sendReport(self): self.reportData(self.data) self.treeNodes, self.treeLeaves = orngTree.countNodes(self.tree), orngTree.countLeaves(self.tree) super(OWITree, self).sendReport()
def tree(data, classify, sameMajorityPruning=False, mForPruning=0, maxMajority= 1, minSubset = 0, minExamples = 0): ''' make a classification tree using orange For more details see `orange tree <http://orange.biolab.si/doc/modules/orngTree.htm>`_ :param data: data from :meth:`perform_experiments` :param classify: function for classifying runs :param sameMajorityPruning: If true, invokes a bottom-up post-pruning by removing the subtrees of which all leaves classify to the same class (default: False). :param mForPruning: If non-zero, invokes an error-based bottom-up post-pruning, where m-estimate is used to estimate class probabilities (default: 0). :param maxMajority: Induction stops when the proportion of majority class in the node exceeds the value set by this parameter (default: 1.0). :param minSubset: Minimal number of examples in non-null leaves (default: 0). :param minExamples: Data subsets with less than minExamples examples are not split any further, that is, all leaves in the tree will contain at least that many of examples (default: 0). :rtype: a classification tree in order to print the results one can for example use `graphiv <http://www.graphviz.org/>`_. >>> import orgnTree >>> tree = tree(input, classify) >>> orngTree.printDot(tree, r'..\..\models\\tree.dot', leafStr="%V (%M out of %N)") this generates a .dot file that can be opened and displayed using graphviz. the leafStr keyword argument specifies the format of the string for each leaf. See on this also the more detailed discussion on the orange web site. At some future state, a convenience function might be added for turning a tree into a `networkx graph <http://networkx.lanl.gov/>`_. However, this is a possible future addition. ''' data = build_orange_data(data, classify) #make the actually tree, for details on the meaning of the parameters, see #the orange webpage info("executing tree learner") tree = orngTree.TreeLearner(data, sameMajorityPruning=sameMajorityPruning, mForPruning=mForPruning, maxMajority=maxMajority, minSubset = minSubset , minExamples = minExamples) info("tree contains %s leaves" % orngTree.countLeaves(tree)) return tree #def multi_dimensional_scaling(data, # classify, # runs=100): # ''' # Perform multi dimensional scaling using the `orngMDS<http://orange.biolab.si/doc/modules/orngMDS.htm>`_ # module. # # :param data: data from :meth:`perform_experiments` # :param classify: function for classifying runs # :param runs: the number of iterations to be used in MDS # :returns: a `figure<http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure>`_ instance # # # ''' # data = build_orange_data(data, classify) # # euclidean = orange.ExamplesDistanceConstructor_Euclidean(data) # distance = orange.SymMatrix(len(data)) # for i in range(len(data)): # for j in range(i+1): # distance[i, j] = euclidean(data[i], data[j]) # # mds=orngMDS.MDS(distance) # mds.run(runs) # # # colors = graphs.COLOR_LIST # points = [] # # figure = plt.figure() # ax = figure.add_subplot(111) # # for (i,d) in enumerate(data): # points.append((mds.points[i][0], mds.points[i][1], d.getclass())) # # for c in range(len(data.domain.classVar.values)): # sel = filter(lambda x: x[-1]==c, points) # x = [s[0] for s in sel] # y = [s[1] for s in sel] # ax.scatter(x, y, c=colors[c]) # # return figure
def tree(data, classify, sameMajorityPruning=False, mForPruning=0, maxMajority= 1, minSubset = 0, minExamples = 0): ''' make a classification tree using orange For more details see `orange tree <http://orange.biolab.si/doc/modules/orngTree.htm>`_ :param data: data from :meth:`perform_experiments` :param classify: function for classifying runs :param sameMajorityPruning: If true, invokes a bottom-up post-pruning by removing the subtrees of which all leaves classify to the same class (default: False). :param mForPruning: If non-zero, invokes an error-based bottom-up post-pruning, where m-estimate is used to estimate class probabilities (default: 0). :param maxMajority: Induction stops when the proportion of majority class in the node exceeds the value set by this parameter (default: 1.0). :param minSubset: Minimal number of examples in non-null leaves (default: 0). :param minExamples: Data subsets with less than minExamples examples are not split any further, that is, all leaves in the tree will contain at least that many of examples (default: 0). :rtype: a classification tree in order to print the results one can for example use `graphiv <http://www.graphviz.org/>`_. >>> import orgnTree >>> tree = tree(input, classify) >>> orngTree.printDot(tree, r'..\..\models\\tree.dot', leafStr="%V (%M out of %N)") this generates a .dot file that can be opened and displayed using graphviz. the leafStr keyword argument specifies the format of the string for each leaf. See on this also the more detailed discussion on the orange web site. At some future state, a convenience function might be added for turning a tree into a `networkx graph <http://networkx.lanl.gov/>`_. However, this is a possible future addition. ''' data = build_orange_data(data, classify) #make the actually tree, for details on the meaning of the parameters, see #the orange webpage info("executing tree learner") tree = orngTree.TreeLearner(data, sameMajorityPruning=sameMajorityPruning, mForPruning=mForPruning, maxMajority=maxMajority, minSubset = minSubset , minExamples = minExamples) info("tree contains %s leaves" % orngTree.countLeaves(tree)) return tree