(self)
X^2 = ∑∑(A_ij - E_ij )^2 / E_ij
        where E_ij = (N_i / N) * C_j. N is total count of merged bucket, N_i is the total count of ith bucket
        and C_j is the count of jth label in merged bucket.
        A_ij is number of jth label in ith bucket.
X^2 = ∑∑(A_ij - E_ij )^2 / E_ij
        where E_ij = (N_i / N) * C_j. N is total count of merged bucket, N_i is the total count of ith bucket
        and C_j is the count of jth label in merged bucket.
        A_ij is number of jth label in ith bucket.
X^2 = ∑∑ ( A_ij - E_ij ) ^2 / E_ij where E_ij = ( N_i / N ) * C_j . N is total count of merged bucket N_i is the total count of ith bucket and C_j is the count of jth label in merged bucket . A_ij is number of jth label in ith bucket .
def cal_score(self):
        """
        X^2 = ∑∑(A_ij - E_ij )^2 / E_ij
        where E_ij = (N_i / N) * C_j. N is total count of merged bucket, N_i is the total count of ith bucket
        and C_j is the count of jth label in merged bucket.
        A_ij is number of jth label in ith bucket.
        """

        self.event_count = self.left_bucket.event_count + self.right_bucket.event_count
        self.non_event_count = self.left_bucket.non_event_count + self.right_bucket.non_event_count
        if self.total_count == 0:
            self.score = -math.inf
            return

        c1 = self.left_bucket.event_count + self.right_bucket.event_count
        c0 = self.left_bucket.non_event_count + self.right_bucket.non_event_count

        if c1 == 0 or c0 == 0:
            self.score = - math.inf
            return

        e_left_1 = (self.left_bucket.total_count / self.total_count) * c1
        e_left_0 = (self.left_bucket.total_count / self.total_count) * c0
        e_right_1 = (self.right_bucket.total_count / self.total_count) * c1
        e_right_0 = (self.right_bucket.total_count / self.total_count) * c0

        chi_square = np.square(self.left_bucket.event_count - e_left_1) / e_left_1 + \
                     np.square(self.left_bucket.non_event_count - e_left_0) / e_left_0 + \
                     np.square(self.right_bucket.event_count - e_right_1) / e_right_1 + \
                     np.square(self.right_bucket.non_event_count - e_right_0) / e_right_0
        LOGGER.debug("chi_sqaure: {}".format(chi_square))

        self.score = chi_square
def cal_score ( self ) : self . event_count = self . left_bucket . event_count + self . right_bucket . event_count self . non_event_count = self . left_bucket . non_event_count + self . right_bucket . non_event_count if self . total_count == 0 : self . score = - math . inf return c1 = self . left_bucket . event_count + self . right_bucket . event_count c0 = self . left_bucket . non_event_count + self . right_bucket . non_event_count if c1 == 0 or c0 == 0 : self . score = - math . inf return e_left_1 = ( self . left_bucket . total_count / self . total_count ) * c1 e_left_0 = ( self . left_bucket . total_count / self . total_count ) * c0 e_right_1 = ( self . right_bucket . total_count / self . total_count ) * c1 e_right_0 = ( self . right_bucket . total_count / self . total_count ) * c0 chi_square = np . square ( self . left_bucket . event_count - e_left_1 ) / e_left_1 + np . square ( self . left_bucket . non_event_count - e_left_0 ) / e_left_0 + np . square ( self . right_bucket . event_count - e_right_1 ) / e_right_1 + np . square ( self . right_bucket . non_event_count - e_right_0 ) / e_right_0 LOGGER . debug ( "chi_sqaure: {}" . format ( chi_square ) ) self . score = chi_square