示例#1
0
 def case_continency_table(self, m, L):
     if L > 0:
         hi = np.random.randint(2, size=m).tolist()
         hj = np.random.randint(2, size=m).tolist()
     else:
         hi = np.random.randint(2, size=m) * 2 - 1
         hj = np.random.randint(2, size=m) * 2 - 1
         hi, hj = hi.tolist(), hj.tolist()
     #   #
     a, b, c, d = contingency_table(hi, hj)
     self.assertEqual(a + b + c + d, m, "Wrong shape! a + b + c + d != m")
示例#2
0
def test_multiclass_contingency_table_part3():
    m = 31  # number of instances / samples
    L = 2  # number of labels / classes
    hi = (np.random.randint(L, size=m) * 2 - 1).tolist()
    hj = (np.random.randint(L, size=m) * 2 - 1).tolist()
    y = (np.random.randint(L, size=m) * 2 - 1).tolist()
    #
    Cij = multiclass_contingency_table(hi, hj, y)
    a, b, c, d = contingency_table(hi, hj)
    if not (((a == Cij[0][0]) and (d == Cij[1][1])) or ((a == Cij[1][1]) and (d == Cij[0][0]))):
        raise AssertionError("Wrong values in shape.")
    if not (((b == Cij[0][1]) and (c == Cij[1][0])) or ((b == Cij[1][0]) and (c == Cij[0][1]))):
        raise AssertionError("Wrong values in shape.")
示例#3
0
 def test_multiclass_contingency_table_part3(self):
     m = 31  # number of instances / samples
     L = 2  # number of labels / classes
     hi = (np.random.randint(L, size=m) * 2 - 1).tolist()
     hj = (np.random.randint(L, size=m) * 2 - 1).tolist()
     y = (np.random.randint(L, size=m) * 2 - 1).tolist()
     Cij = multiclass_contingency_table(hi, hj, y)
     a, b, c, d = contingency_table(hi, hj)
     #
     judge_ad = ((a == Cij[0][0]) and (d == Cij[1][1])) or \
                ((a == Cij[1][1]) and (d == Cij[0][0]))
     judge_bc = ((b == Cij[0][1]) and (c == Cij[1][0])) or \
                ((b == Cij[1][0]) and (c == Cij[0][1]))
     self.assertEqual(judge_ad, True, "Wrong values in shape.")
     self.assertEqual(judge_bc, True, "Wrong values in shape.")
示例#4
0
def case_contingency_table(m, L):
    # m:  number of instances / samples
    # L:  number of labels / classes
    if L > 0:
        hi = np.random.randint(2, size=m).tolist()
        hj = np.random.randint(2, size=m).tolist()
    else:
        hi = np.random.randint(2, size=m) * 2 - 1
        hj = np.random.randint(2, size=m) * 2 - 1
        hi, hj = hi.tolist(), hj.tolist()
    #   #
    a, b, c, d = contingency_table(hi, hj)
    #
    # print("hi", hi)
    # print("hj", hj)
    if not (a + b + c + d == m):
        raise AssertionError("Wrong shape! a + b + c + d != m")
示例#5
0
def Kappa_Statistic_binary(hi, hj, m):
    a, b, c, d = contingency_table(hi, hj)
    Theta_1 = (a + d) / float(m)
    Theta_2 = ((a + b) * (a + c) + (c + d) * (b + d)) / (float(m)**2)
    return (Theta_1 - Theta_2) / check_zero(1. - Theta_2)
示例#6
0
def Correlation_Coefficient_binary(hi, hj):
    a, b, c, d = contingency_table(hi, hj)
    denominator = (a + b) * (a + c) * (c + d) * (b + d)
    denominator = np.sqrt(denominator)
    return (a * d - b * c) / check_zero(denominator)
示例#7
0
def Q_Statistic_binary(hi, hj):
    a, b, c, d = contingency_table(hi, hj)
    tem = a * d + b * c
    return (a * d - b * c) / check_zero(tem)
示例#8
0
def Disagreement_Measure_binary(hi, hj, m):
    _, b, c, _ = contingency_table(hi, hj)
    return (b + c) / float(m)