sklift.models.SoloModel

class sklift.models.models.SoloModel(estimator, method='dummy')[source]

aka Treatment Dummy approach, or Single model approach, or S-Learner.

Fit solo model on whole dataset with ‘treatment’ as an additional feature.

Each object from the test sample is scored twice: with the communication flag equal to 1 and equal to 0. Subtracting the probabilities for each observation, we get the uplift.

Return delta of predictions for each example.

Read more in the User Guide.

Parameters:
  • estimator (estimator object implementing 'fit') – The object to use to fit the data.

  • method (string, ’dummy’ or ’treatment_interaction’, default='dummy') –

    Specifies the approach:

    • 'dummy':

      Single model;

    • 'treatment_interaction':

      Single model including treatment interactions.

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 SoloModel
# import any estimator adheres to scikit-learn conventions
from catboost import CatBoostClassifier


sm = SoloModel(CatBoostClassifier(verbose=100, random_state=777))  # define approach
sm = sm.fit(X_train, y_train, treat_train, estimator_fit_params={{'plot': True})  # fit the model
uplift_sm = sm.predict(X_val)  # predict uplift

References

Lo, Victor. (2002). The True Lift Model - A Novel Data Mining Approach to Response Modeling in Database Marketing. SIGKDD Explorations. 4. 78-86.

See also

Other approaches:

Other:

  • plot_uplift_preds(): Plot histograms of treatment, control and uplift predictions.

fit(X, y, treatment, estimator_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,)) – Binary 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$') SoloModel

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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 in fit.

  • treatment (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for treatment parameter in fit.

Returns:

self – The updated object.

Return type:

object