Install the package by the following command from PyPI:
pip install scikit-uplift
Or install from source:
git clone https://github.com/maks-sh/scikit-uplift.git
cd scikit-uplift
python setup.py install
Use the intuitive python API to train uplift models with sklift.models.
# import approaches
from sklift.models import SoloModel, ClassTransformation
# import any estimator adheres to scikit-learn conventions.
from lightgbm import LGBMClassifier
# define models
estimator = LGBMClassifier(n_estimators=10)
# define metamodel
slearner = SoloModel(estimator=estimator)
# fit model
slearner.fit(
X=X_tr,
y=y_tr,
treatment=trmnt_tr,
)
# predict uplift
uplift_slearner = slearner.predict(X_val)
Uplift model evaluation metrics are available in sklift.metrics.
# import metrics to evaluate your model
from sklift.metrics import (
uplift_at_k, uplift_auc_score, qini_auc_score, weighted_average_uplift
)
# Uplift@30%
uplift_at_k = uplift_at_k(y_true=y_val, uplift=uplift_slearner,
treatment=trmnt_val,
strategy='overall', k=0.3)
# Area Under Qini Curve
qini_coef = qini_auc_score(y_true=y_val, uplift=uplift_slearner,
treatment=trmnt_val)
# Area Under Uplift Curve
uplift_auc = uplift_auc_score(y_true=y_val, uplift=uplift_slearner,
treatment=trmnt_val)
# Weighted average uplift
wau = weighted_average_uplift(y_true=y_val, uplift=uplift_slearner,
treatment=trmnt_val)
Visualize performance metrics with sklift.viz.
from sklift.viz import plot_qini_curve
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax.set_title('Qini curves')
plot_qini_curve(
y_test, uplift_slearner, trmnt_test,
perfect=True, name='Slearner', ax=ax
);
plot_qini_curve(
y_test, uplift_revert, trmnt_test,
perfect=False, name='Revert label', ax=ax
);
from sklift.viz import plot_uplift_curve
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax.set_title('Uplift curves')
plot_uplift_curve(
y_test, uplift_slearner, trmnt_test,
perfect=True, name='Slearner', ax=ax
);
plot_uplift_curve(
y_test, uplift_revert, trmnt_test,
perfect=False, name='Revert label', ax=ax
);
from sklift.viz import plot_uplift_by_percentile
plot_uplift_by_percentile(y_true=y_val, uplift=uplift_preds,
treatment=treat_val, kind='bar')
- 👉Here👈
This is the modules reference of scikit-uplift.
- sklift.models
- sklift.metrics
- sklift.metrics.uplift_at_k
- sklift.metrics.uplift_curve
- sklift.metrics.perfect_uplift_curve
- sklift.metrics.uplift_auc_score
- sklift.metrics.qini_curve
- sklift.metrics.perfect_qini_curve
- sklift.metrics.qini_auc_score
- sklift.metrics.weighted_average_uplift
- sklift.metrics.uplift_by_percentile
- sklift.metrics.response_rate_by_percentile
- sklift.metrics.treatment_balance_curve
- sklift.metrics.average_squared_deviation
- sklift.metrics.max_prof_uplift
- sklift.metrics.make_uplift_scorer
- sklift.viz
- sklift.datasets
- sklift.datasets.clear_data_dir
- sklift.datasets.get_data_dir
- sklift.datasets.fetch_lenta
- sklift.datasets.fetch_x5
- sklift.datasets.fetch_criteo
- sklift.datasets.fetch_hillstrom
- sklift.datasets.fetch_megafon