Esempio n. 1
0
def accuracy_auc(y, ypred, weights=None):
    """Compute the accuracy, AUC, precision, recall and f1"""
    from mozsci.evaluation import classification_error, auc_wmw_fast, precision_recall_f1
    prf1 = precision_recall_f1(y, ypred, weights=weights)
    return {'accuracy': 1.0 - classification_error(y, ypred, weights=weights),
            'auc': auc_wmw_fast(y, ypred, weights=weights),
            'precision': prf1[0],
            'recall': prf1[1],
            'f1': prf1[2]}
Esempio n. 2
0
def accuracy_auc(y, ypred, weights=None):
    """Compute the accuracy, AUC, precision, recall and f1"""
    from mozsci.evaluation import classification_error, auc_wmw_fast, precision_recall_f1
    prf1 = precision_recall_f1(y, ypred, weights=weights)
    return {'accuracy': 1.0 - classification_error(y, ypred, weights=weights),
            'auc': auc_wmw_fast(y, ypred, weights=weights),
            'precision': prf1[0],
            'recall': prf1[1],
            'f1': prf1[2]}
Esempio n. 3
0
    def test_precision_recall_f1(self):
        tp = 1.0
        fp = 3.0
        fn = 2.0

        actual_prec_rec_f1 = Test_precision_recall_f1.prec_rec_f1_from_tp_fp_fn(tp, fp, fn)
        for y in [self.yactual, self.yactual1]:
            for ypred in [self.ypred, self.ypred1]:
                prec_rec_f1 = evaluation.precision_recall_f1(y, ypred)
                for k in range(3):
                    self.assertTrue(abs(actual_prec_rec_f1[k] - prec_rec_f1[k]) < 1e-12)
Esempio n. 4
0
    def test_degenerate(self):
        # test case with degenerate input
        y = np.array([0])
        ypred = np.array([[ 1.0]])
        weights = np.array([1])
        prf = evaluation.precision_recall_f1(y, ypred, weights=weights)

        # check that none are NaN
        self.assertFalse(np.array([np.isnan(ele) for ele in prf]).any())

        # and they should all be 0
        self.assertTrue(np.allclose(prf, [0, 0, 0]))
Esempio n. 5
0
    def test_degenerate(self):
        # test case with degenerate input
        y = np.array([0])
        ypred = np.array([[1.0]])
        weights = np.array([1])
        prf = evaluation.precision_recall_f1(y, ypred, weights=weights)

        # check that none are NaN
        self.assertFalse(np.array([np.isnan(ele) for ele in prf]).any())

        # and they should all be 0
        self.assertTrue(np.allclose(prf, [0, 0, 0]))
Esempio n. 6
0
    def test_precision_recall_f1_weighted(self):
        tp = 5.0
        fp = 2.0 + 3 + 4
        fn = 6.0 + 7

        actual_prec_rec_f1 = Test_precision_recall_f1.prec_rec_f1_from_tp_fp_fn(tp, fp, fn)

        for y in [self.yactual, self.yactual1]:
            for ypred in [self.ypred, self.ypred1]:
                for weights in [self.weights, self.weights1]:
                    prec_rec_f1 = evaluation.precision_recall_f1(y, ypred, weights=weights)
                    for k in range(3):
                        self.assertTrue(abs(actual_prec_rec_f1[k] - prec_rec_f1[k]) < 1e-12)
Esempio n. 7
0
    def test_precision_recall_f1(self):
        tp = 1.0
        fp = 3.0
        fn = 2.0

        actual_prec_rec_f1 = Test_precision_recall_f1.prec_rec_f1_from_tp_fp_fn(
            tp, fp, fn)
        for y in [self.yactual, self.yactual1]:
            for ypred in [self.ypred, self.ypred1]:
                prec_rec_f1 = evaluation.precision_recall_f1(y, ypred)
                for k in xrange(3):
                    self.assertTrue(
                        abs(actual_prec_rec_f1[k] - prec_rec_f1[k]) < 1e-12)
Esempio n. 8
0
    def test_precision_recall_f1_weighted(self):
        tp = 5.0
        fp = 2.0 + 3 + 4
        fn = 6.0 + 7

        actual_prec_rec_f1 = Test_precision_recall_f1.prec_rec_f1_from_tp_fp_fn(
            tp, fp, fn)

        for y in [self.yactual, self.yactual1]:
            for ypred in [self.ypred, self.ypred1]:
                for weights in [self.weights, self.weights1]:
                    prec_rec_f1 = evaluation.precision_recall_f1(
                        y, ypred, weights=weights)
                    for k in xrange(3):
                        self.assertTrue(
                            abs(actual_prec_rec_f1[k] -
                                prec_rec_f1[k]) < 1e-12)