def __init__(self, path, bTrain): self.bTrain = bTrain if bTrain: self.file = open(path+'.tab', "w") else: data = orange.ExampleTable(path) self.file = orange.C45Learner(data, prune=False) self.names = None self.types = None self.classes = None self.examples = []
def train_classifier(data, type, filter): if type == "tree" or type == "c4.5" or type == "decision_tree": learner = orange.C45Learner() elif type == "bayes" or type == "naive" or type == "naive_bayes": learner = orange.BayesLearner() elif type == "svm" or type == "linear_svm": learner = Orange.classification.svm.LinearSVMLearner() #elif type == "logreg" or type == "regression": # learner = Orange.classification.logreg.LogRegLearner() else: print "Invalid Learner Type\n" exit() if filter == 0: classifier = learner(data) else: filtered_learner = Orange.feature.selection.FilteredLearner( learner, filter=Orange.feature.selection.FilterBestN(n=filter), name='filtered') classifier = filtered_learner(data) return classifier
# Description: Shows how to use C4.5 learner # Category: learning # Classes: C45Learner, C45Classifier # Uses: iris # Referenced: C45Learner.htm import orange #data = orange.ExampleTable("lenses.tab") data = orange.ExampleTable("iris") tree = orange.C45Learner(data) print "\n\nC4.5 with default arguments" for i in data[:5]: print tree(i), i.getclass() print "\n\nC4.5 with m=100" tree = orange.C45Learner(data, m=100) for i in data[:5]: print tree(i), i.getclass() print "\n\nC4.5 with minObjs=100" tree = orange.C45Learner(data, minObjs=100) for i in data[:5]: print tree(i), i.getclass() print "\n\nC4.5 with -m 1 and -s" lrn = orange.C45Learner() lrn.commandline("-m 1 -s") tree = lrn(data) for i in data:
def c45_tree(input_dict): import orange output_dict = {} output_dict['c45out'] = orange.C45Learner(name="C4.5 Tree (Orange)") return output_dict
def test_pickling_on(self, dataset): try: orange.C45Learner() except orange.KernelException: raise unittest.SkipTest("C45 dll not found") testing.LearnerTestCase.test_pickling_on(self, dataset)
##f.close() ##print tree.name ##treeC45 = orange.C45Learner(trainD, minObjs=5) ##treeC45.name = "tree - C45 " ##f = file(trainData+'o.txt.C45tree', 'w') ##dumpC45Tree(treeC45,f) ##f.close() ##print treeC45.name t = orngTree.TreeLearner(measure='gainRatio', binarization=0, minSubset=2, minExamples=2, sameMajorityPruning=1, mForPruning=2); bsTree = BLearner(learner=t, examples=trainD) bsTree.name = "bsTree " print bsTree.name c45 = orange.C45Learner(minObjs=2) bsC45 = BLearner(learner=c45, examples=trainD) bsC45.name = "bsC45 " print bsC45.name ##svm = orange.SVMLearner(trainD) ##svm.name = "SVM " ##classifiers = [majority, tree, bsTree, treeC45, bsC45] classifiers = [majority, bsTree, bsC45] # compute accuracies print '='*80 acc = accuracy(trainD, classifiers) print "Classification accuracies - train:" print '-'*80