| | |
| | import gradio as gr |
| | import joblib |
| | import pandas as pd |
| | import numpy as np |
| | from keras.models import load_model |
| | |
| | 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')) |
| | |
| | model = load_model('DNN_model.h5') |
| | |
| | scaler = joblib.load('scaler.joblib') |
| | |
| | def prediction_func(age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome): |
| | |
| | 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] |
| | |
| | x_new = np.array([age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome]).reshape(1, -1) |
| | |
| | x_new = scaler.transform(x_new) |
| | |
| | y_pred = np.round(model.predict(x_new)) |
| | |
| | if y_pred == 1: |
| | return 'Souscrire' |
| | else: |
| | return 'Pas souscrire' |
| | |
| | uniques = [] |
| | for i in range(len(cat_data_columns)): |
| | uniques.append(joblib.load(f'{cat_data_columns[i]}_unique.joblib')) |
| | |
| | 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")] |
| | |
| | outputs = gr.Textbox(label = 'Souscription') |
| | |
| | Interface =gr.Interface(fn = prediction_func, |
| | inputs = inputs, |
| | outputs = outputs, |
| | title = 'Bank Marketing Prediction', |
| | theme = 'earneleh/paris') |
| |
|
| | Interface.launch() |