Ejemplo n.º 1
0
 def test_precision_eval(self):
     p = Precision()
     precision_q1 = p.eval_per_query(self.y_query1, self.y_pred_query1)
     precision_q2 = p.eval_per_query(self.y_query2, self.y_pred_query2)
     precision_dataset = p.eval(self.dataset, self.y_pred)
     assert_almost_equal(precision_dataset[0],
                         np.mean([precision_q1, precision_q2]),
                         decimal=9)
Ejemplo n.º 2
0
    def test_precision_eval_per_query_cutoff(self):
        p = Precision(cutoff=1)
        result = p.eval_per_query(self.y_query1, self.y_pred_query1)
        assert_equal(result, 1.)

        p = Precision(cutoff=2)
        result = p.eval_per_query(self.y_query1, self.y_pred_query1)
        assert_equal(result, 1.)

        p = Precision(cutoff=3)
        result = p.eval_per_query(self.y_query1, self.y_pred_query1)
        assert_equal(result, 2. / 3)
Ejemplo n.º 3
0
    def test_precision_eval_per_query_threshold(self):
        p = Precision(threshold=2)
        result = p.eval_per_query(self.y_query1, self.y_pred_query1)
        assert_equal(result, 2. / 5)

        p = Precision(threshold=1)
        result = p.eval_per_query(self.y_query1, self.y_pred_query1)
        assert_equal(result, 3. / 5)
Ejemplo n.º 4
0
 def test_precision_eval_per_query(self):
     p = Precision()
     result = p.eval_per_query(self.y_query1, self.y_pred_query1)
     assert_equal(result, 3. / 5)
     result = p.eval_per_query(self.y_query2, self.y_pred_query2)
     assert_equal(result, 2. / 5)