PlattScaling

class PlattScaling(num_iters=100)[source]

Platt scaling.

Fitting a logistic regression model to a classifier scores such that the model outputs are transformed into a probability distribution over classes.

Parameters

num_iters (int) – Number of iterations for training.

Examples

>>> import numpy as np
>>> logit = np.random.rand(10)
>>> # binary class
>>> label = np.random.randint(0, 2, 10)
>>> scaler = PlattScaling()
>>> probabilities = scaler.fit_transform(label, logit)

Methods

fit

Fit function like sklearn.

fit_transform

Fit and tranform input to probabilities.

transform

Tranform input to probabilities basing on trained parameters.

fit(logits, labels)[source]

Fit function like sklearn.

Fit the sigmoid to the classifier scores logits and labels using the Platt Method.

Parameters
  • logits (array-like) – Classifier output scores.

  • labels (array like) – Classifier labels, must be +1 vs -1 or 1 vs 0.

Returns

Model with fitted coefficients a and b for the sigmoid function.

fit_transform(logits, labels)[source]

Fit and tranform input to probabilities.

Parameters
  • logits (array-like) – Classifier output scores.

  • labels (array like) – Classifier labels, must be +1 vs -1 or 1 vs 0.

Returns

Array of probabilities.

transform(logits)[source]

Tranform input to probabilities basing on trained parameters.

Parameters

labels (array like) – Classifier labels, must be +1 vs -1 or 1 vs 0.

Returns

Array of probabilities.