(self, train_scores: list, validate_scores: list, train_labels=None, validate_labels=None,
                debug=False, str_intervals=False, round_num=3, pos_label=1)
train/validate scores: predicted scores on train/validate set
        train/validate labels: true labels
        debug: print debug message
        if train&validate labels are not None, count positive sample percentage in every interval
        pos_label: pos label
        round_num： round number
        str_intervals: return str intervals
train/validate scores: predicted scores on train/validate set
        train/validate labels: true labels
        debug: print debug message
        if train&validate labels are not None, count positive sample percentage in every interval
        pos_label: pos label
        round_num： round number
        str_intervals: return str intervals
train / validate scores : predicted scores on train / validate set train / validate labels : true labels debug : print debug message if train&validate labels are not None count positive sample percentage in every interval pos_label : pos label round_num： round number str_intervals : return str intervals
def compute(self, train_scores: list, validate_scores: list, train_labels=None, validate_labels=None,
                debug=False, str_intervals=False, round_num=3, pos_label=1):

        """
        train/validate scores: predicted scores on train/validate set
        train/validate labels: true labels
        debug: print debug message
        if train&validate labels are not None, count positive sample percentage in every interval
        pos_label: pos label
        round_num： round number
        str_intervals: return str intervals
        """

        train_scores = np.array(train_scores)
        validate_scores = np.array(validate_scores)
        quantile_points = ThresholdCutter().cut_by_quantile(train_scores)

        train_count = self.quantile_binning_and_count(train_scores, quantile_points)
        validate_count = self.quantile_binning_and_count(validate_scores, quantile_points)

        train_pos_perc, validate_pos_perc = None, None

        if train_labels is not None and validate_labels is not None:
            assert len(train_labels) == len(train_scores) and len(validate_labels) == len(validate_scores)
            train_labels, validate_labels = np.array(train_labels), np.array(validate_labels)
            train_pos_count = self.quantile_binning_and_count(train_scores[train_labels == pos_label], quantile_points)
            validate_pos_count = self.quantile_binning_and_count(validate_scores[validate_labels == pos_label],
                                                                 quantile_points)

            train_pos_perc = np.array(train_pos_count['count']) / np.array(train_count['count'])
            validate_pos_perc = np.array(validate_pos_count['count']) / np.array(validate_count['count'])

            # handle special cases
            train_pos_perc[train_pos_perc == np.inf] = -1
            validate_pos_perc[validate_pos_perc == np.inf] = -1
            train_pos_perc[np.isnan(train_pos_perc)] = 0
            validate_pos_perc[np.isnan(validate_pos_perc)] = 0

        if debug:
            print(train_count)
            print(validate_count)

        assert (train_count['interval'] == validate_count['interval']), 'train count interval is not equal to ' \
                                                                        'validate count interval'

        expected_interval = np.array(train_count['count'])
        actual_interval = np.array(validate_count['count'])

        expected_interval = expected_interval.astype(np.float)
        actual_interval = actual_interval.astype(np.float)

        psi_scores, total_psi, expected_interval, actual_interval, expected_percentage, actual_percentage \
            = self.psi_score(expected_interval, actual_interval, len(train_scores), len(validate_scores))

        intervals = train_count['interval'] if not str_intervals else PSI.intervals_to_str(train_count['interval'],
                                                                                           round_num=round_num)

        if train_labels is None and validate_labels is None:
            return psi_scores, total_psi, expected_interval, expected_percentage, actual_interval, actual_percentage, \
                   intervals
        else:
            return psi_scores, total_psi, expected_interval, expected_percentage, actual_interval, actual_percentage, \
                   train_pos_perc, validate_pos_perc, intervals
def compute ( self , train_scores : list , validate_scores : list , train_labels = None , validate_labels = None , debug = False , str_intervals = False , round_num = 3 , pos_label = 1 ) : train_scores = np . array ( train_scores ) validate_scores = np . array ( validate_scores ) quantile_points = ThresholdCutter ( ) . cut_by_quantile ( train_scores ) train_count = self . quantile_binning_and_count ( train_scores , quantile_points ) validate_count = self . quantile_binning_and_count ( validate_scores , quantile_points ) train_pos_perc , validate_pos_perc = None , None if train_labels is not None and validate_labels is not None : assert len ( train_labels ) == len ( train_scores ) and len ( validate_labels ) == len ( validate_scores ) train_labels , validate_labels = np . array ( train_labels ) , np . array ( validate_labels ) train_pos_count = self . quantile_binning_and_count ( train_scores [ train_labels == pos_label ] , quantile_points ) validate_pos_count = self . quantile_binning_and_count ( validate_scores [ validate_labels == pos_label ] , quantile_points ) train_pos_perc = np . array ( train_pos_count [ 'count' ] ) / np . array ( train_count [ 'count' ] ) validate_pos_perc = np . array ( validate_pos_count [ 'count' ] ) / np . array ( validate_count [ 'count' ] ) # handle special cases train_pos_perc [ train_pos_perc == np . inf ] = - 1 validate_pos_perc [ validate_pos_perc == np . inf ] = - 1 train_pos_perc [ np . isnan ( train_pos_perc ) ] = 0 validate_pos_perc [ np . isnan ( validate_pos_perc ) ] = 0 if debug : print ( train_count ) print ( validate_count ) assert ( train_count [ 'interval' ] == validate_count [ 'interval' ] ) , 'train count interval is not equal to ' 'validate count interval' expected_interval = np . array ( train_count [ 'count' ] ) actual_interval = np . array ( validate_count [ 'count' ] ) expected_interval = expected_interval . astype ( np . float ) actual_interval = actual_interval . astype ( np . float ) psi_scores , total_psi , expected_interval , actual_interval , expected_percentage , actual_percentage = self . psi_score ( expected_interval , actual_interval , len ( train_scores ) , len ( validate_scores ) ) intervals = train_count [ 'interval' ] if not str_intervals else PSI . intervals_to_str ( train_count [ 'interval' ] , round_num = round_num ) if train_labels is None and validate_labels is None : return psi_scores , total_psi , expected_interval , expected_percentage , actual_interval , actual_percentage , intervals else : return psi_scores , total_psi , expected_interval , expected_percentage , actual_interval , actual_percentage , train_pos_perc , validate_pos_perc , intervals