Skip to content

Commit f4894f0

Browse files
committed
calculate ppv / npv directly from confusion matrix
1 parent 540e908 commit f4894f0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

chebifier/ensemble/weighted_majority_ensemble.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ def calculate_classwise_weights(self, predicted_classes):
3333
if model.classwise_weights is None:
3434
continue
3535
for cls, weights in model.classwise_weights.items():
36+
if cls not in predicted_classes:
37+
continue
38+
ppv = (
39+
weights["TP"] / (weights["TP"] + weights["FP"])
40+
if (weights["TP"] + weights["FP"]) > 0
41+
else 1.0
42+
)
43+
npv = (
44+
weights["TN"] / (weights["TN"] + weights["FN"])
45+
if (weights["TN"] + weights["FN"]) > 0
46+
else 1.0
47+
)
3648
positive_weights[predicted_classes[cls], j] *= (
37-
weights["PPV"] * self.weighting_strength
38-
+ (1 - self.weighting_strength)
49+
ppv * self.weighting_strength + (1 - self.weighting_strength)
3950
) ** self.weighting_exponent
4051
negative_weights[predicted_classes[cls], j] *= (
41-
weights["NPV"] * self.weighting_strength
42-
+ (1 - self.weighting_strength)
52+
npv * self.weighting_strength + (1 - self.weighting_strength)
4353
) ** self.weighting_exponent
4454

4555
if self.verbose_output:

0 commit comments

Comments
 (0)