Ejemplo n.º 1
0
 def __call__(self, trainingData = None, weight = None): 
     if not trainingData:
         print "AZBaseClasses ERROR: Missing training data!"
         self.basicStat = None
         return False
     elif dataUtilities.findDuplicatedNames(trainingData.domain):
         print "AZBaseClasses ERROR: Duplicated names found in the training data. Please use the method dataUtilities.DataTable() when loading a dataset in order to fix the duplicated names and avoid this error."
         self.basicStat = None
         return False
     possibleMetas = dataUtilities.getPossibleMetas(trainingData)
     if possibleMetas:
         print "AZBaseClasses ERROR: Detected attributes that should be considered meta-attributes:"
         for attr in possibleMetas:
             print "    ",attr
         return False
     #Get the Domain basic statistics and save only the desired info in self.basicStat
     basicStat = orange.DomainBasicAttrStat(trainingData)
     self.basicStat = {}
     for attr in trainingData.domain:
         if attr.varType == orange.VarTypes.Discrete:
             self.basicStat[attr.name] = None
         else:       
             self.basicStat[attr.name] = {"min":basicStat[attr].min, "max":basicStat[attr].max}
         
     return True
Ejemplo n.º 2
0
    def __call__(self, trainingData=None, weight=None, allowMetas=False):
        self.basicStat = None
        if not trainingData:
            print "AZBaseClasses ERROR: Missing training data!"
            return False
        elif dataUtilities.findDuplicatedNames(trainingData.domain):
            print "AZBaseClasses ERROR: Duplicated names found in the training data. Please use the method dataUtilities.DataTable() when loading a dataset in order to fix the duplicated names and avoid this error."
            return False
        elif not trainingData.domain.classVar:
            print "AZBaseClasses ERROR: No class attribute found in training data!"
            return False
        elif not len(trainingData):
            print "AZBaseClasses ERROR: No examples in training data!"
            return False
        elif not len(trainingData.domain.attributes):
            print "AZBaseClasses ERROR: No attributes in training data!"
            return False

        possibleMetas = dataUtilities.getPossibleMetas(trainingData,
                                                       checkIndividuality=True)
        if not allowMetas and possibleMetas:
            msg = "\nAZBaseClasses ERROR: Detected attributes that should be considered meta-attributes:"
            for attr in possibleMetas:
                msg += "\n    " + attr
            raise Exception(msg)
            #return False
        #Get the Domain basic statistics and save only the desired info in self.basicStat
        basicStat = orange.DomainBasicAttrStat(trainingData)
        self.basicStat = {}
        for attr in trainingData.domain:
            if attr.varType in [
                    orange.VarTypes.Discrete, orange.VarTypes.String
            ]:
                self.basicStat[attr.name] = None
            else:
                self.basicStat[attr.name] = {
                    "dev": basicStat[attr].dev,
                    "min": basicStat[attr].min,
                    "max": basicStat[attr].max,
                    "avg": basicStat[attr].avg
                }
        # Gather all the learner parameters to be stored along with the classifier
        # Find the name of the Learner
        learnerName = str(
            self.__class__)[:str(self.__class__).rfind("'")].split(".")[-1]
        self.parameters = {}
        if learnerName != "ConsensusLearner":
            # Load the AZLearnersParamsConfig.py from the AZORANGEHOME!
            AZOLearnersConfig = imp.load_source(
                "AZLearnersParamsConfig",
                os.path.join(os.environ["AZORANGEHOME"], 'azorange',
                             "AZLearnersParamsConfig.py"))
            pars = AZOLearnersConfig.API(learnerName)
            if pars:
                for par in pars.getParameterNames():
                    self.parameters[par] = getattr(self, par)
        return True
Ejemplo n.º 3
0
    def __call__(self, trainingData = None, weight = None): 
        self.basicStat = None
        if not trainingData:
            print "AZBaseClasses ERROR: Missing training data!"
            return False
        elif dataUtilities.findDuplicatedNames(trainingData.domain):
            print "AZBaseClasses ERROR: Duplicated names found in the training data. Please use the method dataUtilities.DataTable() when loading a dataset in order to fix the duplicated names and avoid this error."
            return False
        elif not trainingData.domain.classVar:
            print "AZBaseClasses ERROR: No class attribute found in training data!"
            return False
        elif not len(trainingData):
            print "AZBaseClasses ERROR: No examples in training data!"
            return False
        elif not len(trainingData.domain.attributes):
            print "AZBaseClasses ERROR: No attributes in training data!"
            return False



        possibleMetas = dataUtilities.getPossibleMetas(trainingData, checkIndividuality = True)
        if possibleMetas:
            msg="\nAZBaseClasses ERROR: Detected attributes that should be considered meta-attributes:"
            for attr in possibleMetas:
                msg += "\n    "+attr
            raise Exception(msg)
            #return False
        #Get the Domain basic statistics and save only the desired info in self.basicStat
        basicStat = orange.DomainBasicAttrStat(trainingData)
        self.basicStat = {}
        for attr in trainingData.domain:
            if attr.varType == orange.VarTypes.Discrete:
                self.basicStat[attr.name] = None
            else:       
                self.basicStat[attr.name] = {"min":basicStat[attr].min, "max":basicStat[attr].max, "avg":basicStat[attr].avg}
        # Gather all the learner parameters to be stored along with the classifier 
        # Find the name of the Learner
        learnerName = str(self.__class__)[:str(self.__class__).rfind("'")].split(".")[-1] 
        self.parameters = {}
        if learnerName != "ConsensusLearner":
            # Load the AZLearnersParamsConfig.py from the AZORANGEHOME!
            AZOLearnersConfig = imp.load_source("AZLearnersParamsConfig", os.path.join(os.environ["AZORANGEHOME"],'azorange',"AZLearnersParamsConfig.py"))
            pars = AZOLearnersConfig.API(learnerName)
            if pars:
                for par in pars.getParameterNames():
                    self.parameters[par] = getattr(self,par)
        return True