causallib.positivity.trimming.Trimming#

class Trimming(learner=LogisticRegression(), threshold='auto')[source]#
Parameters:
  • learner (sklearn object) – Initialized sklearn model

  • threshold (str | float) –

    The threshold method or value. - if auto: finding the optimized threshold in a principled way. - if float, hard-coded value between 0 to 0.5 is used

    in order to clip the propensity estimation.

__init__(learner=LogisticRegression(), threshold='auto')[source]#
Parameters:
  • learner (sklearn object) – Initialized sklearn model

  • threshold (str | float) –

    The threshold method or value. - if auto: finding the optimized threshold in a principled way. - if float, hard-coded value between 0 to 0.5 is used

    in order to clip the propensity estimation.

fit(X, a)[source]#

Fit propensity model for positivity.

Parameters:
  • X (pandas.DataFrame) – covariate matrix of size (num_subjects, num_features)

  • a (pandas.Series) – treatment assignment of size (num_subjects,)

predict(X, a, threshold=None)[source]#

Predict whether or not a sample is in the overlap region. Find samples that have probabilities to be assigned to one of the treatment groups, that is bigger than the cutoff threshold.

return a boolean indexer which is True if their probabilities are higher than the cutoff threshold and False otherwise. :param X: covariate matrix of size

(num_subjects, num_features)

Parameters:
  • a (pandas.Series) – treatment assignment of size (num_subjects,)

  • threshold (float|None) –

    The cutoff threshold. - if float, an optional value between 0 to 0.5 to clip the

    propensity estimation.

    • if None, use the optimized cutoff in a principled way.

Returns:

a Series of length X.shape[0] with the same index as

X and only boolean values

Return type:

pandas.Series

set_fit_request(*, a='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:

a (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for a parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, a='$UNCHANGED$', threshold='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the predict method.

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 (see sklearn.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 to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • 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:
  • a (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for a parameter in predict.

  • threshold (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for threshold parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, a='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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:

a (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for a parameter in score.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, a='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the transform method.

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 (see sklearn.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 to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • 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:

a (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for a parameter in transform.

Returns:

self – The updated object.

Return type:

object