Spaces:
Sleeping
Sleeping
Churn_Predictor.py
Browse files
app.py
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
def example1():
|
6 |
+
|
7 |
+
model=joblib.load("/Users/shvuuuu/Downloads/Creditfile.pkl")
|
8 |
+
input_model = [[45,1.3,2,0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,0, 0, 1]]
|
9 |
+
pred=model.predict(input_model)
|
10 |
+
churn = "False"
|
11 |
+
if pred[0] == 1:
|
12 |
+
churn = "He Will Churn"
|
13 |
+
elif pred[0] == 0:
|
14 |
+
churn = "He Will Not Churn"
|
15 |
+
return churn
|
16 |
+
|
17 |
+
def example2():
|
18 |
+
|
19 |
+
model=joblib.load("/Users/shvuuuu/Downloads/Creditfile.pkl")
|
20 |
+
input_model = [[7,0.8,5,0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,0, 0, 1]]
|
21 |
+
pred=model.predict(input_model)
|
22 |
+
churn = "False"
|
23 |
+
if pred[0] == 0:
|
24 |
+
churn = "She Will Churn"
|
25 |
+
elif pred[0] == 1:
|
26 |
+
churn = "She Will Not Churn"
|
27 |
+
return churn
|
28 |
+
|
29 |
+
def example3():
|
30 |
+
|
31 |
+
model=joblib.load("/Users/shvuuuu/Downloads/Creditfile.pkl")
|
32 |
+
input_model = [[41,2,2,0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0]]
|
33 |
+
pred=model.predict(input_model)
|
34 |
+
churn = "False"
|
35 |
+
if pred[0] == 1:
|
36 |
+
churn = "He Will Churn"
|
37 |
+
elif pred[0] == 0:
|
38 |
+
churn = "He Will Not Churn"
|
39 |
+
return churn
|
40 |
+
|
41 |
+
|
42 |
+
def example4():
|
43 |
+
|
44 |
+
model=joblib.load("/Users/shvuuuu/Downloads/Creditfile.pkl")
|
45 |
+
input_model = [[10,1.1,2,0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0]]
|
46 |
+
pred=model.predict(input_model)
|
47 |
+
churn = "False"
|
48 |
+
if pred[0] == 1:
|
49 |
+
churn = "He Will Churn"
|
50 |
+
elif pred[0] == 0:
|
51 |
+
churn = "He Will Not Churn"
|
52 |
+
return churn
|
53 |
+
|
54 |
+
|
55 |
+
def greet(Total_Transaction, Total_Ct_Chng_Q4_Q1, Total_Relationship_Count, Education=None, Annual_Income=None, Marital_Status=None, Card_Type=None):
|
56 |
+
educ, edud, edug, eduh, edup, eduu, ai0, ai40, ai60, ai80, ai120, msd, msm, mss, ctb, ctg, cts = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
57 |
+
|
58 |
+
if Annual_Income == "0k-40k":
|
59 |
+
ai0 = 1
|
60 |
+
elif Annual_Income == "40k-60k":
|
61 |
+
ai40 = 1
|
62 |
+
elif Annual_Income == "60k-80k":
|
63 |
+
ai60 = 1
|
64 |
+
elif Annual_Income == "80k-120k":
|
65 |
+
ai80 = 1
|
66 |
+
elif Annual_Income == "120k+":
|
67 |
+
ai120 = 1
|
68 |
+
|
69 |
+
if Marital_Status == "Single":
|
70 |
+
mss = 1
|
71 |
+
elif Marital_Status == "Married":
|
72 |
+
msm = 1
|
73 |
+
elif Marital_Status == "Divorced":
|
74 |
+
msd = 1
|
75 |
+
|
76 |
+
if Card_Type == "Blue":
|
77 |
+
ctb = 1
|
78 |
+
elif Card_Type == "Gold":
|
79 |
+
ctg = 1
|
80 |
+
elif Card_Type == "Silver":
|
81 |
+
cts = 1
|
82 |
+
|
83 |
+
if Education == "College":
|
84 |
+
educ = 1
|
85 |
+
elif Education == "Doctorate":
|
86 |
+
edud = 1
|
87 |
+
elif Education == "Graduate":
|
88 |
+
edug = 1
|
89 |
+
elif Education == "High-School":
|
90 |
+
eduh = 1
|
91 |
+
elif Education == "Post-Graduate":
|
92 |
+
edup = 1
|
93 |
+
elif Education == "Uneducated":
|
94 |
+
eduu = 1
|
95 |
+
|
96 |
+
|
97 |
+
input_model = [[Total_Transaction,Total_Ct_Chng_Q4_Q1,Total_Relationship_Count,educ, edud, edug, eduh, edup, eduu, ai120, ai40, ai60, ai80, ai0, msd, msm, mss,ctb, ctg, cts]]
|
98 |
+
model=joblib.load("/Users/shvuuuu/Downloads/Creditfile.pkl")
|
99 |
+
pred=model.predict(input_model)
|
100 |
+
churn = "False"
|
101 |
+
if pred[0] == 1:
|
102 |
+
churn = "True"
|
103 |
+
elif pred[0] == 0:
|
104 |
+
churn = "Flase"
|
105 |
+
return churn
|
106 |
+
|
107 |
+
with gr.Blocks() as demo:
|
108 |
+
with gr.Row():
|
109 |
+
with gr.Column(scale=1,min_width=600):
|
110 |
+
gr.Image("/Users/shvuuuu/Downloads/Untitled design copy.png").style(height='7')
|
111 |
+
Total_Transaction = gr.Slider(0, 200,label="Total Transaction Count")
|
112 |
+
Total_Ct_Chng_Q4_Q1 = gr.Slider(0, 30,label="Transaction Count Q4 vs Q1")
|
113 |
+
Total_Relationship_Count = gr.Slider(0, 20,label="Total Relationship Count")
|
114 |
+
|
115 |
+
with gr.Column(scale=2,min_width=600):
|
116 |
+
with gr.Row():
|
117 |
+
with gr.Column(scale=1,min_width=300):
|
118 |
+
Annual_Income = gr.Dropdown(["0k-40k","40k-60k","60k-80k","80k-120K","120k+"],label="Annual Income")
|
119 |
+
with gr.Column(scale=2,min_width=300):
|
120 |
+
Education = gr.Dropdown(["College","Doctorate","Graduate","High-School","Post-Graduate","Uneducated","Unknown"],label="Education")
|
121 |
+
|
122 |
+
with gr.Row():
|
123 |
+
with gr.Column(scale=3,min_width=300):
|
124 |
+
Marital_Status = gr.Dropdown(["Single","Married","Divorced","Unknown"],label="Marital Status")
|
125 |
+
with gr.Column(scale=4,min_width=300):
|
126 |
+
Card_Type = gr.Dropdown(["Blue","Silver","Gold"],label="Crad Type")
|
127 |
+
churn = gr.Textbox(value="", label="Churn")
|
128 |
+
btn = gr.Button("PREDICT").style(size = "lg")
|
129 |
+
btn.click(fn=greet, inputs=[Total_Transaction,Total_Ct_Chng_Q4_Q1,Total_Relationship_Count,Education,Annual_Income,Marital_Status,Card_Type], outputs=[churn])
|
130 |
+
gr.Markdown("""# Few Examples Based on Real-World Simulations""")
|
131 |
+
|
132 |
+
with gr.Row():
|
133 |
+
with gr.Column(scale=1,min_width=300):
|
134 |
+
gr.Image("/Users/shvuuuu/Downloads/Untitled design (1)/1.png")
|
135 |
+
churn1 = gr.Textbox(value="", label="Churn")
|
136 |
+
btn1 = gr.Button("PREDICT").style()
|
137 |
+
exp =1
|
138 |
+
btn1.click(fn=example1, inputs=[], outputs=[churn1])
|
139 |
+
gr.Markdown("""
|
140 |
+
# Corporate Professional!
|
141 |
+
Total Transaction Count - 45\n
|
142 |
+
Transaction Count Q4 vs Q1 - 1.3\n
|
143 |
+
Total Relationship Count - 2\n
|
144 |
+
Annual Income - 40k-60k\n
|
145 |
+
Education - Graduate\n
|
146 |
+
Marital Status - Married\n
|
147 |
+
Card Type - Silver\n
|
148 |
+
""")
|
149 |
+
with gr.Column(scale=2,min_width=300):
|
150 |
+
gr.Image("/Users/shvuuuu/Downloads/Untitled design (1)/4.png")
|
151 |
+
churn2 = gr.Textbox(value="", label="Churn")
|
152 |
+
bt2 = gr.Button("PREDICT").style()
|
153 |
+
bt2.click(fn=example2, inputs=[], outputs=[churn2])
|
154 |
+
gr.Markdown("""
|
155 |
+
# Medical Professional!
|
156 |
+
Total Transaction Count - 7\n
|
157 |
+
Transaction Count Q4 vs Q1 - 0.8\n
|
158 |
+
Total Relationship Count - 5\n
|
159 |
+
Annual Income - 80k-120k\n
|
160 |
+
Education - Doctorate\n
|
161 |
+
Marital Status - Married\n
|
162 |
+
Card Type - Gold\n
|
163 |
+
""")
|
164 |
+
with gr.Column(scale=3,min_width=300):
|
165 |
+
gr.Image("/Users/shvuuuu/Downloads/Untitled design (1)/2.png")
|
166 |
+
churn3 = gr.Textbox(value="", label="Churn")
|
167 |
+
btn3 = gr.Button("PREDICT").style()
|
168 |
+
btn3.click(fn=example3, inputs=[], outputs=[churn3])
|
169 |
+
gr.Markdown("""
|
170 |
+
# Freelance Photographer!
|
171 |
+
Total Transaction Count - 41\n
|
172 |
+
Transaction Count Q4 vs Q1 - 2\n
|
173 |
+
Total Relationship Count - 2\n
|
174 |
+
Annual Income - 0k-40k\n
|
175 |
+
Education - High-School\n
|
176 |
+
Marital Status - Single\n
|
177 |
+
Card Type - Blue\n
|
178 |
+
""")
|
179 |
+
with gr.Column(scale=4,min_width=300):
|
180 |
+
gr.Image("/Users/shvuuuu/Downloads/Untitled design (1)/3.png")
|
181 |
+
churn4 = gr.Textbox(value="", label="Churn")
|
182 |
+
btn4 = gr.Button("PREDICT").style()
|
183 |
+
btn4.click(fn=example4, inputs=[], outputs=[churn4])
|
184 |
+
gr.Markdown("""
|
185 |
+
# Retired Veteran Pensioner!
|
186 |
+
Total Transaction Count - 10\n
|
187 |
+
Transaction Count Q4 vs Q1 - 1.1\n
|
188 |
+
Total Relationship Count - 2\n
|
189 |
+
Annual Income - 80k-120k\n
|
190 |
+
Education - Post-Graduate\n
|
191 |
+
Marital Status - Divorced\n
|
192 |
+
Card Type - GOld\n
|
193 |
+
""")
|
194 |
+
|
195 |
+
demo.launch()
|