File size: 3,512 Bytes
966824d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import gradio as gr
from joblib import load
import pandas as pd

dv , model = load("train_model.joblib")


# creating a predict function to be passed into gradio UI
def predict(age, job, marital, education, default, housing,
            loan, contact, month,day_of_week,campaign,pdays,
            previous,poutcome,cons_price_idx,cons_conf_idx,emp_var_rate):
  
    customer = {
        'age': age,
        'job': job,
        'marital': marital,
        'education': education,
        'default': default, 
        'housing': housing,
        'loan': loan,
        'contact': contact,
        'month': month,
        'day_of_week': day_of_week,
        'campaign': campaign,
        'pdays': pdays,
        'previous': previous,
        'poutcome': poutcome,
        'cons_price_idx': cons_price_idx,
        'cons_conf_idx': cons_conf_idx,
        'emp_var_rate': emp_var_rate
    }
    
    print(customer)
    df_transformed = dv.transform([customer])
    prediction = model.predict_proba(df_transformed)[:,1]
    
#     Desposited = prediction >= 0.50
    
#     result = {
#         "deposit_probability": float(prediction),
#         "Deposited": bool(Deposited)
#     } 
    print(f' The probabilty of depositing in the bank is  : {str(prediction)}')
    
    return str(prediction)

age = gr.inputs.Slider(minimum=1,default = 35, maximum=100, label = 'age') #default=data['age'].mean()
job = gr.inputs.Dropdown(choices=["housemaid", "services","admin.","blue-collar","technician",
                                 "retired","management","unemployed","self-employed","unknown",
                                  "entrepreneur","student"],label = 'job')
marital = gr.inputs.Dropdown(choices=["married", "single","divorced","unknown"],label = 'marital')
education = gr.inputs.Dropdown(choices=["basic.4y", "high.school","basic.6y","basic.9y","professional.course",
                                 "unknown","university.degree","illiterate"],label = 'education')
default = gr.inputs.Dropdown(choices=["yes", "no","unknown"],label = 'default')
housing = gr.inputs.Dropdown(choices=["yes", "no","unknown"],label = 'housing')
loan = gr.inputs.Dropdown(choices=["yes", "no","unknown"],label = 'loan')
contact = gr.inputs.Dropdown(choices=["telephone", "cellular"],label = 'contact')
month = gr.inputs.Dropdown(choices=['may', 'jun', 'jul', 'aug', 'oct', 'nov', 'dec',
                                    'mar', 'apr','sep'],label = 'month')
day_of_week = gr.inputs.Dropdown(choices=['mon', 'tue', 'wed', 'thu', 'fri'],label = 'day_of_week')
campaign = gr.inputs.Slider(minimum=1,default = 2, maximum=56, label = 'campaign') 
pdays = gr.inputs.Slider(minimum=0,default = 0, maximum=27, label = 'pdays') 
previous = gr.inputs.Slider(minimum=0,default = 0, maximum=7, label = 'previous') 
poutcome = gr.inputs.Dropdown(choices=["nonexistent", "failure","success"],label = 'poutcome')
cons_price_idx = gr.inputs.Slider(minimum=92,default = 94, maximum=95, label = 'cons_price_idx')
cons_conf_idx = gr.inputs.Slider(minimum=-51,default = -42, maximum=-27, label = 'cons_conf_idx')
emp_var_rate = gr.inputs.Slider(minimum=4964,default = 5191, maximum=5228, label = 'emp_var_rate')





iface = gr.Interface(predict,[age, job, marital, education, default, housing,
            loan, contact, month,day_of_week,campaign,pdays,
            previous,poutcome,cons_price_idx,cons_conf_idx,emp_var_rate],
             outputs = "number",
            interpretation="default"
             )
iface.launch(share=True)