Calibration
CalibratedClassifier
- class DLL.MachineLearning.SupervisedLearning.Calibration.CalibratedClassifier(estimator, method='logistic', learning_rate=0.01)[source]
Bases:
object
The CalibratedClassifier for probability calibration.
- Parameters:
estimator (DLL.Machinelearning classifier) – An estimator to calibrate. The estimator must have the predict_proba method defined.
method (str, optional) – The method used for the calibration. Must be one of “logistic” or “isotonic”. Defaults to “logistic”.
learning_rate (float, optional) – The learning rate for fitting the logistic regression. Must be a positive real number. If method == “isotonic”, this parameter is ignored. Defaults to 0.01.
- fit(X, y, calibration_size=0.2, **kwargs)[source]
Fits chosen classifier to the input data and the output labels trying to be as accurate as possible about the probabilities of each class. Uses part of the data for the calibration and not for the fitting.
- Parameters:
X (torch.Tensor of shape (n_samples, n_features)) – The input data, where each row is a sample and each column is a feature.
y (torch.Tensor of shape (n_samples,)) – The labels corresponding to each sample. Every element must be in [0, …, n_classes - 1].
calibration_size (float, optional) – The amount of data used for the model calibration. Defaults to 0.2.
**kwargs – Key word arguments, which are passed to the fit method of the chosen estimator.
- predict(X)[source]
Predicts the classes of each data point using the calibrated probabilities.
- Parameters:
X (torch.Tensor of shape (n_samples, n_features)) – The input data, where each row is a sample and each column is a feature.
- Returns:
The predicted probabilities.
- Return type:
torch.Tensor of shape (n_samples, n_classes) or (n_samples,)
- predict_proba(X)[source]
Predicts the calibrated probabilities of the data points.
- Parameters:
X (torch.Tensor of shape (n_samples, n_features)) – The input data, where each row is a sample and each column is a feature.
- Returns:
The predicted probabilities.
- Return type:
torch.Tensor of shape (n_samples, n_classes) or (n_samples,)
IsotonicRegression
- class DLL.MachineLearning.SupervisedLearning.Calibration.IsotonicRegression[source]
Bases:
object
Isotonic regression model.
- fit(X, y, weight=None, increasing=True)[source]
Fits a monotonic function to the trainin data using the Pool-Adjacent-Violators (PAV) algorithm.
- Parameters:
X (torch.Tensor of shape (n_samples,)) – Independent variable (not necessarily sorted).
y (torch.Tensor of shape (n_samples,)) – Dependent variable.
weight (torch.Tensor of shape (n_samples,) | None, optional) – Sample weights. Must be a non-negative torch tensor. Defaults to None, which corresponds to uniform weights.
increasing (bool, optional) – Deterimines if the final predictions should be increasing or decreasing. Must be a boolean. Defaults to True.