def test_mcc_inverse(): golds = np.concatenate( (np.arange(2), np.random.randint(0, 2, size=np.random.randint(4, 100))), axis=0) preds = 1 - golds cm = ConfusionMatrix.create(golds, preds) np.testing.assert_allclose(cm.get_mcc(), -1.0, TOL)
def test(): C = np.random.randint(3, 11) golds = np.concatenate( (np.arange(C), np.random.randint(0, C, size=np.random.randint(4, 100))), axis=0) preds = np.random.randint(0, C, size=len(golds)) cm = ConfusionMatrix.create(golds, preds) np.testing.assert_allclose(cm.get_r_k(), explicit_r_k(cm._cm), TOL)
def test_r_k_inverse(): """The worst value for R k ranges from -1 to 0 depending on the distribution of the true labels.""" C = np.random.randint(2, 11) golds = np.concatenate( (np.arange(C), np.random.randint(0, C, size=np.random.randint(4, 100))), axis=0) preds = golds + 1 % C cm = ConfusionMatrix.create(golds, preds) assert -1.0 <= cm.get_r_k() <= 0.0
def test_r_k_perfect(): """Perfect correlation results in a score of 1.""" C = np.random.randint(2, 11) golds = np.concatenate( (np.arange(C), np.random.randint(0, C, size=np.random.randint(4, 100))), axis=0) preds = np.copy(golds) cm = ConfusionMatrix.create(golds, preds) np.testing.assert_allclose(cm.get_r_k(), 1.0)
def test(): golds = np.concatenate( (np.arange(2), np.random.randint(0, 2, size=np.random.randint(4, 100))), axis=0) preds = np.random.randint(0, 2, size=len(golds)) cm = ConfusionMatrix.create(golds, preds) np.testing.assert_allclose(cm.get_mcc(), explicit_mcc(golds, preds), TOL) np.testing.assert_allclose(cm.get_mcc(), author_mcc(cm._cm), TOL, TOL)
def test_mcc_example(): Y_TRUE = [1, 1, 1, 0] Y_PRED = [1, 0, 1, 1] MCC_GOLD = -0.3333333333333333 cm = ConfusionMatrix.create(Y_TRUE, Y_PRED) np.testing.assert_allclose(cm.get_mcc(), MCC_GOLD, TOL)
def test_create_cm(): gold = make_mc_cm() cm = ConfusionMatrix.create(Y_TRUE, Y_PRED) np.testing.assert_equal(gold._cm, cm._cm)