Skip to content

Commit 9ddb954

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c5dd85b commit 9ddb954

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

machine_learning/confusion_matrix.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ def precision(actual: list, predicted: list, positive_label: int = 1) -> float:
6969
>>> precision(actual, predicted)
7070
0.6666666666666666
7171
"""
72-
tp = sum(1 for a, p in zip(actual, predicted) if a == positive_label and p == positive_label)
73-
fp = sum(1 for a, p in zip(actual, predicted) if a != positive_label and p == positive_label)
72+
tp = sum(
73+
1
74+
for a, p in zip(actual, predicted)
75+
if a == positive_label and p == positive_label
76+
)
77+
fp = sum(
78+
1
79+
for a, p in zip(actual, predicted)
80+
if a != positive_label and p == positive_label
81+
)
7482
return tp / (tp + fp) if (tp + fp) > 0 else 0.0
7583

7684

@@ -97,8 +105,16 @@ def recall(actual: list, predicted: list, positive_label: int = 1) -> float:
97105
>>> recall(actual, predicted)
98106
1.0
99107
"""
100-
tp = sum(1 for a, p in zip(actual, predicted) if a == positive_label and p == positive_label)
101-
fn = sum(1 for a, p in zip(actual, predicted) if a == positive_label and p != positive_label)
108+
tp = sum(
109+
1
110+
for a, p in zip(actual, predicted)
111+
if a == positive_label and p == positive_label
112+
)
113+
fn = sum(
114+
1
115+
for a, p in zip(actual, predicted)
116+
if a == positive_label and p != positive_label
117+
)
102118
return tp / (tp + fn) if (tp + fn) > 0 else 0.0
103119

104120

0 commit comments

Comments
 (0)