-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
127 lines (109 loc) · 4 KB
/
app.py
File metadata and controls
127 lines (109 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
from sklearn.metrics import roc_auc_score
import plotly.figure_factory as ff
import plotly.express as px
from plotly_web_app.data import init_data, split_members_into_n_groups
from plotly_web_app.utils import avg_roc_auc_fed
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
fp_members, fm_members = init_data()
score = roc_auc_score(
y_true=np.concatenate((np.ones_like(fp_members), np.zeros_like(fm_members))),
y_score=np.concatenate((fp_members, fm_members))
)
ratios = [0.02, 0.2, 0.4, 0.6, 0.8, 1]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
server = app.server
app.layout = html.Div([
# divs levers
html.Div([
html.Div([
dcc.Slider(
id='fm-slider',
min=0,
max=1,
value=0.4,
marks={str(i): str(i) for i in ratios},
step=None
)], style={'width': '45%', 'display': 'inline-block'}
),
html.Div([
dcc.Slider(
id='fp-slider',
min=0,
max=1,
value=0.8,
marks={str(i): str(i) for i in ratios},
step=None
)], style={'width': '45%', 'display': 'inline-block',
'float': 'right'}
)
], style={
'borderBottom': 'thin lightgrey solid',
'backgroundColor': 'rgb(250, 250, 250)',
'padding': '10px 5px'
}),
# divs with graphs
html.Div([
dcc.Graph(
id='fm_dist'
)
], style={'width': '49%', 'display': 'inline-block', 'padding': '0 20'}),
html.Div([
dcc.Graph(
id='fp_dist'
)
], style={'width': '49%', 'display': 'inline-block', 'padding': '0 20',
'float': 'right'}),
html.Div(id='roc-auc-scores'),
html.Div(id='roc-auc-mean'),
html.Div(id='roc-auc', children=f'ROC-AUC {np.round(score, 3)}')
])
@app.callback(
[dash.dependencies.Output('fp_dist', 'figure'),
dash.dependencies.Output('fm_dist', 'figure'),
dash.dependencies.Output('roc-auc-scores', 'children'),
dash.dependencies.Output('roc-auc-mean', 'children')],
[dash.dependencies.Input('fp-slider', 'value'),
dash.dependencies.Input('fm-slider', 'value')])
def update_fp_fm_dist(ratio_p, ratio_m):
fp_members_fed = split_members_into_n_groups(fp_members, similarity_ratio=ratio_p)
fm_members_fed = split_members_into_n_groups(fm_members, similarity_ratio=ratio_m)
labels = [f'pod {i}' for i in range(len(fp_members_fed))]
fig_p = ff.create_distplot(fp_members_fed,
labels,
show_hist=False,
colors=px.colors.sequential.Sunsetdark[2:])
fig_m = ff.create_distplot(fm_members_fed,
labels,
show_hist=False,
colors=px.colors.sequential.Teal[2:])
fig_p.update_traces(opacity=0.8)
fig_p.update_layout(
title_text='Scores distribution (positive class)',
xaxis_title_text='Score',
bargap=0.85,
bargroupgap=0
)
fig_m.update_traces(opacity=0.8)
fig_m.update_layout(
title_text='Scores distribution (negative class)',
xaxis_title_text='Score',
bargap=0.85,
bargroupgap=0
)
roc_auc_fed, roc_auc_mean, _ = avg_roc_auc_fed(fm_members_fed, fp_members_fed)
roc_auc_fed = list(map(lambda x: str(np.round(x, 3)), roc_auc_fed))
scores = ', '.join(roc_auc_fed)
res1 = f"ROC-AUC scores = [{scores}]"
res2 = f"ROC-AUC mean = {np.round(roc_auc_mean, 3)}"
return fig_p, fig_m, res1, res2
if __name__ == '__main__':
server.run(host='0.0.0.0', port=80)
# app.run_server(port=80)
# app.run_server(debug=True)
# app.run(host='0.0.0.0')