Skip to content

Commit c9dd56a

Browse files
committed
Merge branch 'realese/v0.4.0'
2 parents e9de7ab + e93aeba commit c9dd56a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+21142
-481
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
omit = sklift/tests/*,*__init__.py*

.github/workflows/ci-test.yml

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,67 @@ name: Python package
33
on:
44
push:
55
branches: [ master ]
6-
pull_request:
7-
6+
pull_request_target:
87

98
jobs:
109
test:
1110
name: Check tests
12-
runs-on: ${{ matrix.operating-system }}
11+
runs-on: ${{ matrix.os }}
12+
env:
13+
# fix the python version and the operating system for codecoverage commentator
14+
USING_COVERAGE_PY: '3.8'
15+
USING_COVERAGE_OS: 'ubuntu-latest'
16+
outputs:
17+
# fix the results of pytest for unix
18+
output1: ${{ steps.pytest.outputs.exit_code }}
19+
1320
strategy:
1421
matrix:
15-
operating-system: [ubuntu-latest, windows-latest, macos-latest]
16-
python-version: [3.6, 3.7, 3.8, 3.9]
22+
os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
23+
python-version: ['3.6', '3.7', '3.8', '3.9']
24+
# GitHub does not cancel all in-progress jobs if any matrix job fails
1725
fail-fast: false
1826

1927
steps:
20-
- uses: actions/checkout@v2
21-
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v2
23-
with:
24-
python-version: ${{ matrix.python-version }}
25-
- name: Install dependencies and lints
26-
run: pip install pytest .[tests]
27-
- name: Run PyTest
28-
run: pytest
28+
- uses: actions/checkout@v2
29+
# Install python
30+
- name: Set up Python ${{ matrix.python-version }}
31+
uses: actions/setup-python@v2
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
# Update pip and install dependencies
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install . -r test_requirements.txt -r requirements.txt
39+
# Pytest in windows
40+
- name: Run PyTest windows
41+
if: ${{ matrix.os == 'windows-latest' }}
42+
run: |
43+
pytest | tee pytest-coverage.txt
44+
# Pytest in unix. Exit code of this run captures the exit status of tee and not of pytest
45+
# So, use $PIPESTATUS that holds the exit status of each command in pipeline
46+
- name: Run PyTest unix
47+
if: ${{ matrix.os != 'windows-latest' }}
48+
id: pytest
49+
run: |
50+
pytest | tee pytest-coverage.txt;
51+
exit_code=${PIPESTATUS[0]};
52+
echo "::set-output name=exit_code::$exit_code"
53+
# Сomment on the results of the test coverage
54+
- name: Comment coverage
55+
if: contains(env.USING_COVERAGE_PY, matrix.python-version) && contains(env.USING_COVERAGE_OS, matrix.os)
56+
uses: MishaKav/[email protected]
57+
with:
58+
pytest-coverage-path: ./pytest-coverage.txt
59+
junitxml-path: ./pytest.xml
60+
# For unix workflow should have failed if exit code of pytest were 1
61+
- name: Check fail of pytest unix
62+
if: ${{ matrix.os != 'windows-latest' && steps.pytest.outputs.exit_code == 1 }}
63+
uses: actions/github-script@v3
64+
with:
65+
script: |
66+
core.setFailed('Some tests failed!')
2967
3068
check_sphinx_build:
3169
name: Check Sphinx build for docs
@@ -34,15 +72,15 @@ jobs:
3472
matrix:
3573
python-version: [3.8]
3674
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v2
39-
- name: Set up Python
40-
uses: actions/setup-python@v2
41-
with:
42-
python-version: ${{ matrix.python-version }}
43-
- name: Update pip
44-
run: python -m pip install --upgrade pip
45-
- name: Install dependencies
46-
run: pip install -r docs/requirements.txt
47-
- name: Run Sphinx
48-
run: sphinx-build -b html docs /tmp/_docs_build
75+
- name: Checkout
76+
uses: actions/checkout@v2
77+
- name: Set up Python
78+
uses: actions/setup-python@v2
79+
with:
80+
python-version: ${{ matrix.python-version }}
81+
- name: Update pip and install dependencies
82+
run: |
83+
python -m pip install --upgrade pip
84+
pip install -r docs/requirements.txt -r requirements.txt
85+
- name: Run Sphinx
86+
run: sphinx-build -W -b html docs /tmp/_docs_build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ coverage.xml
6262
*.cover
6363
.hypothesis/
6464
.pytest_cache/
65+
pytest.xml
6566

6667
# Translations
6768
*.mo

.readthedocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ sphinx:
1313
# configuration: mkdocs.yml
1414

1515
# Optionally build your docs in additional formats such as PDF and ePub
16-
formats: all
16+
formats:
17+
- htmlzip
1718

1819
# Optionally set the version of Python and requirements required to build your docs
1920
python:

Readme.rst

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,22 @@ Articles in russian on habr.com: `Part 1 <https://habr.com/ru/company/ru_mts/blo
5454
`Part 2 <https://habr.com/ru/company/ru_mts/blog/485976/>`__
5555
and `Part 3 <https://habr.com/ru/company/ru_mts/blog/538934/>`__.
5656

57-
**Features**:
57+
Why sklift
58+
-------------
59+
60+
- Сomfortable and intuitive *scikit-learn*-like API;
5861

59-
* Сomfortable and intuitive scikit-learn-like API;
62+
- More uplift metrics than you have ever seen in one place! Include brilliants like *Area Under Uplift Curve* (AUUC) or *Area Under Qini Curve* (Qini coefficient) with ideal cases;
6063

61-
* Applying any estimator compatible with scikit-learn (e.g. Xgboost, LightGBM, Catboost, etc.);
64+
- Supporting any estimator compatible with scikit-learn (e.g. Xgboost, LightGBM, Catboost, etc.);
6265

63-
* 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|_));
66+
- All approaches can be used in the ``sklearn.pipeline``. See the example of usage on `the Tutorials page <https://www.uplift-modeling.com/en/latest/tutorials.html>`__;
6467

65-
* Almost all implemented approaches solve classification and regression problem;
68+
- Also metrics are compatible with the classes from ``sklearn.model_selection``. See the example of usage on `the Tutorials page <https://www.uplift-modeling.com/en/latest/tutorials.html>`__;
6669

67-
* More uplift metrics that you have ever seen in one place! Include brilliants like *Area Under Uplift Curve* (AUUC) or *Area Under Qini Curve* (Qini coefficient) with ideal cases;
70+
- Almost all implemented approaches solve classification and regression problems;
6871

69-
* Nice and useful viz for analyzing a performance model.
72+
- Nice and useful viz for analysing a performance model.
7073

7174
Installation
7275
-------------
@@ -112,24 +115,25 @@ Use the intuitive python API to train uplift models with `sklift.models <https:
112115
.. code-block:: python
113116
114117
# import approaches
115-
from sklift.models import SoloModel, ClassTransformation, TwoModels
118+
from sklift.models import SoloModel, ClassTransformation
116119
# import any estimator adheres to scikit-learn conventions.
117-
from catboost import CatBoostClassifier
118-
120+
from lightgbm import LGBMClassifier
119121
120122
# define models
121-
treatment_model = CatBoostClassifier(iterations=50, thread_count=3,
122-
random_state=42, silent=True)
123-
control_model = CatBoostClassifier(iterations=50, thread_count=3,
124-
random_state=42, silent=True)
123+
estimator = LGBMClassifier(n_estimators=10)
124+
125+
# define metamodel
126+
slearner = SoloModel(estimator=estimator)
125127
126-
# define approach
127-
tm = TwoModels(treatment_model, control_model, method='vanilla')
128128
# fit model
129-
tm = tm.fit(X_train, y_train, treat_train)
129+
slearner.fit(
130+
X=X_tr,
131+
y=y_tr,
132+
treatment=trmnt_tr,
133+
)
130134
131135
# predict uplift
132-
uplift_preds = tm.predict(X_val)
136+
uplift_slearner = slearner.predict(X_val)
133137
134138
**Evaluate your uplift model**
135139

@@ -144,33 +148,48 @@ Uplift model evaluation metrics are available in `sklift.metrics <https://www.u
144148
145149
146150
# Uplift@30%
147-
tm_uplift_at_k = uplift_at_k(y_true=y_val, uplift=uplift_preds, treatment=treat_val,
148-
strategy='overall', k=0.3)
151+
uplift_at_k = uplift_at_k(y_true=y_val, uplift=uplift_slearner,
152+
treatment=trmnt_val,
153+
strategy='overall', k=0.3)
149154
150155
# Area Under Qini Curve
151-
tm_qini_auc = qini_auc_score(y_true=y_val, uplift=uplift_preds, treatment=treat_val)
156+
qini_coef = qini_auc_score(y_true=y_val, uplift=uplift_slearner,
157+
treatment=trmnt_val)
152158
153159
# Area Under Uplift Curve
154-
tm_uplift_auc = uplift_auc_score(y_true=y_val, uplift=uplift_preds, treatment=treat_val)
160+
uplift_auc = uplift_auc_score(y_true=y_val, uplift=uplift_slearner,
161+
treatment=trmnt_val)
155162
156163
# Weighted average uplift
157-
tm_wau = weighted_average_uplift(y_true=y_val, uplift=uplift_preds, treatment=treat_val)
164+
wau = weighted_average_uplift(y_true=y_val, uplift=uplift_slearner,
165+
treatment=trmnt_val)
158166
159167
**Vizualize the results**
160168

161169
Visualize performance metrics with `sklift.viz <https://www.uplift-modeling.com/en/latest/api/viz/index.html>`__.
162170

163171
.. code-block:: python
164172
165-
# import vizualisation tools
166173
from sklift.viz import plot_qini_curve
174+
import matplotlib.pyplot as plt
175+
176+
fig, ax = plt.subplots(1, 1)
177+
ax.set_title('Qini curves')
178+
179+
plot_qini_curve(
180+
y_test, uplift_slearner, trmnt_test,
181+
perfect=True, name='Slearner', ax=ax
182+
);
167183
168-
plot_qini_curve(y_true=y_val, uplift=uplift_preds, treatment=treat_val, negative_effect=True)
184+
plot_qini_curve(
185+
y_test, uplift_revert, trmnt_test,
186+
perfect=False, name='Revert label', ax=ax
187+
);
169188
170-
.. image:: docs/_static/images/Readme_qini_curve.png
189+
.. image:: docs/_static/images/quick_start_qini.png
171190
:width: 514px
172191
:height: 400px
173-
:alt: Example of model's qini curve, perfect qini curve and random qini curve
192+
:alt: Example of some models qini curves, perfect qini curve and random qini curve
174193

175194
Development
176195
-----------

docs/404.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
:orphan:
2+
3+
*******************
4+
404 Page Not Found
5+
*******************
6+
7+
.. image:: _static/images/sklift_404.png
8+
:alt: 404 Page not found
9+
:align: center
10+
:width: 250 px
11+
:height: 250 px
12+
13+
Sorry, we couldn't find that page.
14+
15+
Try using the search box or go to the `homepage <https://www.uplift-modeling.com/en/latest/index.html>`__.
-52.6 KB
Binary file not shown.
-18.8 KB
Loading
-2.67 KB
Loading
2.88 KB
Loading

0 commit comments

Comments
 (0)