sklift.models.ClassTransformation
- class sklift.models.models.ClassTransformation(estimator)[source]
aka Class Variable Transformation or Revert Label approach.
Redefine target variable, which indicates that treatment make some impact on target or did target is negative without treatment:
Z = Y * W + (1 - Y)(1 - W),where
Y- target vector,W- vector of binary communication flags.Then,
Uplift ~ 2 * (Z == 1) - 1Returns only uplift predictions.
Read more in the User Guide.
- Parameters:
estimator (estimator object implementing 'fit') – The object to use to fit the data.
Example:
# import approach from sklift.models import ClassTransformation # import any estimator adheres to scikit-learn conventions from catboost import CatBoostClassifier # define approach ct = ClassTransformation(CatBoostClassifier(verbose=100, random_state=777)) # fit the model ct = ct.fit(X_train, y_train, treat_train, estimator_fit_params={{'plot': True}) # predict uplift uplift_ct = ct.predict(X_val)
References
Maciej Jaskowski and Szymon Jaroszewicz. Uplift modeling for clinical trial data. ICML Workshop on Clinical Data Analysis, 2012.
See also
Other approaches:
ClassTransformationReg: Transformed Outcome approach.SoloModel: Single model approach.TwoModels: Double classifier 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,))
- set_fit_request(*, estimator_fit_params: bool | None | str = '$UNCHANGED$', treatment: bool | None | str = '$UNCHANGED$') ClassTransformation
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.
- Parameters:
estimator_fit_params (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
estimator_fit_paramsparameter infit.treatment (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
treatmentparameter infit.
- Returns:
self – The updated object.
- Return type:
object