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.
- 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:
- set_fit_request(*, a='$UNCHANGED$')#
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.
- set_transform_request(*, treatment_values='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
transformmethod.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 totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.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.