Пример #1
0
    def test_multi_accuracy(self):
        y_true = np.array([1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4])
        y_predict = [1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 3, 3, 3, 3, 2, 4, 4, 4, 4, 4]
        gt_score = 0.6
        gt_number = 12
        eva = Evaluation("multi")

        acc = eva.accuracy(y_true, y_predict)
        self.assertFloatEqual(gt_score, acc)
        acc_number = eva.accuracy(y_true, y_predict, normalize=False)
        self.assertEqual(acc_number, gt_number)
Пример #2
0
    def test_bin_accuracy(self):
        y_true = np.array([1, 1, 0, 0, 0, 1, 1, 0, 0, 1])
        y_predict = np.array([0.57, 0.70, 0.25, 0.31, 0.46, 0.62, 0.76, 0.46, 0.35, 0.56])
        gt_score = {"0.3": 0.6, "0.5": 1.0, "0.7": 0.7}

        split_thresholds = [0.3, 0.5, 0.7]
        eva = Evaluation("binary")

        acc = eva.accuracy(y_true, y_predict, thresholds=split_thresholds)
        for i in range(len(split_thresholds)):
            score = gt_score[str(split_thresholds[i])]
            self.assertFloatEqual(score, acc[i])
Пример #3
0
    def test_multi_accuracy(self):

        y_true = np.array(
            [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4])
        y_predict = [
            1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 3, 3, 3, 3, 2, 4, 4, 4, 4, 4
        ]
        gt_score = 0.6

        eva = Evaluation()
        eva._init_model(EvaluateParam(eval_type=consts.MULTY, pos_label=1))

        acc = eva.accuracy(y_true, y_predict)
        self.assertFloatEqual(acc, gt_score)
Пример #4
0
    def test_bin_accuracy(self):

        y_true = np.array([1, 1, 0, 0, 0, 1, 1, 0, 0, 1])
        y_predict = np.array(
            [0.57, 0.70, 0.25, 0.31, 0.46, 0.62, 0.76, 0.46, 0.35, 0.56])
        gt_score = [
            0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.6,
            0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.7, 0.7, 0.7,
            0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.8, 0.8, 0.8, 0.8, 0.8,
            0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9,
            0.9, 0.9, 0.9, 0.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
            1.0, 1.0, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
            0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.6, 0.6,
            0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6
        ]

        eva = Evaluation()
        eva._init_model(EvaluateParam(eval_type=consts.BINARY, pos_label=1))

        acc, cuts, thresholds = eva.accuracy(y_true, y_predict)

        self.assertListEqual(acc, gt_score)