Skip to content

Commit fd0b633

Browse files
committed
make f1-weighting more gentle (multiply by 1 + f1 instead of only f1)
1 parent da4084e commit fd0b633

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

chebifier/ensemble/weighted_majority_ensemble.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def calculate_classwise_weights(self, predicted_classes):
3636
"""
3737
Given the positions of predicted classes in the predictions tensor, assign weights to each class. The
3838
result is two tensors of shape (num_predicted_classes, num_models). The weight for each class is the model_weight
39-
(default: 1) multiplied by the class-specific validation-f1 (default 1).
39+
(default: 1) multiplied by (1 + the class-specific validation-f1 (default 1)).
4040
"""
4141
weights_by_cls = torch.ones(len(predicted_classes), len(self.models))
4242
for j, model in enumerate(self.models):
@@ -46,7 +46,7 @@ def calculate_classwise_weights(self, predicted_classes):
4646
for cls, weights in model.classwise_weights.items():
4747
if (2 * weights["TP"] + weights["FP"] + weights["FN"]) > 0:
4848
f1 = 2 * weights["TP"] / (2 * weights["TP"] + weights["FP"] + weights["FN"])
49-
weights_by_cls[predicted_classes[cls], j] *= f1
49+
weights_by_cls[predicted_classes[cls], j] *= 1 + f1
5050

5151
print(f"Calculated model weightings. The average weights are:")
5252
for i, model in enumerate(self.models):

0 commit comments

Comments
 (0)