def test2(): """ tests the max_kappa function that finds the maximum kappa value for 2 sets of predictions up to permutations of the cluster numberings """ pred1 = np.array([0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0]) pred2 = np.array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2]) x = np.array([[2, 0, 3], [5, 0, 0], [1, 4, 0]]) kappa_max, corrected_x, new_order = max_kappa(pred1, pred2) assert_allclose(x[:, new_order], corrected_x) assert kappa_max == kappa_function(x[:, new_order])
def test1(): """ tests the kappa_function """ x = np.array([[2, 0, 3], [5, 0, 0], [1, 4, 0]]) pred1 = np.array([0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0]) pred2 = np.array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2]) assert_allclose(x, sklearn.metrics.confusion_matrix(pred1, pred2)) # kappa calculation: # matrix data # [2,0,3] 5 # [5,0,0] 5 # [1,4,0] 5 # 8 4 3 15 # P_o = 2/15 # P_e = (8*5 + 4*5 + 3*5)/(15^2) = 1/3 # kappa_value = (P_o-P_e)/(1-P_e) = (2/15-1/3)/(1-1/3) = -.299999 assert kappa_function(x) == (2 / 15 - 1 / 3) / (1 - 1 / 3)