Ignore:
Timestamp:
03/14/12 00:15:17 (2 years ago)
Author:
martin@…
Branch:
default
Message:

Improved learning of rules with ABCN2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/orng/orngABML.py

    r9737 r10518  
    99import math 
    1010 
    11 from Orange.classification.rules import create_dichotomous_class as createDichotomousClass 
    12 from Orange.classification.rules import ConvertClass 
    1311# regular expressions 
    1412# exppression for testing validity of a set of arguments: 
     
    286284 
    287285 
     286 
     287class ConvertClass: 
     288    """ Converting class variables into dichotomous class variable. """ 
     289    def __init__(self, classAtt, classValue, newClassAtt): 
     290        self.classAtt = classAtt 
     291        self.classValue = classValue 
     292        self.newClassAtt = newClassAtt 
     293 
     294    def __call__(self, example, returnWhat): 
     295        if example[self.classAtt] == self.classValue: 
     296            return Orange.data.Value(self.newClassAtt, self.classValue + "_") 
     297        else: 
     298            return Orange.data.Value(self.newClassAtt, "not " + self.classValue) 
     299 
     300 
     301def create_dichotomous_class(domain, att, value, negate, removeAtt=None): 
     302    # create new variable 
     303    newClass = Orange.feature.Discrete(att.name + "_", values=[str(value) + "_", "not " + str(value)]) 
     304    positive = Orange.data.Value(newClass, str(value) + "_") 
     305    negative = Orange.data.Value(newClass, "not " + str(value)) 
     306    newClass.getValueFrom = ConvertClass(att, str(value), newClass) 
     307 
     308    att = [a for a in domain.attributes] 
     309    newDomain = Orange.data.Domain(att + [newClass]) 
     310    newDomain.addmetas(domain.getmetas()) 
     311    if negate == 1: 
     312        return (newDomain, negative) 
     313    else: 
     314        return (newDomain, positive) 
     315 
     316 
     317 
    288318def addErrors(test_data, classifier): 
    289319    """ Main task of this function is to add probabilistic errors to examples.""" 
Note: See TracChangeset for help on using the changeset viewer.