def test_lift(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.30, 0.46, 0.62, 0.76, 0.46, 0.35, 0.56]) dict_score = {"0": {0: 0, 1: 1}, "0.4": {0: 2, 1: 1.43}, "0.6": {0: 1.43, 1: 2}} eva = Evaluation("binary") split_thresholds = [0, 0.4, 0.6] lifts = eva.lift(y_true, y_predict, thresholds=split_thresholds) fix_lifts = [] for lift in lifts: fix_lift = [round(pos, 2) for pos in lift] fix_lifts.append(fix_lift) for i in range(len(split_thresholds)): score_0 = dict_score[str(split_thresholds[i])][0] score_1 = dict_score[str(split_thresholds[i])][1] pos_lift = fix_lifts[i] self.assertEqual(len(pos_lift), 2) self.assertFloatEqual(score_0, pos_lift[0]) self.assertFloatEqual(score_1, pos_lift[1])
def test_lift(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.30, 0.46, 0.62, 0.76, 0.46, 0.35, 0.56]) lift_y_true = [[1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.1111111111111112, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.25, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.4285714285714286, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [1.6666666666666667, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.4285714285714286], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.25], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112], [2.0, 1.1111111111111112]] lift_x_true = [[1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.8, 0.2], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.7, 0.3], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [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.5, 0.5], [0.5, 0.5], [0.5, 0.5], [0.5, 0.5], [0.5, 0.5], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.3, 0.7], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.2, 0.8], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9]] eva = Evaluation() eva._init_model(EvaluateParam(eval_type=consts.BINARY, pos_label=1)) lift_y, lift_x, thresholds = eva.lift(y_true, y_predict) self.assertListEqual(lift_y, lift_y_true) self.assertListEqual(lift_x, lift_x_true)