我有一个二元分类问题,我感兴趣的主要指标是 True Positive。 目前我正在使用 BCE 损失,但它并没有给我带来好的结果。
我的问题是,是否存在有助于这个方向的损失,我正在考虑使用调整后的权重来加权我的预测,例如:
class WeightedBCELoss(nn.Module):
def __init__(self):
super().__init__()
self.binary_loss = nn.BCELoss(reduction="none")
def forward(self, prediction, gt):
class_loss = self.binary_loss(prediction, gt)
weights = torch.ones_like(gt)
weights[gt >= 0.5] = w_positive
weights[gt < 0.5] = w_negative
return torch.mean(weights * class_loss)
但我不知道如何选择w_positive
和w_negative
。
有什么好的选择方法吗?还是有适合我情况的损失?
先谢谢你!