• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pymarc_dedupe / 76e76f1a-5c1b-4fc6-ae21-8c08d3f6ab74

21 May 2025 04:25PM UTC coverage: 99.611% (-0.4%) from 100.0%
76e76f1a-5c1b-4fc6-ae21-8c08d3f6ab74

Pull #24

circleci

maxkadel
Small fixes
Pull Request #24: Green locally - connect to Postgres DB

204 of 207 new or added lines in 9 files covered. (98.55%)

2 existing lines in 1 file now uncovered.

769 of 772 relevant lines covered (99.61%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/src/confusion_matrix.py
1
class ConfusionMatrix:
1✔
2
    def __init__(self, labels_data, model_data):
1✔
3
        self.labels_data = labels_data
1✔
4
        self.model_data = model_data
1✔
5
        self.confusion_matrix = self.build_matrix()
1✔
6

7
    def build_matrix(self):
1✔
8
        confusion_matrix = dict(
1✔
9
            [
10
                ("true positive", 0),
11
                ("true negative", 0),
12
                ("false positive", 0),
13
                ("false negative", 0),
14
            ]
15
        )
16
        for label_row in self.labels_data:
1✔
17
            try:
1✔
18
                first_cluster_id = self.model_data[label_row["id1"]]["cluster_id"]
1✔
19
                second_cluster_id = self.model_data[label_row["id2"]]["cluster_id"]
1✔
20
                label = int(label_row["label"])
1✔
21
                model_guess = self.model_guess(first_cluster_id, second_cluster_id)
1✔
22
                if label == model_guess == 1:
1✔
23
                    confusion_matrix["true positive"] += 1
1✔
24
                elif label == model_guess == 0:
1✔
25
                    confusion_matrix["true negative"] += 1
1✔
26
                elif label != model_guess and label == 1:
1✔
27
                    confusion_matrix["false negative"] += 1
1✔
28
                elif label != model_guess and label == 0:
1✔
29
                    confusion_matrix["false positive"] += 1
1✔
NEW
UNCOV
30
            except KeyError:
×
NEW
UNCOV
31
                pass
×
32
        return confusion_matrix
1✔
33

34
    def tp(self):
1✔
35
        return self.confusion_matrix["true positive"]
1✔
36

37
    def tn(self):
1✔
38
        return self.confusion_matrix["true negative"]
1✔
39

40
    def fp(self):
1✔
41
        return self.confusion_matrix["false positive"]
1✔
42

43
    def fn(self):
1✔
44
        return self.confusion_matrix["false negative"]
1✔
45

46
    def model_guess(self, first_cluster_id, second_cluster_id):
1✔
47
        guess = None
1✔
48
        if first_cluster_id == second_cluster_id:
1✔
49
            guess = 1
1✔
50
        else:
51
            guess = 0
1✔
52
        return guess
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc