|
1 | 1 | .. -*- mode: rst -*- |
2 | 2 |
|
3 | | -|Python3|_ |PyPi|_ |Docs|_ |
| 3 | +|Python3|_ |PyPi|_ |Docs|_ |License| |
4 | 4 |
|
5 | 5 | .. |Python3| image:: https://img.shields.io/badge/python-3-blue.svg |
6 | 6 | .. _Python3: https://badge.fury.io/py/scikit-uplift |
|
11 | 11 | .. |Docs| image:: https://readthedocs.org/projects/scikit-uplift/badge/?version=latest |
12 | 12 | .. _Docs: https://scikit-uplift.readthedocs.io/en/latest/ |
13 | 13 |
|
| 14 | +.. |Docs| image:: https://img.shields.io/badge/license-MIT-green |
| 15 | +.. _Docs: https://github.com/maks-sh/scikit-uplift/blob/master/LICENSE |
| 16 | + |
14 | 17 | .. |Open In Colab1| image:: https://colab.research.google.com/assets/colab-badge.svg |
15 | 18 | .. _Open In Colab1: https://colab.research.google.com/github/maks-sh/scikit-uplift/blob/master/notebooks/RetailHero_EN.ipynb |
16 | 19 |
|
@@ -39,15 +42,15 @@ scikit-uplift |
39 | 42 |
|
40 | 43 | Uplift prediction aims to estimate the causal impact of a treatment at the individual level. |
41 | 44 |
|
42 | | -More about uplift modelling problem read in russian on habr.com: `Part 1`_ and `Part 2`_. |
| 45 | +More about uplift modelling problem read in `User guide <https://scikit-uplift.readthedocs.io/en/latest/user_guide/index.html>`__, and also in russian on habr.com: `Part 1`_ and `Part 2`_. |
43 | 46 |
|
44 | 47 | **Features**: |
45 | 48 |
|
46 | 49 | * Comfortable and intuitive style of modelling like scikit-learn; |
47 | 50 |
|
48 | 51 | * Applying any estimator adheres to scikit-learn conventions; |
49 | 52 |
|
50 | | -* All approaches can be used in sklearn.pipeline (see example (`EN <https://nbviewer.jupyter.org/github/maks-sh/scikit-uplift/blob/master/notebooks/pipeline_usage_EN.ipynb>`__ |Open In Colab3|_, `RU <https://nbviewer.jupyter.org/github/maks-sh/scikit-uplift/blob/master/notebooks/pipeline_usage_RU.ipynb>`__ |Open In Colab4|_)) |
| 53 | +* All approaches can be used in sklearn.pipeline (see example (`EN <https://nbviewer.jupyter.org/github/maks-sh/scikit-uplift/blob/master/notebooks/pipeline_usage_EN.ipynb>`__ |Open In Colab3|_, `RU <https://nbviewer.jupyter.org/github/maks-sh/scikit-uplift/blob/master/notebooks/pipeline_usage_RU.ipynb>`__ |Open In Colab4|_)); |
51 | 54 |
|
52 | 55 | * Almost all implemented approaches solve both the problem of classification and regression; |
53 | 56 |
|
@@ -101,57 +104,65 @@ See the **RetailHero tutorial notebook** (`EN <https://nbviewer.jupyter.org/gith |
101 | 104 | # import any estimator adheres to scikit-learn conventions. |
102 | 105 | from catboost import CatBoostClassifier |
103 | 106 |
|
| 107 | +
|
| 108 | + # define models |
| 109 | + treatment_model = CatBoostClassifier(iterations=50, thread_count=3, |
| 110 | + random_state=42, silent=True) |
| 111 | + control_model = CatBoostClassifier(iterations=50, thread_count=3, |
| 112 | + random_state=42, silent=True) |
| 113 | +
|
104 | 114 | # define approach |
105 | | - sm = SoloModel(CatBoostClassifier(verbose=100, random_state=777)) |
| 115 | + tm = TwoModels(treatment_model, control_model, method='vanilla') |
106 | 116 | # fit model |
107 | | - sm = sm.fit(X_train, y_train, treat_train, estimator_fit_params={'plot': True}) |
| 117 | + tm = tm.fit(X_train, y_train, treat_train) |
108 | 118 |
|
109 | 119 | # predict uplift |
110 | | - uplift_sm = sm.predict(X_val) |
| 120 | + uplift_preds = tm.predict(X_val) |
111 | 121 |
|
112 | 122 | **Evaluate your uplift model** |
113 | 123 |
|
114 | 124 | .. code-block:: python |
115 | 125 |
|
116 | 126 | # import metrics to evaluate your model |
117 | | - from sklift.metrics import qini_auc_score, uplift_auc_score, uplift_at_k |
| 127 | + from sklift.metrics import ( |
| 128 | + uplift_at_k, uplift_auc_score, qini_auc_score, weighted_average_uplift |
| 129 | + ) |
| 130 | +
|
118 | 131 |
|
119 | 132 | # Uplift@30% |
120 | | - sm_uplift_at_k = uplift_at_k(y_true=y_val, uplift=uplift_sm, treatment=treat_val, k=0.3) |
| 133 | + tm_uplift_at_k = uplift_at_k(y_true=y_val, uplift=uplift_preds, treatment=treat_val, |
| 134 | + strategy='overall', k=0.3) |
| 135 | +
|
121 | 136 | # Area Under Qini Curve |
122 | | - sm_qini_auc_score = qini_auc_score(y_true=y_val, uplift=uplift_sm, treatment=treat_val) |
| 137 | + tm_qini_auc = qini_auc_score(y_true=y_val, uplift=uplift_preds, treatment=treat_val) |
| 138 | +
|
123 | 139 | # Area Under Uplift Curve |
124 | | - sm_uplift_auc_score = uplift_auc_score(y_true=y_val, uplift=uplift_sm, treatment=treat_val) |
| 140 | + tm_uplift_auc = uplift_auc_score(y_true=y_val, uplift=uplift_preds, treatment=treat_val) |
| 141 | +
|
| 142 | + # Weighted average uplift |
| 143 | + tm_wau = weighted_average_uplift(y_true=y_val, uplift=uplift_preds, treatment=treat_val) |
125 | 144 |
|
126 | 145 | **Vizualize the results** |
127 | 146 |
|
128 | 147 | .. code-block:: python |
129 | 148 |
|
130 | 149 | # import vizualisation tools |
131 | | - from sklift.viz import plot_uplift_preds, plot_uplift_qini_curves |
132 | | -
|
133 | | - # get conditional predictions (probabilities) of performing a target action |
134 | | - # with interaction for each object |
135 | | - sm_trmnt_preds = sm.trmnt_preds_ |
136 | | - # get conditional predictions (probabilities) of performing a target action |
137 | | - # without interaction for each object |
138 | | - sm_ctrl_preds = sm.ctrl_preds_ |
139 | | -
|
140 | | - # draw probability distributions and their difference (uplift) |
141 | | - plot_uplift_preds(trmnt_preds=sm_trmnt_preds, ctrl_preds=sm_ctrl_preds); |
142 | | - # draw Uplift and Qini curves |
143 | | - plot_uplift_qini_curves(y_true=y_val, uplift=uplift_sm, treatment=treat_val); |
144 | | -
|
145 | | -.. image:: https://raw.githubusercontent.com/maks-sh/scikit-uplift/master/docs/_static/images/readme_img1.png |
146 | | - :align: center |
147 | | - :alt: Probabilities Histogram, Uplift anf Qini curves |
| 150 | + from sklift.viz import plot_qini_curve |
148 | 151 |
|
| 152 | + plot_qini_curve(y_true=y_val, uplift=uplift_preds, treatment=treat_val) |
149 | 153 |
|
| 154 | +.. image:: _static/images/quick_start_qini.png |
| 155 | + :width: 514px |
| 156 | + :height: 400px |
| 157 | + :alt: Example of model's qini curve, perfect qini curve and random qini curve |
150 | 158 |
|
151 | 159 | Development |
152 | 160 | ----------- |
153 | 161 |
|
154 | | -We welcome new contributors of all experience levels. Please see our `Contributing Guide <https://scikit-uplift.readthedocs.io/en/latest/contributing.html>`_ for more details. |
| 162 | +We welcome new contributors of all experience levels. |
| 163 | + |
| 164 | +- Please see our `Contributing Guide <https://scikit-uplift.readthedocs.io/en/latest/contributing.html>`_ for more details. |
| 165 | +- By participating in this project, you agree to abide by its `Code of Conduct <https://github.com/maks-sh/scikit-uplift/blob/master/.github/CODE_OF_CONDUCT.md>`__. |
155 | 166 |
|
156 | 167 | Contributing |
157 | 168 | ~~~~~~~~~~~~~~~ |
@@ -195,6 +206,7 @@ Important links |
195 | 206 | - Official source code repo: https://github.com/maks-sh/scikit-uplift/ |
196 | 207 | - Issue tracker: https://github.com/maks-sh/scikit-uplift/issues |
197 | 208 | - Documentation: https://scikit-uplift.readthedocs.io/en/latest/ |
| 209 | +- User guide: https://scikit-uplift.readthedocs.io/en/latest/user_guide/index.html |
198 | 210 | - Contributing guide: https://scikit-uplift.readthedocs.io/en/latest/contributing.html |
199 | 211 | - Release History: https://scikit-uplift.readthedocs.io/en/latest/changelog.html |
200 | 212 |
|
@@ -239,10 +251,10 @@ Papers and materials |
239 | 251 | Uplift Modeling with Multiple Treatments and General Response Types. 10.1137/1.9781611974973.66. |
240 | 252 |
|
241 | 253 | 10. Nicholas J Radcliffe. 2007. |
242 | | - Using control groups to target on predicted lift: Building and assessing uplift model. Direct Marketing Analytics Journal, (3):14–21, 2007. |
| 254 | + Using control groups to target on predicted lift: Building and assessing uplift model. Direct Marketing Analytics Journal, (3):14–21, 2007. |
243 | 255 |
|
244 | 256 | 11. Devriendt, F., Guns, T., & Verbeke, W. 2020. |
245 | | - Learning to rank for uplift modeling. ArXiv, abs/2002.05897. |
| 257 | + Learning to rank for uplift modeling. ArXiv, abs/2002.05897. |
246 | 258 |
|
247 | 259 | =============== |
248 | 260 |
|
|
0 commit comments