(self, labels, pred_scores)
compute confusion matrix
compute confusion matrix
compute confusion matrix
def confusion_mat(self, labels, pred_scores):

        """
        compute confusion matrix
        """

        if self.eval_type == consts.BINARY:

            sorted_labels, sorted_scores = classification_metric.sort_score_and_label(labels, pred_scores)
            score_threshold, cuts = classification_metric.ThresholdCutter.cut_by_step(sorted_scores, steps=0.01)
            score_threshold.append(0)
            confusion_mat = classification_metric.ConfusionMatrix.compute(sorted_labels, sorted_scores,
                                                                          score_threshold,
                                                                          ret=['tp', 'fp', 'fn', 'tn'])

            confusion_mat['tp'] = self.__to_int_list(confusion_mat['tp'])
            confusion_mat['fp'] = self.__to_int_list(confusion_mat['fp'])
            confusion_mat['fn'] = self.__to_int_list(confusion_mat['fn'])
            confusion_mat['tn'] = self.__to_int_list(confusion_mat['tn'])

            return confusion_mat, cuts, score_threshold
        else:
            logging.warning('error: f-score metric is for binary classification only')
def confusion_mat ( self , labels , pred_scores ) : if self . eval_type == consts . BINARY : sorted_labels , sorted_scores = classification_metric . sort_score_and_label ( labels , pred_scores ) score_threshold , cuts = classification_metric . ThresholdCutter . cut_by_step ( sorted_scores , steps = 0.01 ) score_threshold . append ( 0 ) confusion_mat = classification_metric . ConfusionMatrix . compute ( sorted_labels , sorted_scores , score_threshold , ret = [ 'tp' , 'fp' , 'fn' , 'tn' ] ) confusion_mat [ 'tp' ] = self . __to_int_list ( confusion_mat [ 'tp' ] ) confusion_mat [ 'fp' ] = self . __to_int_list ( confusion_mat [ 'fp' ] ) confusion_mat [ 'fn' ] = self . __to_int_list ( confusion_mat [ 'fn' ] ) confusion_mat [ 'tn' ] = self . __to_int_list ( confusion_mat [ 'tn' ] ) return confusion_mat , cuts , score_threshold else : logging . warning ( 'error: f-score metric is for binary classification only' )