Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from joblib import load
|
3 |
import pandas as pd
|
@@ -7,7 +8,6 @@ import pandas as pd
|
|
7 |
dv , model = load("train_model.joblib")
|
8 |
|
9 |
|
10 |
-
|
11 |
# creating a predict function to be passed into gradio UI
|
12 |
def predict(age, job, marital, education, default, housing,
|
13 |
loan, contact, month,day_of_week,campaign,pdays,
|
@@ -36,25 +36,62 @@ def predict(age, job, marital, education, default, housing,
|
|
36 |
|
37 |
print(customer)
|
38 |
df_transformed = dv.transform([customer])
|
39 |
-
prediction = model.predict_proba(df_transformed)[
|
40 |
|
|
|
|
|
|
|
41 |
# Desposited = prediction >= 0.50
|
42 |
|
43 |
# result = {
|
44 |
# "deposit_probability": float(prediction),
|
45 |
# "Deposited": bool(Deposited)
|
46 |
# }
|
47 |
-
|
|
|
48 |
|
49 |
-
return str(prediction)
|
50 |
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
age = gr.inputs.Slider(minimum=1,default = 35, maximum=100, step=1,label = 'Age') #default=data['age'].mean()
|
55 |
job = gr.inputs.Dropdown(choices=["Housemaid", "Services","Admin.","Blue-Collar","Technician",
|
56 |
-
"Retired","Management","Unemployed","Self-Employed","Unknown",
|
57 |
-
|
58 |
marital = gr.inputs.Dropdown(choices=["Married", "Single","Divorced","Unknown"],label = 'Marital')
|
59 |
education = gr.inputs.Dropdown(choices=["Basic.4y", "High.School","Basic.6y","Basic.9y","Professional.Course",
|
60 |
"Unknown","University.Degree","Illiterate"],label = 'Education')
|
@@ -78,12 +115,7 @@ cons_conf_idx = gr.inputs.Slider(minimum=-51,default = -42, maximum=-27, step =
|
|
78 |
iface = gr.Interface(predict,[age, job, marital, education, default, housing,
|
79 |
loan, contact, month,day_of_week,campaign,pdays,
|
80 |
previous,poutcome,emp_var_rate,cons_price_idx,cons_conf_idx],
|
81 |
-
|
82 |
-
|
83 |
)
|
84 |
-
iface.launch(share=True)
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
from joblib import load
|
4 |
import pandas as pd
|
|
|
8 |
dv , model = load("train_model.joblib")
|
9 |
|
10 |
|
|
|
11 |
# creating a predict function to be passed into gradio UI
|
12 |
def predict(age, job, marital, education, default, housing,
|
13 |
loan, contact, month,day_of_week,campaign,pdays,
|
|
|
36 |
|
37 |
print(customer)
|
38 |
df_transformed = dv.transform([customer])
|
39 |
+
prediction = model.predict_proba(df_transformed)[0]
|
40 |
|
41 |
+
# return prediction[1]
|
42 |
+
return {'Failure(!Deposit)': prediction[0], 'Success(Deposit)': prediction[1]}
|
43 |
+
|
44 |
# Desposited = prediction >= 0.50
|
45 |
|
46 |
# result = {
|
47 |
# "deposit_probability": float(prediction),
|
48 |
# "Deposited": bool(Deposited)
|
49 |
# }
|
50 |
+
# print(f' The probabilty of depositing in the bank is : {str(prediction)}')
|
51 |
+
|
52 |
|
|
|
53 |
|
54 |
|
55 |
+
# In[4]:
|
56 |
+
|
57 |
+
|
58 |
+
def feature_importance(age, job, marital, education, default, housing,
|
59 |
+
loan, contact, month,day_of_week,campaign,pdays,
|
60 |
+
previous,poutcome,emp_var_rate,cons_price_idx,cons_conf_idx):
|
61 |
+
customer = {
|
62 |
+
'age': age,
|
63 |
+
'job': job,
|
64 |
+
'marital': marital,
|
65 |
+
'education': education,
|
66 |
+
'default': default,
|
67 |
+
'housing': housing,
|
68 |
+
'loan': loan,
|
69 |
+
'contact': contact,
|
70 |
+
'month': month,
|
71 |
+
'day_of_week': day_of_week,
|
72 |
+
'campaign': campaign,
|
73 |
+
'pdays': pdays,
|
74 |
+
'previous': previous,
|
75 |
+
'poutcome': poutcome,
|
76 |
+
'emp_var_rate': emp_var_rate,
|
77 |
+
'cons_price_idx': cons_price_idx,
|
78 |
+
'cons_conf_idx': cons_conf_idx,
|
79 |
+
|
80 |
+
}
|
81 |
+
df_transformed = pd.DataFrame(dv.transform(customer))
|
82 |
+
df_transformed.columns = dv.get_feature_names_out()
|
83 |
+
important_features = pd.DataFrame({'cols':df_transformed.columns, 'imp':model.feature_importances_}
|
84 |
+
).sort_values('imp', ascending=False)
|
85 |
+
return important_features.plot('cols', 'imp', 'barh', figsize=(12,7), legend=False)
|
86 |
+
# return print(important_features.to_json())
|
87 |
+
|
88 |
+
|
89 |
|
90 |
|
91 |
age = gr.inputs.Slider(minimum=1,default = 35, maximum=100, step=1,label = 'Age') #default=data['age'].mean()
|
92 |
job = gr.inputs.Dropdown(choices=["Housemaid", "Services","Admin.","Blue-Collar","Technician",
|
93 |
+
"Retired","Management","Unemployed","Self-Employed","Unknown","Entrepreneur","Student"],
|
94 |
+
label = 'Job')
|
95 |
marital = gr.inputs.Dropdown(choices=["Married", "Single","Divorced","Unknown"],label = 'Marital')
|
96 |
education = gr.inputs.Dropdown(choices=["Basic.4y", "High.School","Basic.6y","Basic.9y","Professional.Course",
|
97 |
"Unknown","University.Degree","Illiterate"],label = 'Education')
|
|
|
115 |
iface = gr.Interface(predict,[age, job, marital, education, default, housing,
|
116 |
loan, contact, month,day_of_week,campaign,pdays,
|
117 |
previous,poutcome,emp_var_rate,cons_price_idx,cons_conf_idx],
|
118 |
+
outputs = "label",
|
119 |
+
interpretation=feature_importance
|
120 |
)
|
121 |
+
iface.launch(share=True , debug=True)
|
|
|
|
|
|
|
|
|
|