Ariussabaramondo commited on
Commit
a5862c5
·
verified ·
1 Parent(s): 26efe77

Rename README.md to app.py

Browse files
Files changed (2) hide show
  1. README.md +0 -3
  2. app.py +69 -0
README.md DELETED
@@ -1,3 +0,0 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fonction de prédiction
2
+ import gradio as gr
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ from keras.models import load_model
7
+
8
+ # importer les encodeurs
9
+ encoders = joblib.load(f'encoders.joblib')
10
+ #for i in range(len(cat_data.columns)):
11
+ #encoders.append(joblib.load(f'{cat_data.columns[i]}_encoder.joblib'))
12
+ # importer le modèle
13
+ model = load_model('DNN_model.h5')
14
+ # importer le scaler
15
+ scaler = joblib.load('scaler.joblib')
16
+ # Fonction de prédiction simple
17
+ def prediction_func(age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome):
18
+ # encoder les valeurs
19
+ job = encoders[0].transform([job])[0]
20
+ marital = encoders[1].transform([marital])[0]
21
+ education = encoders[2].transform([education])[0]
22
+ default = encoders[3].transform([default])[0]
23
+ housing = encoders[4].transform([housing])[0]
24
+ loan = encoders[5].transform([loan])[0]
25
+ contact = encoders[6].transform([contact])[0]
26
+ month = encoders[7].transform([month])[0]
27
+ day_of_week = encoders[8].transform([day_of_week])[0]
28
+ poutcome = encoders[9].transform([poutcome])[0]
29
+ # vecteur des valeurs
30
+ x_new = np.array([age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome]).reshape(1, -1)
31
+ # normaliser les valeurs
32
+ x_new = scaler.transform(x_new)
33
+ # prédire la valeur
34
+ y_pred = np.round(model.predict(x_new))
35
+ # retourner
36
+ if y_pred == 1:
37
+ return 'Souscrire'
38
+ else:
39
+ return 'Pas souscrire'
40
+
41
+ # load les valeurs uniques
42
+ # importer les uniques
43
+ uniques = joblib.load(f'uniques.joblib')
44
+ #for i in range(len(cat_data.columns)):
45
+ #uniques.append(joblib.load(f'{cat_data.columns[i]}_unique.joblib'))
46
+ # créer les inputs
47
+ inputs = [gr.Number(label="age"),
48
+ gr.Dropdown(uniques[0], label="job"),
49
+ gr.Dropdown(uniques[1], label="marital"),
50
+ gr.Dropdown(uniques[2], label="education"),
51
+ gr.Dropdown(uniques[3], label="default"),
52
+ gr.Dropdown(uniques[4], label="housing"),
53
+ gr.Dropdown(uniques[5], label="loan"),
54
+ gr.Dropdown(uniques[6], label="contact"),
55
+ gr.Dropdown(uniques[7], label="month"),
56
+ gr.Dropdown(uniques[8], label="day_of_week"),
57
+ gr.Number(label="duration"),
58
+ gr.Number(label="campaign"),
59
+ gr.Number(label="pdays"),
60
+ gr.Number(label="previous"),
61
+ gr.Dropdown(uniques[9], label="poutcome")]
62
+ # créer les outputs
63
+ outputs = gr.Textbox(label = 'Souscription')
64
+ # Interface
65
+ Interface =gr.Interface(fn = prediction_func,
66
+ inputs = inputs,
67
+ outputs = outputs,
68
+ title = 'Bank Marketing Prediction', theme='earneleh/paris')
69
+ Interface.launch()