Commits

Blaz Zupan  committed a68fd2f

Old code files in tutorial removed.

  • Participants
  • Parent commits afd9213

Comments (0)

Files changed (6)

File docs/tutorial/rst/code/assoc1.py

-import orngAssoc
-import Orange
-
-data = Orange.data.Table("imports-85")
-data = Orange.data.Table("zoo")
-#data = Orange.data.preprocess.Discretize(data, \
-#  method=Orange.data.discretization.EqualFreq(numberOfIntervals=3))
-# data = data.select(range(10))
-
-rules = Orange.associate.AssociationRulesInducer(data, support=0.4)
-
-print "%i rules with support higher than or equal to %5.3f found.\n" % (len(rules), 0.4)
-
-orngAssoc.sort(rules, ["support", "confidence"])
-
-orngAssoc.printRules(rules[:5], ["support", "confidence"])
-print
-
-del rules[:3]
-orngAssoc.printRules(rules[:5], ["support", "confidence"])
-print

File docs/tutorial/rst/code/assoc2.py

-# Description: Association rule sorting and filtering
-# Category:    description
-# Uses:        imports-85
-# Classes:     orngAssoc.build, Preprocessor_discretize, EquiNDiscretization
-# Referenced:  assoc.htm
-
-import orngAssoc
-import Orange
-
-data = Orange.data.Table("imports-85")
-data = Orange.data.preprocess.Discretize(data, \
-  method=Orange.data.discretization.EqualFreq(numberOfIntervals=3))
-data = data.select(range(10))
-
-rules = Orange.associate.AssociationRulesInducer(data, support=0.4)
-
-n = 5
-print "%i most confident rules:" % (n)
-orngAssoc.sort(rules, ["confidence", "support"])
-orngAssoc.printRules(rules[0:n], ['confidence', 'support', 'lift'])
-
-conf = 0.8; lift = 1.1
-print "\nRules with confidence>%5.3f and lift>%5.3f" % (conf, lift)
-rulesC = rules.filter(lambda x: x.confidence > conf and x.lift > lift)
-orngAssoc.sort(rulesC, ['confidence'])
-orngAssoc.printRules(rulesC, ['confidence', 'support', 'lift'])

File docs/tutorial/rst/code/bagging.py

-# Description: An implementation of bagging (only bagging class is defined here)
-# Category:    modelling
-# Referenced:  c_bagging.htm
-
-import random
-import Orange
-
-def Learner(examples=None, **kwds):
-    learner = apply(Learner_Class, (), kwds)
-    if examples:
-        return learner(examples)
-    else:
-        return learner
-
-class Learner_Class:
-    def __init__(self, learner, t=10, name='bagged classifier'):
-        self.t = t
-        self.name = name
-        self.learner = learner
-
-    def __call__(self, examples, weight=None):
-        r = random.Random()
-        r.seed(0)
-
-        n = len(examples)
-        classifiers = []
-        for i in range(self.t):
-            selection = []
-            for j in range(n):
-                selection.append(r.randrange(n))
-            data = examples.getitems(selection)
-            classifiers.append(self.learner(data))
-            
-        return Classifier(classifiers = classifiers, name=self.name, domain=examples.domain)
-
-class Classifier:
-    def __init__(self, **kwds):
-        self.__dict__.update(kwds)
-
-    def __call__(self, example, resultType = Orange.classification.Classifier.GetValue):
-        freq = [0.] * len(self.domain.classVar.values)
-        for c in self.classifiers:
-            freq[int(c(example))] += 1
-        index = freq.index(max(freq))
-        value = Orange.data.Value(self.domain.classVar, index)
-        for i in range(len(freq)):
-            freq[i] = freq[i]/len(self.classifiers)
-        if resultType == Orange.classification.Classifier.GetValue: return value
-        elif resultType == Orange.classification.Classifier.GetProbabilities: return freq
-        else: return (value, freq)
-        

File docs/tutorial/rst/code/bagging_test.py

-# Description: Test for bagging as defined in bagging.py
-# Category:    modelling
-# Uses:        adult_sample.tab, bagging.py
-# Referenced:  c_bagging.htm
-# Classes:     orngTest.crossValidation
-
-import bagging
-import Orange
-data = Orange.data.Table("adult_sample.tab")
-
-tree = Orange.classification.tree.TreeLearner(mForPrunning=10, minExamples=30)
-tree.name = "tree"
-baggedTree = bagging.Learner(learner=tree, t=5)
-
-learners = [tree, baggedTree]
-
-results = Orange.evaluation.testing.cross_validation(learners, data, folds=5)
-for i in range(len(learners)):
-    print "%s: %5.3f" % (learners[i].name, Orange.evaluation.scoring.CA(results)[i])

File docs/tutorial/rst/code/fss6.py

-# Author:      B Zupan
-# Version:     1.0
-# Description: Same as fss5.py but uses FilterRelieff class from orngFSS
-# Category:    preprocessing
-# Uses:        adult_saple.tab
-# Referenced:  o_fss.htm
-
-import orngFSS
-import Orange
-data = Orange.data.Table("adult_sample.tab")
-
-def report_relevance(data):
-  m = Orange.feature.scoring.score_all(data)
-  for i in m:
-    print "%5.3f %s" % (i[1], i[0])
-
-print "Before feature subset selection (%d attributes):" % len(data.domain.attributes)
-report_relevance(data)
-data = Orange.data.Table("adult_sample.tab")
-
-marg = 0.01
-filter = Orange.feature.selection.FilterRelief(margin=marg)
-ndata = filter(data)
-print "\nAfter feature subset selection with margin %5.3f (%d attributes):" % (marg, len(ndata.domain.attributes))
-report_relevance(ndata)

File docs/tutorial/rst/code/fss7.py

-# Author:      B Zupan
-# Version:     1.0
-# Description: Shows the use of feature subset selection and compares
-#              plain naive Bayes (with discretization) and the same classifier but with
-#              feature subset selection. On crx data set, both classifiers achieve similarly
-#              accuracy but naive Bayes with feature subset selection uses substantially
-#              less features. Wrappers FilteredLearner and DiscretizedLearner are used,
-#              and example illustrates how to analyze classifiers used in ten-fold cross
-#              validation (how many and which attributes were used?).
-# Category:    preprocessing
-# Uses:        crx.tab
-# Referenced:  o_fss.htm
-
-import orngFSS
-import Orange
-
-data = Orange.data.Table("crx.tab")
-
-bayes = Orange.classification.bayes.NaiveLearner()
-dBayes = Orange.feature.discretization.DiscretizedLearner(bayes, name='disc bayes')
-fss = Orange.feature.selection.FilterAboveThreshold(threshold=0.05)
-fBayes = Orange.feature.selection.FilteredLearner(dBayes, filter=fss, name='bayes & fss')
-
-learners = [dBayes, fBayes]
-results = Orange.evaluation.testing.cross_validation(learners, data, folds=10, storeClassifiers=1)
-
-# how many attributes did each classifier use?
-
-natt = [0.] * len(learners)
-for fold in range(results.numberOfIterations):
-  for lrn in range(len(learners)):
-    natt[lrn] += len(results.classifiers[fold][lrn].domain.attributes)
-for lrn in range(len(learners)):
-  natt[lrn] = natt[lrn] / 10.
-
-print "\nLearner         Accuracy  #Atts"
-for i in range(len(learners)):
-  print "%-15s %5.3f     %5.2f" % (learners[i].name, Orange.evaluation.scoring.CA(results)[i], natt[i])
-
-# which attributes were used in filtered case?
-
-print '\nAttribute usage (in how many folds attribute was used?):'
-used = {}
-for fold in range(results.numberOfIterations):
-  for att in results.classifiers[fold][1].domain.attributes:
-    a = att.name
-    if a in used.keys(): used[a] += 1
-    else: used[a] = 1
-for a in used.keys():
-  print '%2d x %s' % (used[a], a)