to_binary_class#
- sdm.evaluation.to_binary_class(pred: TableTensor, target: TableTensor | CategoricalTensor, positive_class: bool | int | float | str) tuple[Tensor, Tensor]#
Convert binary predictions and targets to positive-class form.
- Parameters:
pred (TableTensor) – Prediction table whose numerical columns contain class scores. Column names define the class order.
target (TableTensor | CategoricalTensor) – Single-column categorical target.
positive_class (bool | int | float | str) – Class value treated as the positive class.
- Return type:
>>> import torch >>> import sdm >>> from sdm.evaluation import to_binary_class >>> pred = sdm.TableTensor.from_tensor( ... torch.tensor([[0.8, 0.2], [0.1, 0.9], [0.4, 0.6]]), ... columns=["false", "true"], ... ) >>> target = sdm.CategoricalTensor( ... code=torch.tensor([[0], [1], [1]]), ... categories=(sdm.StringTensor.from_list(["false", "true"]),), ... ) >>> positive_scores, binary_target = to_binary_class( ... pred, ... target, ... positive_class="true", ... ) >>> positive_scores tensor([0.2000, 0.9000, 0.6000]) >>> binary_target tensor([False, True, True]) >>> pred = sdm.TableTensor.from_tensor( ... torch.tensor([[0.2, 0.8], [0.9, 0.1], [0.6, 0.4]]), ... columns=["true", "false"], ... ) >>> positive_scores, binary_target = to_binary_class( ... pred, ... target, ... positive_class="true", ... ) >>> positive_scores tensor([0.2000, 0.9000, 0.6000]) >>> binary_target tensor([False, True, True])