IsotonicRegressionScaler#
- class torch_uncertainty.post_processing.IsotonicRegressionScaler(model=None, eps=1e-06, device=None)[source]#
Isotonic Regression post-processing for calibrated probabilities.
Isotonic regression is a non-parametric calibration method that fits a piecewise-constant, non-decreasing function to map uncalibrated probabilities to calibrated ones. It minimizes the mean squared error. Multi-class calibration is handled using a one-vs-rest approach per class.
- Parameters:
model (nn.Module) – Model to calibrate. Defaults to
None.eps (float) – Small value for stability when converting probs back to logits. Defaults to
1e-6.device (Optional[Literal["cpu", "cuda"]], optional) – Device to use for tensor operations. Defaults to
None.
References
[1] Transforming Classifier Scores into Accurate Multiclass Probability Estimates. In KDD 2002. <https://dl.acm.org/doi/10.1145/775047.775151>`_.
Note
This implementation uses Scikit-Learn’s
IsotonicRegressionas the underlying solver.- Remark:
Isotonic regression requires a sufficient amount of calibration data to avoid overfitting the step function, especially in multiclass scenarios.
- fit(dataloader, progress=True)[source]#
Fit the isotonic regression models to the calibration data.
For binary classification, a single isotonic regressor is fit. For multiclass classification, a One-vs-Rest (OvR) approach is used: one regressor is trained per class to predict the probability of that class versus all others.
- Parameters:
dataloader (DataLoader) – Dataloader providing the calibration data (logits and targets).
progress (bool, optional) – Whether to show a progress bar during data extraction. Defaults to
True.
- forward(inputs)[source]#
Apply the fitted Isotonic Regression and return calibrated logits.
The forward pass transforms the input logits into probabilities, applies the isotonic mapping, and then converts the resulting probabilities back into the logit space for compatibility with downstream loss functions or metrics.
- Parameters:
inputs (Tensor) – Input logits to be calibrated.
- Returns:
Calibrated logits.
- Return type:
Tensor