Spaces:
Runtime error
Runtime error
HardWorkingStation
commited on
Commit
·
b61f7d0
1
Parent(s):
5624d07
Initial commit
Browse files- src/test.ipynb +0 -0
- src/web_app.py +13 -6
src/test.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
src/web_app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import catboost
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
-
from sklift.metrics import uplift_at_k, uplift_by_percentile, qini_auc_score
|
5 |
from sklift.viz import plot_qini_curve, plot_uplift_curve
|
6 |
from sklift.models import SoloModel, TwoModels, ClassTransformation
|
7 |
import streamlit as st
|
@@ -210,6 +210,7 @@ with st.expander(label='Посмотреть пример пользовател
|
|
210 |
sample_size = 7 if filtered_dataset.shape[0] >= 7 else filtered_dataset.shape[0]
|
211 |
example = filtered_dataset.sample(sample_size)
|
212 |
st.dataframe(example)
|
|
|
213 |
res = st.button('Обновить')
|
214 |
|
215 |
with st.expander('Результаты ручной фильтрации', expanded=True):
|
@@ -218,11 +219,13 @@ with st.expander('Результаты ручной фильтрации', expan
|
|
218 |
user_metric_uplift_by_percentile = uplift_by_percentile(target_filtered, uplift, treatment_filtered)
|
219 |
user_metric_qini_auc_score = qini_auc_score(target_filtered, uplift, treatment_filtered)
|
220 |
user_metric_weighted_average_uplift = tools.get_weighted_average_uplift(target_filtered, uplift, treatment_filtered)
|
|
|
221 |
# отображаем метрики
|
222 |
col1, col2, col3 = st.columns(3)
|
223 |
col1.metric(label=f'Uplift для {k}% пользователей', value=f'{user_metric_uplift_at_k:.4f}')
|
224 |
col2.metric(label=f'Qini AUC score', value=f'{user_metric_qini_auc_score:.4f}', help='Всегда будет 0 для пользователя')
|
225 |
col3.metric(label=f'Weighted average uplift', value=f'{user_metric_weighted_average_uplift:.4f}')
|
|
|
226 |
st.write('Uplift по процентилям')
|
227 |
st.write(user_metric_uplift_by_percentile)
|
228 |
|
@@ -238,19 +241,23 @@ if show_ml_reasons:
|
|
238 |
catboost_uplift_by_percentile = uplift_by_percentile(target_filtered, final_uplift, treatment_filtered)
|
239 |
catboost_qini_auc_score = qini_auc_score(target_filtered, final_uplift, treatment_filtered)
|
240 |
catboost_weighted_average_uplift = tools.get_weighted_average_uplift(target_filtered, final_uplift, treatment_filtered)
|
|
|
241 |
# отображаем метрики
|
242 |
col1, col2, col3 = st.columns(3)
|
243 |
col1.metric(label=f'Uplift для {k}% пользователей', value=f'{catboost_uplift_at_k:.4f}', delta=f'{catboost_uplift_at_k - user_metric_uplift_at_k:.4f}')
|
244 |
col2.metric(label=f'Qini AUC score', value=f'{catboost_qini_auc_score:.4f}', help='Всегда будет 0 для пользователя', delta=f'{catboost_qini_auc_score - user_metric_qini_auc_score:.4f}')
|
245 |
col3.metric(label=f'Weighted average uplift', value=f'{catboost_weighted_average_uplift:.4f}', delta=f'{catboost_weighted_average_uplift - user_metric_weighted_average_uplift:.4f}')
|
246 |
|
247 |
-
st.write()
|
248 |
-
|
249 |
st.write('Uplift по процентилям')
|
250 |
st.write(catboost_uplift_by_percentile)
|
251 |
-
|
252 |
st.form_submit_button('Обновить графики', help='При изменении флагов')
|
253 |
perfect_qini = st.checkbox('Отрисовать идеальную метрику qini')
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
prefect_uplift = st.checkbox('Отрисовать идеальную метрику uplift')
|
256 |
-
st.pyplot(plot_uplift_curve(
|
|
|
1 |
import catboost
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
+
from sklift.metrics import uplift_at_k, uplift_by_percentile, qini_auc_score, qini_curve
|
5 |
from sklift.viz import plot_qini_curve, plot_uplift_curve
|
6 |
from sklift.models import SoloModel, TwoModels, ClassTransformation
|
7 |
import streamlit as st
|
|
|
210 |
sample_size = 7 if filtered_dataset.shape[0] >= 7 else filtered_dataset.shape[0]
|
211 |
example = filtered_dataset.sample(sample_size)
|
212 |
st.dataframe(example)
|
213 |
+
st.info(f'Количество пользователей, попавших в выборку: {filtered_dataset.shape[0]} ({filtered_dataset.shape[0] / data_test.shape[0] * 100 :.2f}%)')
|
214 |
res = st.button('Обновить')
|
215 |
|
216 |
with st.expander('Результаты ручной фильтрации', expanded=True):
|
|
|
219 |
user_metric_uplift_by_percentile = uplift_by_percentile(target_filtered, uplift, treatment_filtered)
|
220 |
user_metric_qini_auc_score = qini_auc_score(target_filtered, uplift, treatment_filtered)
|
221 |
user_metric_weighted_average_uplift = tools.get_weighted_average_uplift(target_filtered, uplift, treatment_filtered)
|
222 |
+
qini_curve_user_score = qini_curve(target_filtered, uplift, treatment_filtered)
|
223 |
# отображаем метрики
|
224 |
col1, col2, col3 = st.columns(3)
|
225 |
col1.metric(label=f'Uplift для {k}% пользователей', value=f'{user_metric_uplift_at_k:.4f}')
|
226 |
col2.metric(label=f'Qini AUC score', value=f'{user_metric_qini_auc_score:.4f}', help='Всегда будет 0 для пользователя')
|
227 |
col3.metric(label=f'Weighted average uplift', value=f'{user_metric_weighted_average_uplift:.4f}')
|
228 |
+
|
229 |
st.write('Uplift по процентилям')
|
230 |
st.write(user_metric_uplift_by_percentile)
|
231 |
|
|
|
241 |
catboost_uplift_by_percentile = uplift_by_percentile(target_filtered, final_uplift, treatment_filtered)
|
242 |
catboost_qini_auc_score = qini_auc_score(target_filtered, final_uplift, treatment_filtered)
|
243 |
catboost_weighted_average_uplift = tools.get_weighted_average_uplift(target_filtered, final_uplift, treatment_filtered)
|
244 |
+
qini_curve_score = qini_curve(target_filtered, final_uplift, treatment_filtered)
|
245 |
# отображаем метрики
|
246 |
col1, col2, col3 = st.columns(3)
|
247 |
col1.metric(label=f'Uplift для {k}% пользователей', value=f'{catboost_uplift_at_k:.4f}', delta=f'{catboost_uplift_at_k - user_metric_uplift_at_k:.4f}')
|
248 |
col2.metric(label=f'Qini AUC score', value=f'{catboost_qini_auc_score:.4f}', help='Всегда будет 0 для пользователя', delta=f'{catboost_qini_auc_score - user_metric_qini_auc_score:.4f}')
|
249 |
col3.metric(label=f'Weighted average uplift', value=f'{catboost_weighted_average_uplift:.4f}', delta=f'{catboost_weighted_average_uplift - user_metric_weighted_average_uplift:.4f}')
|
250 |
|
|
|
|
|
251 |
st.write('Uplift по процентилям')
|
252 |
st.write(catboost_uplift_by_percentile)
|
|
|
253 |
st.form_submit_button('Обновить графики', help='При изменении флагов')
|
254 |
perfect_qini = st.checkbox('Отрисовать идеальную метрику qini')
|
255 |
+
# получаем координаты пользовательской метрики для точки на графике
|
256 |
+
x, y = qini_curve_user_score[0][1], qini_curve_user_score[1][1]
|
257 |
+
# получаем объект UpliftCurveDisplay с осями и графиком matplotlib
|
258 |
+
fig = plot_qini_curve(target_test, sm_cbc['0'], treatment_test, perfect=perfect_qini)
|
259 |
+
# добавляем пользовательскую метрику на оси графика
|
260 |
+
fig.ax_.plot(x, y, 'ro--', linewidth=2, markersize=3)
|
261 |
+
st.pyplot(fig.figure_)
|
262 |
prefect_uplift = st.checkbox('Отрисовать идеальную метрику uplift')
|
263 |
+
st.pyplot(plot_uplift_curve(target_test, sm_cbc['0'], treatment_test, perfect=prefect_uplift).figure_)
|