Martin Dočekal
initial commit
d0c77e3
raw
history blame contribute delete
2.6 kB
from unittest import TestCase
from precision_recall_fscore_accuracy import PrecisionRecallFscoreAccuracy
class PrecisionRecallFscoreAccuracyTestBinary(TestCase):
"""
All of these tests are also used for multiset configuration. So please mind this and write the test in a way that
it is valid for both configurations (do not use same label multiple times).
"""
def setUp(self):
self.metric = PrecisionRecallFscoreAccuracy(average="binary")
def test_eok(self):
self.assertDictEqual(
{
"precision": 1.0,
"recall": 1.0,
"fscore": 1.0,
"accuracy": 1.0,
},
self.metric.compute(
predictions=[0, 1, 0],
references=[0, 1, 0]
)
)
def test_eok_string(self):
self.assertDictEqual(
{
"precision": 1.0,
"recall": 1.0,
"accuracy": 1.0,
"fscore": 1.0
},
self.metric.compute(
predictions=["0", "1", "0"],
references=["0", "1", "0"]
)
)
def test_completely_different(self):
self.assertDictEqual(
{
"precision": 0.0,
"recall": 0.0,
"accuracy": 0.0,
"fscore": 0.0
},
self.metric.compute(
predictions=[0, 1, 0],
references=[1, 0, 1]
)
)
def test_max_precision(self):
self.assertDictEqual(
{
"precision": 1.0,
"recall": 0.5,
"accuracy": 0.5,
"fscore": 2 / 3
},
self.metric.compute(
predictions=[0, 1],
references=[1, 1]
)
)
def test_max_recall(self):
self.assertDictEqual(
{
"precision": 0.5,
"recall": 1.0,
"accuracy": 0.5,
"fscore": 2 / 3
},
self.metric.compute(
predictions=[1, 1],
references=[1, 0]
)
)
def test_partial_match(self):
self.assertDictEqual(
{
"precision": 0.5,
"recall": 0.5,
"accuracy": 0.5,
"fscore": 0.5
},
self.metric.compute(
predictions=[0, 1, 0, 1],
references=[1, 1, 0, 0]
)
)