lm_polygraph.utils.cir_model module
This module contains the CenteredIsotonicRegression class. Copied with minor modifications from https://github.com/mathijs02/cir-model/blob/main/src/cir_model/cir_model.py
- class lm_polygraph.utils.cir_model.CenteredIsotonicRegression(non_centered_points: List[float | int] = [0, 1], **kwargs: Any)[source]
Bases:
IsotonicRegressionCentered Isotonic Regression (CIR) model. CIR is described in [1] and is similar to Isotonic Regression (IR). CIR takes as an additional constraint, compared to IR, that the resulting function needs to be strictly monotonic: ranges of constant function values are prevented as much as possible. The CenteredIsotonicRegression class inherits all methods and attributes from the scikit-learn implementation IsotonicRegression and it is therefore compatible with the other components of the scikit-learn library, like for example pipelines.
Parameters
This class takes the same parameters and has the same attributes as IsotonicRegression from scikit-learn.[2]_ For full documentation of IsotonicRegression, see: https://scikit-learn.org/stable/modules/generated/sklearn.isotonic.IsotonicRegression.html
CenteredIsotonicRegression takes one additional parameter:
- non_centered_pointslist, default: [0, 1]
A list of y values that should not be collapsed in the CIR algorithm. In the original CIR algorithm, y values of 0 and 1 are treated differently by not collapsing them. This is because CIR is typically used for a binary target variable. The default behaviour can be overruled by passing a list of values for non_centered_points. An empty list means that no points are treated differently.
References
Examples
>>> from cir_model import CenteredIsotonicRegression >>> x = [1, 2, 3, 4] >>> y = [1, 21, 41, 34] >>> model = CenteredIsotonicRegression().fit(x, y) >>> model.transform(x) array([ 1. , 21. , 32. , 37.5])
- fit(X: ndarray | List, y: ndarray | List, sample_weight: ndarray | List | None = None) CenteredIsotonicRegression[source]
Fit the model using X, y and optionally sample_weight as training data. This method takes the same parameters and returns the same objects as fit from IsotonicRegression. For full documentation of IsotonicRegression, see: https://scikit-learn.org/stable/modules/generated/sklearn.isotonic.IsotonicRegression.html#sklearn.isotonic.IsotonicRegression.fit
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') CenteredIsotonicRegression
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.New in version 1.3.
Parameters
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter infit.
Returns
- selfobject
The updated object.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') CenteredIsotonicRegression
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.New in version 1.3.
Parameters
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns
- selfobject
The updated object.