sklift.models.ClassTransformationReg
- class sklift.models.models.ClassTransformationReg(estimator, propensity_val=None, propensity_estimator=None)[source]
aka CATE-generating (Conditional Average Treatment Effect) Transformation of the Outcome.
Redefine target variable, which indicates that treatment make some impact on target or did target is negative without treatment:
Z = Y * (W - p)/(p * (1 - p))
,where
Y
- target vector,W
- vector of binary communication flags, andp
is a propensity score (the probabilty that each y_i is assigned to the treatment group.).Then, train a regressor on
Z
to predict uplift.Returns uplift predictions and optionally propensity predictions.
The propensity score can be a scalar value (e.g. p = 0.5), which would mean that every subject has identical probability of being assigned to the treatment group.
Alternatively, the propensity can be learned using a Classifier model. In this case, the model predicts the probability that a given subject would be assigned to the treatment group.
Read more in the User Guide.
- Parameters:
estimator (estimator object implementing 'fit') – The object to use to fit the data.
propensity_val (float) – A constant propensity value, which assumes every subject has equal probability of assignment to the treatment group.
propensity_estimator (estimator object with predict_proba) – The object used to predict the propensity score if propensity_val is not given.
Example:
# import approach from sklift.models import ClassTransformationReg # import any estimator adheres to scikit-learn conventions from sklearn.linear_model import LinearRegression, LogisticRegression # define approach ct = ClassTransformationReg(estimator=LinearRegression(), propensity_estimator=LogisticRegression()) # fit the model ct = ct.fit(X_train, y_train, treat_train) # predict uplift uplift_ct = ct.predict(X_val)
References
Athey, Susan & Imbens, Guido & Ramachandra, Vikas. (2015). Machine Learning Methods for Estimating Heterogeneous Causal Effects.
See also
Other approaches:
SoloModel
: Single model approach.TwoModels
: Double classifier approach.ClassTransformation
: Binary classifier transformation approach.
- fit(X, y, treatment, estimator_fit_params=None)[source]
Fit the model according to the given training data.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.
y (array-like, shape (n_samples,)) – Target vector relative to X.
treatment (array-like, shape (n_samples,)) – Binary treatment vector relative to X.
estimator_fit_params (dict, optional) – Parameters to pass to the fit method of the estimator.
- Returns:
self
- Return type:
object
- predict(X)[source]
Perform uplift on samples in X.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.
- Returns:
uplift
- Return type:
array (shape (n_samples,))
- predict_propensity(X)[source]
Predict propensity values.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.
- Returns:
propensity
- Return type:
array (shape (n_samples,))
- set_fit_request(*, estimator_fit_params: bool | None | str = '$UNCHANGED$', treatment: bool | None | str = '$UNCHANGED$') ClassTransformationReg
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if 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.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.- Parameters:
estimator_fit_params (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
estimator_fit_params
parameter infit
.treatment (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
treatment
parameter infit
.
- Returns:
self – The updated object.
- Return type:
object