How to use the orange.MajorityLearner function in Orange

To help you get started, we’ve selected a few Orange examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biolab / orange2 / Orange / preprocess / __init__.py View on Github external
def __init__(self, model=None, **kwargs):
        self.model = orange.MajorityLearner() if model is None else model
github biolab / orange2 / orange / orng / orngCI.py View on Github external
else:
        subgen=orange.SubsetsGenerator_minMaxSize(min = self.boundsize[0], max = self.boundsize[1])
    else:
        subgen=orange.SubsetsGenerator_constSize(B = 2)
        

    if type=="auto":
      im=orange.IMBySorting(data, [])
      if im.fuzzy():
        type="error"
      else:
        type="complexity"

    inducer=StructureInducer(removeDuplicates = 1,
                             redundancyRemover = AttributeRedundanciesRemover(),
                             learnerForUnknown = orange.MajorityLearner()
                           )

    if type=="complexity":
      inducer.featureInducer = FeatureByMinComplexity()
      return inducer(data, weight)

    elif type=="error":
      ms=getattr(self, "m", orange.frange(0.1)+orange.frange(1.2, 3.0, 0.2)+orange.frange(4.0, 10.0, 1.0))
    
      inducer.redundancyRemover.inducer=inducer.featureInducer = FeatureByMinError()

      # it's the same object for redundancy remover and the real inducer, so we can tune just one
      return orngWrap.Tune1Parameter(
          parameter = "featureInducer.m",
          values = ms,
          object = inducer,
github biolab / orange2 / docs / tutorial / rst / code / regression2.py View on Github external
# Description: Builds regression models from data and outputs predictions for first five instances
# Category:    modelling
# Uses:        housing
# Classes:     MakeRandomIndices2, MajorityLearner, orngTree.TreeLearner, orange.kNNLearner
# Referenced:  regression.htm

import orange, orngTree, orngTest, orngStat

data = orange.ExampleTable("housing.tab")
selection = orange.MakeRandomIndices2(data, 0.5)
train_data = data.select(selection, 0)
test_data = data.select(selection, 1)

maj = orange.MajorityLearner(train_data)
maj.name = "default"

rt = orngTree.TreeLearner(train_data, measure="retis", mForPruning=2, minExamples=20)
rt.name = "reg. tree"

k = 5
knn = orange.kNNLearner(train_data, k=k)
knn.name = "k-NN (k=%i)" % k

regressors = [maj, rt, knn]

print "\n%10s " % "original",
for r in regressors:
  print "%10s " % r.name,
print
github biolab / orange2 / orange / doc / ofb / regression2.py View on Github external
# Description: Builds regression models from data and outputs predictions for first five instances
# Category:    modelling
# Uses:        housing
# Classes:     MakeRandomIndices2, MajorityLearner, orngTree.TreeLearner, orange.kNNLearner
# Referenced:  regression.htm

import orange, orngTree, orngTest, orngStat

data = orange.ExampleTable("../datasets/housing.tab")
selection = orange.MakeRandomIndices2(data, 0.5)
train_data = data.select(selection, 0)
test_data = data.select(selection, 1)

maj = orange.MajorityLearner(train_data)
maj.name = "default"

rt = orngTree.TreeLearner(train_data, measure="retis", mForPruning=2, minExamples=20)
rt.name = "reg. tree"

k = 5
knn = orange.kNNLearner(train_data, k=k)
knn.name = "k-NN (k=%i)" % k

regressors = [maj, rt, knn]

print "\n%10s " % "original",
for r in regressors:
  print "%10s " % r.name,
print
github biolab / orange2 / orange / orng / orngRegression.py View on Github external
# continuization (replaces discrete with continuous attributes)
        continuizer = orange.DomainContinuizer()
        continuizer.multinomialTreatment = continuizer.FrequentIsBase
        continuizer.zeroBased = True
        domain0 = continuizer(data)
        data = data.translate(domain0)

        if self.stepwise and not self.stepwise_before:
            use_attributes=stepwise(data,weight,add_sig=self.add_sig,remove_sig=self.remove_sig)
            new_domain = orange.Domain(use_attributes, data.domain.classVar)
            new_domain.addmetas(data.domain.getmetas())
            data = orange.ExampleTable(new_domain, data)        
        
        # missing values handling (impute missing)
        imputer = orange.ImputerConstructor_model()
        imputer.learnerContinuous = orange.MajorityLearner()
        imputer.learnerDiscrete = orange.MajorityLearner()
        imputer = imputer(data)
        data = imputer(data)

        # convertion to numpy
        A, y, w = data.toNumpy()        # weights ??
        if A==None:
            n = len(data)
            m = 0
        else:
            n, m = numpy.shape(A)
     
        if self.beta0 == True:
             if A==None:
                 X = numpy.ones([len(data),1])
             else:
github cuthbertLab / music21 / music21 / demos / ismir2011.py View on Github external
def xtestChinaEuropeSimpler():
    import orange, orngTree # @UnusedImport @UnresolvedImport

    trainData = orange.ExampleTable('ismir2011_fb_folkTrain.tab')
    testData  = orange.ExampleTable('ismir2011_fb_folkTest.tab')

    majClassifier = orange.MajorityLearner(trainData)
    knnClassifier = orange.kNNLearner(trainData)

    majWrong = 0
    knnWrong = 0

    for testRow in testData:
        majGuess = majClassifier(testRow)
        knnGuess = knnClassifier(testRow)
        realAnswer = testRow.getclass()
        if majGuess != realAnswer:
            majWrong += 1
        if knnGuess != realAnswer:
            knnWrong += 1

    total = float(len(testData))
    print (majWrong/total, knnWrong/total)
github biolab / orange2 / docs / tutorial / rst / code / regression4.py View on Github external
# Uses:        housing
# Classes:     orngTest.crossValidation, orngTree.TreeLearner, orange.kNNLearner, orngRegression.LinearRegressionLearner
# Referenced:  regression.htm

import orange
import orngRegression
import orngTree
import orngStat, orngTest

data = orange.ExampleTable("housing")

# definition of learners (regressors)
lr = orngRegression.LinearRegressionLearner(name="lr")
rt = orngTree.TreeLearner(measure="retis", mForPruning=2,
                          minExamples=20, name="rt")
maj = orange.MajorityLearner(name="maj")
knn = orange.kNNLearner(k=10, name="knn")
learners = [maj, lr, rt, knn]

# evaluation and reporting of scores
results = orngTest.crossValidation(learners, data, folds=10)
scores = [("MSE", orngStat.MSE),
          ("RMSE", orngStat.RMSE),
          ("MAE", orngStat.MAE),
          ("RSE", orngStat.RSE),
          ("RRSE", orngStat.RRSE),
          ("RAE", orngStat.RAE),
          ("R2", orngStat.R2)]

print "Learner  " + "".join(["%-7s" % s[0] for s in scores])
for i in range(len(learners)):
    print "%-8s " % learners[i].name + "".join(["%6.3f " % s[1](results)[i] for s in scores])
github biolab / orange2 / Orange / orng / orngVizRank.py View on Github external
def findArguments(self, example):
        self.clearArguments()
        if not self.graph.have_data or not self.graph.data_has_class or len(self.results) == 0:
            if len(self.results) == 0: print 'To classify an example using VizRank you first have to evaluate some projections.'
            return orange.MajorityLearner(self.graph.raw_data)(example, orange.GetBoth)

        self.arguments = [[] for i in range(len(self.graph.data_domain.classVar.values))]
        vals = [0.0 for i in range(len(self.arguments))]

        if self.rankArgumentsByStrength == 1:
            for index in range(min(len(self.results), self.argumentCount + 50)):
                classValue, dist = self.computeClassificationForExample(index, example, kValue = len(self.graph.raw_data))
                if classValue and dist:
                    for i in range(len(self.arguments)):
                        self.arguments[i].insert(self.getArgumentIndex(dist[i], i), (dist[i], dist, self.results[index][ATTR_LIST], index))

            for i in range(len(self.arguments)):
                arr = self.arguments[i]
                arr.sort()
                arr.reverse()
                arr = arr[:self.argumentCount]
github biolab / orange2 / docs / reference / rst / code / statExamplesRegression.py View on Github external
# Category:    evaluation
# Uses:        housing.tab
# Referenced:  orngStat.htm

import orange
import orngRegression as r
import orngTree
import orngStat, orngTest

data = orange.ExampleTable("housing")

# definition of regressors
lr = r.LinearRegressionLearner(name="lr")
rt = orngTree.TreeLearner(measure="retis", mForPruning=2,
                          minExamples=20, name="rt")
maj = orange.MajorityLearner(name="maj")
knn = orange.kNNLearner(k=10, name="knn")

learners = [maj, rt, knn, lr]

# cross validation, selection of scores, report of results
results = orngTest.crossValidation(learners, data, folds=3)
scores = [("MSE", orngStat.MSE),   ("RMSE", orngStat.RMSE),
          ("MAE", orngStat.MAE),   ("RSE", orngStat.RSE),
          ("RRSE", orngStat.RRSE), ("RAE", orngStat.RAE),
          ("R2", orngStat.R2)]

print "Learner   " + "".join(["%-8s" % s[0] for s in scores])
for i in range(len(learners)):
    print "%-8s " % learners[i].name + \
    "".join(["%7.3f " % s[1](results)[i] for s in scores])
github biolab / orange2 / docs / tutorial / rst / code / ensemble3.py View on Github external
# Description: Bagging and boosting with k-nearest neighbors
# Category:    modelling
# Uses:        promoters.tab
# Classes:     orngTest.crossValidation, orngEnsemble.BaggedLearner, orngEnsemble.BoostedLearner
# Referenced:  o_ensemble.htm

import orange, orngTest, orngStat, orngEnsemble
data = orange.ExampleTable("promoters")

majority = orange.MajorityLearner()
majority.name = "default"
knn = orange.kNNLearner(k=11)
knn.name = "k-NN (k=11)"

bagged_knn = orngEnsemble.BaggedLearner(knn, t=10)
bagged_knn.name = "bagged k-NN"
boosted_knn = orngEnsemble.BoostedLearner(knn, t=10)
boosted_knn.name = "boosted k-NN"

learners = [majority, knn, bagged_knn, boosted_knn]
results = orngTest.crossValidation(learners, data, folds=10)
print "        Learner   CA     Brier Score"
for i in range(len(learners)):
    print ("%15s:  %5.3f  %5.3f") % (learners[i].name,
        orngStat.CA(results)[i], orngStat.BrierScore(results)[i])