-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
92 lines (84 loc) · 2.93 KB
/
util.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
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"
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='.0%', range=[0, 1]),
height=400,
margin=dict(l=20, r=20, t=40, b=20))
return fig