causallib.preprocessing.transformers.PropensityTransformer#

class PropensityTransformer(learner, include_covariates=False)[source]#

Transform covariates by adding/replacing with the propensity score.

Parameters:
  • learner (sklearn.estimator) – A learner implementing fit and predict_proba to use for predicting the propensity score.

  • include_covariates (bool) – Whether to return the original covariates alongside the “propensity” column.

__init__(learner, include_covariates=False)[source]#

Transform covariates by adding/replacing with the propensity score.

Parameters:
  • learner (sklearn.estimator) – A learner implementing fit and predict_proba to use for predicting the propensity score.

  • include_covariates (bool) – Whether to return the original covariates alongside the “propensity” column.

fit(X, a)[source]#
transform(X, treatment_values=None)[source]#

Append propensity or replace covariates with propensity.

Parameters:
  • X (pandas.DataFrame) – A DataFrame of samples to transform. This will be input to the learner trained by fit. If the columns are different, the results will not be valid.

  • treatment_values (Any | None) – A desired value/s to extract propensity to (i.e. probabilities to what treatment value should be calculated). If not specified, then the maximal treatment value is chosen. This is since the usual case is of treatment (A=1) control (A=0) setting.

Returns:

DataFrame with a “propensity” column. If “include_covariates” is True, it will include all of the original features plus “propensity”, else it will only have the “propensity” column.

Return type:

pandas.DataFrame

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_transform_request(*, treatment_values='$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:

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

Returns:

self – The updated object.

Return type:

object