sklift.models.TwoModels
- class sklift.models.models.TwoModels(estimator_trmnt, estimator_ctrl, method='vanilla')[source]
aka naïve approach, or difference score method, or double classifier approach.
Fit two separate models: on the treatment data and on the control data.
Read more in the User Guide.
- Parameters:
estimator_trmnt (estimator object implementing 'fit') – The object to use to fit the treatment data.
estimator_ctrl (estimator object implementing 'fit') – The object to use to fit the control data.
method (string, 'vanilla', 'ddr_control' or 'ddr_treatment', default='vanilla') –
Specifies the approach:
'vanilla':Two independent models;
'ddr_control':Dependent data representation (First train control estimator).
'ddr_treatment':Dependent data representation (First train treatment estimator).
- trmnt_preds_
Estimator predictions on samples when treatment.
- Type:
array-like, shape (n_samples, )
- ctrl_preds_
Estimator predictions on samples when control.
- Type:
array-like, shape (n_samples, )
Example:
# import approach from sklift.models import TwoModels # import any estimator adheres to scikit-learn conventions from catboost import CatBoostClassifier estimator_trmnt = CatBoostClassifier(silent=True, thread_count=2, random_state=42) estimator_ctrl = CatBoostClassifier(silent=True, thread_count=2, random_state=42) # define approach tm_ctrl = TwoModels( estimator_trmnt=estimator_trmnt, estimator_ctrl=estimator_ctrl, method='ddr_control' ) # fit the models tm_ctrl = tm_ctrl.fit( X_train, y_train, treat_train, estimator_trmnt_fit_params={'cat_features': cat_features}, estimator_ctrl_fit_params={'cat_features': cat_features} ) uplift_tm_ctrl = tm_ctrl.predict(X_val) # predict uplift
- References
Betlei, Artem & Diemert, Eustache & Amini, Massih-Reza. (2018). Uplift Prediction with Dependent Feature Representation in Imbalanced Treatment and Control Conditions: 25th International Conference, ICONIP 2018, Siem Reap, Cambodia, December 13–16, 2018, Proceedings, Part V. 10.1007/978-3-030-04221-9_5.
Zhao, Yan & Fang, Xiao & Simchi-Levi, David. (2017). Uplift Modeling with Multiple Treatments and General Response Types. 10.1137/1.9781611974973.66.
See also
Other approaches:
SoloModel: Single model approach.ClassTransformation: Class Variable Transformation approach.ClassTransformationReg: Transformed Outcome approach.
Other:
plot_uplift_preds(): Plot histograms of treatment, control and uplift predictions.
- fit(X, y, treatment, estimator_trmnt_fit_params=None, estimator_ctrl_fit_params=None)[source]
Fit the model according to the given training data.
For each test example calculate predictions on new set twice: by the first and second models. After that calculate uplift as a delta between these predictions.
Return delta of predictions for each example.
- 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_trmnt_fit_params (dict, optional) – Parameters to pass to the fit method of the treatment estimator.
estimator_ctrl_fit_params (dict, optional) – Parameters to pass to the fit method of the control 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_ctrl_fit_params: bool | None | str = '$UNCHANGED$', estimator_trmnt_fit_params: bool | None | str = '$UNCHANGED$', treatment: bool | None | str = '$UNCHANGED$') TwoModels
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_ctrl_fit_params (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
estimator_ctrl_fit_paramsparameter infit.estimator_trmnt_fit_params (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
estimator_trmnt_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