def inputPMML(self): """""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(pmmlNaiveBayesModel)[0] self._existingTests = self._model.getChildrenOfType(pmmlNaiveBayes) self._localTransformations = self._model.getChildrenOfType(pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None seg={} if (self.__mode=='Update'): for t in self._existingTests: for e in t.getChildrenOfType(pmmlSegments)[0].getChildrenOfType(pmmlExplicitSegment): seg[e.getAttribute('field')]=e.getAttribute('value') segment=Producer.tupelize(seg) if segment in self._baseDict.keys(): testdistributions=t.getChildrenOfType(pmmlNaiveBayes)[0].getChildrenOfType(pmmlNaiveBayesInputs) try: test=testdistributions[0] test.makeAttribute("sample","0") vctable={} for vc in test.getChildrenOfType(pmmlValueCount): vctable[vc.getAttribute('value')]=float(vc.getAttribute('count')) self._baseDict[segment]=[0,vctable,False] except: pass
def inputPMML(self): """This function reads in a pmml file and saves the things we are going to be reusing when we collect stats.""" if self.__timer: self.__timer.output("Inputting model") # input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(pmmlBaselineModel)[0] self._existingTests = self._model.getChildrenOfType(pmmlTestDistributions) self._localTransformations = self._model.getChildrenOfType(pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None # It looks like this will only work for explicit segments seg = {} if self.__mode == "Update": for t in self._existingTests: for e in t.getChildrenOfType(pmmlSegments)[0].getChildrenOfType(pmmlExplicitSegment): seg[e.getAttribute("field")] = e.getAttribute("value") segment = Producer.tupelize(seg) if segment in self._baseDict.keys(): testdistributions = t.getChildrenOfType(pmmlBaseline)[0].getChildrenOfType(pmmlDiscreteDistribution) try: test = testdistributions[0] test.makeAttribute("sample", "0") vctable = {} for vc in test.getChildrenOfType(pmmlValueCount): vctable[vc.getAttribute("value")] = float(vc.getAttribute("count")) self._baseDict[segment] = [0, vctable, False] except: pass
def inputPMML(self): """This function reads in a pmml file and saves the things we are going to be reusing when we collect stats.""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(self._modelType)[0] self._localTransformations = self._model.getChildrenOfType(pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None
def inputPMML(self): """This function reads in a pmml file and saves the things we are going to be reusing when we collect stats.""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(self._modelType)[0] self._localTransformations = self._model.getChildrenOfType( pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None
def inputPMML(self, pmmlModelClass): if self._timer: self._timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() try: reader.parse(str(self.__input)) except: print str(self.__input) self._pmml = reader.root # Specific elements of regression models: self._model = self._pmml.getChildrenOfType(pmmlModelClass)[0] # Container of local transformations (if any) self._localTransformations = self._model.getChildrenOfType(pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None
def inputPMML(self): """This function reads in a pmml file and saves the things we are going to be reusing when we collect stats.""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(pmmlNaiveBayesModel)[0] #self._existingTests = self._model.getChildrenOfType(pmmlNaiveBayes) self._inputs = self._model.getChildrenOfType(pmmlBayesInputs)[0] self._output = self._model.getChildrenOfType(pmmlBayesOutput)[0] self._localTransformations = self._model.getChildrenOfType(pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None #It looks like this will only work for explicit segments """
def inputPMML(self, pmmlModelClass): if self._timer: self._timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() try: reader.parse(str(self.__input)) except: print str(self.__input) self._pmml = reader.root # Specific elements of regression models: self._model = self._pmml.getChildrenOfType(pmmlModelClass)[0] # Container of local transformations (if any) self._localTransformations = self._model.getChildrenOfType( pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None
def inputPMML(self): """This function reads in a pmml file and saves the things we are going to be reusing when we collect stats.""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(pmmlNaiveBayesModel)[0] #self._existingTests = self._model.getChildrenOfType(pmmlNaiveBayes) self._inputs = self._model.getChildrenOfType(pmmlBayesInputs)[0] self._output = self._model.getChildrenOfType(pmmlBayesOutput)[0] self._localTransformations = self._model.getChildrenOfType( pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None #It looks like this will only work for explicit segments """
def inputPMML(self): """""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(pmmlBaselineModel)[0] self._existingTests = self._model.getChildrenOfType( pmmlTestDistributions) self._localTransformations = self._model.getChildrenOfType( pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None seg = {} if (self.__mode == 'Update'): for t in self._existingTests: for e in t.getChildrenOfType(pmmlSegments)[ 0].getChildrenOfType(pmmlExplicitSegment): seg[e.getAttribute('field')] = e.getAttribute('value') segment = Producer.tupelize(seg) if segment in self._baseDict.keys(): testdistributions = t.getChildrenOfType(pmmlBaseline)[ 0].getChildrenOfType(pmmlDiscreteDistribution) try: test = testdistributions[0] test.makeAttribute("sample", "0") vctable = {} for vc in test.getChildrenOfType(pmmlValueCount): vctable[vc.getAttribute('value')] = float( vc.getAttribute('count')) self._baseDict[segment] = [0, vctable, False] except: pass
def inputPMML(self): """This function reads in a pmml file and saves the things we are going to be reusing when we collect stats.""" if self.__timer: self.__timer.output("Inputting model") #input the portion of the model that is completed reader = pmmlReader() reader.parse(str(self.__input)) self._pmml = reader.root self._model = self._pmml.getChildrenOfType(self._modelType)[0] self._localTransformations = self._model.getChildrenOfType(pmmlLocalTransformations) if len(self._localTransformations) > 0: self._localTransformations = self._localTransformations[0] else: self._localTransformations = None self.fields = [] for clusteringField in self._model.getChildrenOfType(pmmlClusteringField): self.fields.append(clusteringField.getAttributes()["field"]) try: self.numberOfClusters = int(self._model.getAttributes()['numberOfClusters']) except TypeError: raise ValueError("The numberOfClusters must be specified in ClusteringModel as an integer.") self.clusterNames = [] self.clusters = [] for cluster in self._model.getChildrenOfType(pmmlCluster): try: self.clusterNames.append(cluster.getAttributes()['name']) except TypeError: raise ValueError("Each cluster must have a 'name' attribute.") self.clusters.append(cluster.getChildrenOfType(pmmlArray)[0].array_values) if len(self.clusterNames) != self.numberOfClusters: raise ValueError("Number of Clusters in ClusteringModel (%d) does not match numberOfClusters attribute (%d)." % (len(self.clusterNames), self.numberOfClusters))