-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
116 lines (109 loc) · 2.67 KB
/
utils.py
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
import plotly.graph_objects as go
def create_gauge_chart(probability):
if probability < 0.3:
color="green"
elif probability < 0.6:
color="yellow"
else:
color="red"
#create a gauge chart
fig = go.Figure(
go.Indicator(
mode="gauge+number",
value=probability*100,
domain={
'x': [0, 1],
'y': [0, 1]
},
title={
'text': "Churn probability",
'font': {
'size': 24,
'color': 'white'
}
},
number={
'font':{
'size': 40,
'color': 'white'
}
},
gauge={
'axis':{
'range': [0,100],
'tickwidth': 1,
'tickcolor': 'white'
},
'bar':{
'color': color
},
'bgcolor': 'rgba(0,0,0,0)',
'borderwidth':2,
'bordercolor': 'white',
'steps': [{
'range': [0,30],
'color': 'rgba(0,255,0,0.3)',
},
{
'range': [30,60],
'color': 'rgba(255,255,0,0.3)',
},
{
'range': [60,100],
'color': 'rgba(255,0,0,0.3)',
},
],
'threshold': {
'line': {
'color': "white",
'width': 4
},
'thickness': 0.75,
'value': 100
}
}
)
)
fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
font_color= 'white',
width=400,
height=300,
margin=dict(l=20, r=20, t=50, b=20)
)
return fig
def create_model_probability_chart(probabilities):
models = list(probabilities.keys())
probs = list(probabilities.values())
fig=go.Figure(data=[
go.Bar(y=models,
x=probs,
orientation='h',
text=[f'{p:.2%}' for p in probs],
textposition="auto"
)
])
fig.update_layout(
title="Churn Probability by Model",
yaxis_title="Models",
xaxis_title="Probability",
xaxis= dict(tickformat='.8%', range=[0,1]),
height=400,
margin=dict(l=20, r=20, t=40, b=20)
)
return fig
def create_percentiles_chart(percentiles, metrics):
fig = go.Figure(go.Bar(
x=list(percentiles.values()),
y=metrics,
orientation='h',
marker=dict(color='rgb(158,202,225)', line=dict(color='rgb(8,48,107)', width=1.5))
))
fig.update_layout(
title="Customer Percentiles",
xaxis_title="Percentil",
yaxis_title="Metric",
xaxis=dict(range=[0, 1], tickformat=".0%"),
yaxis=dict(showgrid=False),
)
return fig