示例#1
0
 def predict(self, features):
     """
     predict the label given the feature
     :param features: list[list]
     :return: labels
     """
     parentList = self.__BN.getParents()
     featureList = [featureAttri.name for featureAttri in self._featureTable]
     predY = []
     postProbY = []
     for i in range(len(features)):
         postProbY.append(copy.deepcopy(self.__P_y))
         for j in range(len(features[i])):
             featureIndex = self._featureTable[j].values.index(features[i][j])
             if j == 0:
                 for yIndex in range(len(self._featureTable[-1].values)):
                     postProbY[i][yIndex] *= self.__P_x_p12[j][yIndex][featureIndex]
             else:
                 p1 = featureList.index(parentList[self._featureTable[j].name][0])
                 p1Index = self._featureTable[p1].values.index(features[i][p1])
                 for yIndex in range(len(self._featureTable[-1].values)):
                     postProbY[i][yIndex] *= self.__P_x_p12[j][p1Index][yIndex][featureIndex]
         utils.uniformize(postProbY[i])
         predY.append(self._featureTable[-1].values[postProbY[i].index(max(postProbY[i]))])
     return predY, postProbY
示例#2
0
 def predict(self, features):
     """
     predict the label given the feature
     :param features: list[list]
     :return: labels, postProbY
     """
     labels = []
     postProbY = []
     for inst in features:
         postProbY.append(copy.deepcopy(self.__prob_y))
         for i in range(len(self._featureTable[-1].values)):
             for j in range(len(inst)):
                 postProbY[-1][i] *= self.__prob_x_y[i][j][inst[j]]
         utils.uniformize(postProbY[-1])
         labels.append(self._featureTable[-1].values[postProbY[-1].index(max(postProbY[-1]))])
     return labels, postProbY