Spaces:
Runtime error
Runtime error
updated
Browse files- app.py +38 -0
- churn_model2.h5 +3 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tensorflow.keras.models import load_model
|
2 |
+
|
3 |
+
saved_model = load_model('churn_model2.h5')
|
4 |
+
|
5 |
+
def churn_prediction(CreditScore,Gender,Age,Tenure,Balance,NumOfProducts,HasCrCard,IsActiveMember,EstimatedSalary,Location):
|
6 |
+
Geography_France,Geography_Germany,Geography_Spain=0,0,0
|
7 |
+
df = pd.DataFrame.from_dict({
|
8 |
+
"Credit score":[CreditScore],
|
9 |
+
"Is female?":[1 if Gender=='Female' else 0],
|
10 |
+
"Age":[Age],
|
11 |
+
'Tenure':[Tenure],
|
12 |
+
'Balance':[Balance],
|
13 |
+
'Number of products':[NumOfProducts],
|
14 |
+
'Has credit card?': [1 if HasCrCard=='Yes' else 0],
|
15 |
+
'Is a active member?':[1 if IsActiveMember=='Yes' else 0],
|
16 |
+
'Estimated Salary': [EstimatedSalary],
|
17 |
+
'Geography_France': [1 if Location=='France' else 0],
|
18 |
+
'Geography_Germany':[1 if Location=='Germany' else 0],
|
19 |
+
'Geography_Spain':[1 if Location=='Spain' else 0]
|
20 |
+
|
21 |
+
})
|
22 |
+
cols_to_scale = ["Credit score",'Age','Tenure','Balance','Number of products','Estimated Salary']
|
23 |
+
df[cols_to_scale] = scaler.transform(df[cols_to_scale])
|
24 |
+
pred=saved_model.predict(df)
|
25 |
+
pred = pred[0][0]
|
26 |
+
churn_prob=str(round(pred,2))
|
27 |
+
non_churn_prob = str(round(1-pred,2))
|
28 |
+
percent_likelihood = int(pred*100)
|
29 |
+
return {"probability customer will exit (%)":churn_prob , "probability customer will stay (%)": non_churn_prob}
|
30 |
+
|
31 |
+
|
32 |
+
import gradio as gr
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=churn_prediction,
|
35 |
+
inputs=['number',gr.inputs.Radio(['Female','Male']),'number','number','number','number',gr.inputs.Radio(['Yes','No']),gr.inputs.Radio(['Yes','No']),'number',gr.inputs.Radio(['France','Germany','Spain'])],
|
36 |
+
outputs=['label'])
|
37 |
+
|
38 |
+
iface.launch()
|
churn_model2.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c002ce5378d37e065dc66704b68b083aa314ad4ff32e8d824179d4e6ad34ded0
|
3 |
+
size 34600
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tensorflow
|