Spaces:
Sleeping
Sleeping
HardWorkingStation commited on
Commit ·
f496f49
1
Parent(s): 4a94de3
Initial commit
Browse files- src/web_app.py +17 -3
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, 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
|
|
@@ -220,6 +220,7 @@ with st.expander('Результаты ручной фильтрации', expan
|
|
| 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}')
|
|
@@ -242,6 +243,7 @@ if show_ml_reasons:
|
|
| 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}')
|
|
@@ -252,12 +254,24 @@ if show_ml_reasons:
|
|
| 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', markersize=3)
|
|
|
|
|
|
|
| 261 |
st.pyplot(fig.figure_)
|
| 262 |
prefect_uplift = st.checkbox('Отрисовать идеальную метрику uplift')
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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, uplift_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
|
|
|
|
| 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 |
+
uplift_curve_user_score = uplift_curve(target_filtered, uplift, treatment_filtered)
|
| 224 |
# отображаем метрики
|
| 225 |
col1, col2, col3 = st.columns(3)
|
| 226 |
col1.metric(label=f'Uplift для {k}% пользователей', value=f'{user_metric_uplift_at_k:.4f}')
|
|
|
|
| 243 |
catboost_qini_auc_score = qini_auc_score(target_filtered, final_uplift, treatment_filtered)
|
| 244 |
catboost_weighted_average_uplift = tools.get_weighted_average_uplift(target_filtered, final_uplift, treatment_filtered)
|
| 245 |
qini_curve_score = qini_curve(target_filtered, final_uplift, treatment_filtered)
|
| 246 |
+
|
| 247 |
# отображаем метрики
|
| 248 |
col1, col2, col3 = st.columns(3)
|
| 249 |
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}')
|
|
|
|
| 254 |
st.write(catboost_uplift_by_percentile)
|
| 255 |
st.form_submit_button('Обновить графики', help='При изменении флагов')
|
| 256 |
perfect_qini = st.checkbox('Отрисовать идеальную метрику qini')
|
| 257 |
+
|
| 258 |
# получаем координаты пользовательской метрики для точки на графике
|
| 259 |
x, y = qini_curve_user_score[0][1], qini_curve_user_score[1][1]
|
| 260 |
# получаем объект UpliftCurveDisplay с осями и графиком matplotlib
|
| 261 |
fig = plot_qini_curve(target_test, sm_cbc['0'], treatment_test, perfect=perfect_qini)
|
| 262 |
# добавляем пользовательскую метрику на оси графика
|
| 263 |
+
fig.ax_.plot(x, y, 'ro', markersize=3, label='Analitic qini')
|
| 264 |
+
# добавляем обозначение метрики пользователя в легенду
|
| 265 |
+
fig.ax_.legend(loc=u'upper left', bbox_to_anchor=(1, 1))
|
| 266 |
st.pyplot(fig.figure_)
|
| 267 |
prefect_uplift = st.checkbox('Отрисовать идеальную метрику uplift')
|
| 268 |
+
|
| 269 |
+
# получаем координаты пользовательской метрики для точки на графике
|
| 270 |
+
x, y = uplift_curve_user_score[0][1], uplift_curve_user_score[1][1]
|
| 271 |
+
# получаем объект UpliftCurveDisplay с осями и графиком matplotlib
|
| 272 |
+
fig = plot_uplift_curve(target_test, sm_cbc['0'], treatment_test, perfect=perfect_qini)
|
| 273 |
+
# добавляем пользовательскую метрику на оси графика
|
| 274 |
+
fig.ax_.plot(x, y, 'ro', markersize=3, label='Analitic qini')
|
| 275 |
+
# добавляем обозначение метрики пользователя в легенду
|
| 276 |
+
fig.ax_.legend(loc=u'upper left', bbox_to_anchor=(1, 1))
|
| 277 |
+
st.pyplot(fig.figure_)
|