How to use the orange.Example 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 / orng / orngLR_Jakulin.py View on Github external
if self.normalization:
                  mi = 1e100
                  ma = -1e100
                  for ex in learn_data:
                      margin = classifier.getmargin(ex)
                      mi = min(mi,margin)
                      ma = max(ma,margin)
                  coeff = 1.0/max(ma-mi,1e-16)
              else:
                  coeff = 1.0  
              for ex in test_data:
                  margin = coeff*classifier.getmargin(ex)
                  if type(margin)==type(1.0) or type(margin)==type(1):
                      # ignore those examples which are handled with
                      # the actual probability distribution
                      mistake = orange.Example(estdomain,[float(margin), ex.getclass()])
                      if weight!=0:
                          mistake.setmeta(ex.getMetaAttribute(weight),1)
                      mistakes.append(mistake)

        if len(mistakes) < 1:
            # nothing to learn from
            if weight == 0:
                return self.learner(examples)
            else:
                return self.learner(examples,weight)
        if weight != 0:
            # learn a classifier to estimate the probabilities from margins
            # learn a classifier for the whole training set
            estimate = self.metalearner(mistakes, weight = 1)
            classifier = self.learner(examples, weight)
        else:
github biolab / orange2 / orange / doc / reference / example.py View on Github external
# Referenced:  Example.htm

import orange
data = orange.ExampleTable("lenses")
domain = data.domain

for attr in domain:
    print attr.name, attr.values

ex = orange.Example(domain)
print ex

ex = orange.Example(domain, ["young", "myope", "yes", "reduced", "soft"])
print ex

ex = orange.Example(domain, ["young", 0, 1, orange.Value(domain[3], \
                             "reduced"), "soft"])
print ex

reduced_dom = orange.Domain(["age", "lenses"], domain)
reduced_ex = orange.Example(reduced_dom, ex)
print reduced_ex

age = data.domain["age"]
example = data[0]
print example[0]
print example[age]
print example["age"]

print data[0]
d = data[0][0]
example[age] = (int(example[age])+1) % 3
github biolab / orange2 / orange / OrangeWidgets / Prototypes / OWDataGenerator.py View on Github external
def removeSelectedClassLabel(self):
        index = self.selectedClassLabelIndex()
        if index is not None and len(self.classValuesModel) > 1:
            label = self.classValuesModel[index]
            examples = [ex for ex in self.graph.data if str(ex.getclass()) != label]
            
            values = [val for val in self.classValuesModel if val != label]
            newclass = orange.EnumVariable("Class label", values=values)
            newdomain = orange.Domain(self.graph.data.domain.attributes, newclass)
            newdata = orange.ExampleTable(newdomain)
            for ex in examples:
                if ex[self.classVariable] != label and ex[self.classVariable] in values:
                    newdata.append(orange.Example(newdomain, [ex[a] for a in ex.domain.attributes] + [str(ex.getclass())]))
                
            self.classVariable = newclass
            self.classValuesModel.wrap(self.classVariable.values)
            
            self.graph.data = newdata
            self.graph.updateGraph()
            
            newindex = self.classValuesModel.index(max(0, index - 1))
            self.classValuesView.selectionModel().select(newindex, QItemSelectionModel.ClearAndSelect)
            
            self.removeClassLabel.setEnabled(len(self.classValuesModel) > 1)
github biolab / orange2 / Orange / orng / orngVizRank.py View on Github external
(accuracy, other_results, lenTable, attrList, tryIndex, generalDict) = self.results[projectionIndex]

        if 1 in [example[attr].isSpecial() for attr in attrList]: return None, None

        attrIndices = [self.graph.attribute_name_index[attr] for attr in attrList]
        attrVals = [self.graph.scale_example_value(example, ind) for ind in attrIndices]

        table = self.graph.create_projection_as_example_table(attrIndices, settingsDict = generalDict)
        [xTest, yTest] = self.graph.get_projected_point_position(attrIndices, attrVals, settingsDict = generalDict)

        learner = self.externalLearner or self.createkNNLearner(k = kValue)
        if self.useExampleWeighting: table, weightID = orange.Preprocessor_addClassWeight(table, equalize=1)
        else: weightID = 0

        classifier = learner(table, weightID)
        classVal, dist = classifier(orange.Example(table.domain, [xTest, yTest, "?"]), orange.GetBoth)
        return classVal, dist
github biolab / orange2 / orange / OrangeWidgets / Prototypes / OWDataGenerator.py View on Github external
def dataTransform(self, attr1, val1, attr2, val2):
        example = orange.Example(self.graph.data.domain)
        example[attr1] = val1
        example[attr2] = val2
        example.setclass(self.graph.data.domain.classVar(self.graph.data.domain.classVar.baseValue))
        self.graph.data.append(example)
        self.graph.updateGraph(dataInterval=(-1, sys.maxint))
github biolab / orange2 / orange / orngTextCorpus.py View on Github external
self.lem = lemmatizer.NOPLemmatization()
            
        cat = orange.StringVariable("category")
        meta = orange.StringVariable("meta")
        addCat = [cat, meta]
        if additionalTags:
            addCat.extend([orange.StringVariable(s) for s in additionalTags])
        dom = orange.Domain(addCat, 0)
        self.data = orange.ExampleTable(dom)
    
        f = open(fileName, "r")
        t = DocumentSetRetriever(f, tags = tags, doNotParse = doNotParse, additionalTags = additionalTags)       
        
        while 1:
            # load document
            ex = orange.Example(dom)
            
            doc = t.getNextDocument()
            if not len(doc): break
                
            if not len(charsPerDocRange) == 2:
                raise Exception('length of charsPerDocRange != 2')                
            if not charsPerDocRange[0] == -1:
                if len(doc['content']) <= charsPerDocRange[0]: continue
            if not charsPerDocRange[1] == -1:
                if len(doc['content']) >= charsPerDocRange[1]: continue
            
            ex['meta'] = " ".join([("%s=\"%s\"" % meta).encode('iso-8859-2') for meta in doc['meta']])
            ex['category'] = ".".join([d.encode('iso-8859-2') for d in doc['categories']])
            for tag in additionalTags:
                ex[tag.encode('iso-8859-2')] = (doc.has_key(tag) and [doc[tag].encode('iso-8859-2')] or [''])[0]
github biolab / orange2 / Orange / orng / orngInteract.py View on Github external
# 2006-08-23: added by PJ: add a class variable (if not already existing)
            if not t.domain.classVar:
                newatts.append(orange.EnumVariable("class", values=["."]))
                t = orange.ExampleTable(orange.Domain(t.domain.attributes, newatts[-1]), t)

            newd = orange.Domain(newatts)
            for ex in t:
                nex = []
                for i in range(len(newatts)):
                    if ex[i].isSpecial():
                        v = newatts[i]('.')
                    else:
                        v = newatts[i](int(ex[i]))
                    nex.append(v)
                exs.append(orange.Example(newd,nex))
            t = orange.ExampleTable(exs)
        return t
github biolab / orange2 / orange / Orange / classify / svm.py View on Github external
def getDecisionValues(self, example):
        example = orange.Example(self.wrapped.domain, example)
        return self.wrapped.getDecisionValues(example)
github biolab / orange2 / orange / orng / orng2Array.py View on Github external
def transformClass(self, classvector):
        # used for getting the label list
        r = []
        for i in classvector:
            newc = [0.0]
            x = orange.Example(orange.Domain([self.cv.attr]),[i])
            self.cv.apply(x,newc)
            r.append(newc[0])
        return r