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:

Other:

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,))