lir.algorithms.isotonic_regression module
- class lir.algorithms.isotonic_regression.IsotonicCalibrator(add_misleading: int = 0)[source]
Bases:
TransformerCalculate LR from a score belonging to one of two distributions using isotonic regression.
Calculates a likelihood ratio of a score value, provided it is from one of two distributions. Uses isotonic regression for interpolation.
In contrast to IsotonicRegression, this class:
has an initialization argument that provides the option of adding misleading data points
outputs logodds instead of probabilities
- Parameters:
add_misleading (int, optional) – Number of synthetic misleading points to add to reduce extreme LRs.
- apply(instances: InstanceData) LLRData[source]
Transform instances using the fitted isotonic regression model.
- Parameters:
instances (InstanceData) – Instances to transform.
- Returns:
Calibrated log-likelihood-ratio data.
- Return type:
- fit(instances: InstanceData) Self[source]
Fit the estimator on the given data.
- Parameters:
instances (InstanceData) – Training instances.
- Returns:
Fitted calibrator.
- Return type:
Self
- fit_apply(instances: InstanceData) LLRData[source]
Fit and apply the calibrator to the given data.
- Parameters:
instances (InstanceData) – Instances to fit and transform.
- Returns:
Calibrated log-likelihood-ratio data.
- Return type:
- class lir.algorithms.isotonic_regression.IsotonicRegression(*, y_min=None, y_max=None, increasing=True, out_of_bounds='nan')[source]
Bases:
IsotonicRegressionWrap SKlearn implementation to support infinite values.
Sklearn implementation IsotonicRegression throws an error when values are Inf or -Inf when in fact IsotonicRegression can handle infinite values. This wrapper around the sklearn implementation of IsotonicRegression prevents the error being thrown when Inf or -Inf values are provided.
- fit(X: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], y: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], sample_weight: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | tuple | None = None) IsotonicRegression[source]
Fit the model using X, y as training data.
X is stored for future use, as
transform()needs X to interpolate new input data.- Parameters:
X (ArrayLike) – Training data with shape
(n_samples,).y (ArrayLike) – Training target with shape
(n_samples,).sample_weight (ArrayLike | tuple | None, optional) – Sample weights. If None, equal weights are used.
- Returns:
Fitted estimator.
- Return type:
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') IsotonicRegression
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') IsotonicRegression
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.- Returns:
self – The updated object.
- Return type:
object
- transform(T: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray[source]
Transform new data by linear interpolation.
- Parameters:
T (ArrayLike) – Data to transform.
- Returns:
The transformed data.
- Return type:
np.ndarray