File size: 2,753 Bytes
a37e421
 
 
 
 
f439d1b
a37e421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Fonction de prédiction
import gradio as gr
import joblib
import pandas as pd
import numpy as np
from keras.models import load_model
# importer les encodeurs

#importer le cat_data

cat_data_columns = joblib.load('cat_data_columns.joblib')
encoders = []
for i in range(len(cat_data_columns)):
  encoders.append(joblib.load(f'{cat_data_columns[i]}_encoder.joblib'))
# importer le modèle
model = load_model('DNN_model.h5')
# importer le scaler
scaler = joblib.load('scaler.joblib')


# Fonction de prédiction simple
def prediction_func(age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome):
  # encoder les valeurs
  job = encoders[0].transform([job])[0]
  marital = encoders[1].transform([marital])[0]
  education = encoders[2].transform([education])[0]
  default = encoders[3].transform([default])[0]
  housing = encoders[4].transform([housing])[0]
  loan = encoders[5].transform([loan])[0]
  contact = encoders[6].transform([contact])[0]
  month = encoders[7].transform([month])[0]
  day_of_week = encoders[8].transform([day_of_week])[0]
  poutcome = encoders[9].transform([poutcome])[0]
  # vecteur des valeurs
  x_new = np.array([age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome]).reshape(1, -1)
  # normaliser les valeurs
  x_new = scaler.transform(x_new)
  # prédire la valeur
  y_pred = np.round(model.predict(x_new))
  # retourner
  if y_pred == 1:
    return 'Souscrire'
  else:
    return 'Pas souscrire'

# load les valeurs uniques
uniques = []
for i in range(len(cat_data_columns)):
  uniques.append(joblib.load(f'{cat_data_columns[i]}_unique.joblib'))
# créer les inputs
inputs = [gr.Number(label="age"),
          gr.Dropdown(uniques[0], label="job"),
          gr.Dropdown(uniques[1], label="marital"),
          gr.Dropdown(uniques[2], label="education"),
          gr.Dropdown(uniques[3], label="default"),
          gr.Dropdown(uniques[4], label="housing"),
          gr.Dropdown(uniques[5], label="loan"),
          gr.Dropdown(uniques[6], label="contact"),
          gr.Dropdown(uniques[7], label="month"),
          gr.Dropdown(uniques[8], label="day_of_week"),
          gr.Number(label="duration"),
          gr.Number(label="campaign"),
          gr.Number(label="pdays"),
          gr.Number(label="previous"),
          gr.Dropdown(uniques[9], label="poutcome")]
# créer les outputs
outputs = gr.Textbox(label = 'Souscription')
# Interface
Interface =gr.Interface(fn = prediction_func,
             inputs = inputs,
             outputs = outputs,
             title = 'Bank Marketing Prediction',
             theme='NoCrypt/miku'
             )
Interface.launch()