File size: 3,938 Bytes
f5193be
f9280be
 
 
 
 
 
0280c86
f9280be
 
f5193be
f9280be
f5193be
f9280be
 
a58296a
f9280be
5bd8f44
 
a58296a
f9280be
 
 
 
 
a58296a
f5193be
a58296a
f5193be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a58296a
f5193be
a58296a
 
f5193be
 
 
8d1c5f7
a58296a
 
 
fcfa53b
 
 
a58296a
 
 
 
 
 
 
 
 
 
fcfa53b
a58296a
 
 
 
 
 
fcfa53b
a58296a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcfa53b
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
87
88
89
90
91
92
93
94
95
96
97
#import modules
import numpy as np
import gradio as gr
import joblib
import pandas as pd
import os


def load_model():
    cwd = os.getcwd()

    destination = os.path.join(cwd, "saved cap")

    Final_model_file_path = os.path.join(destination, "Final_model.joblib")
    preprocessor_file_path = os.path.join(destination, "preprocessor.joblib")
    

    preprocessor = joblib.load(preprocessor_path)
    best_model = joblib.load(model_path)
    

    return Final_model, preprocessor

Final_model, preprocessor = load_model()


#define prediction function
def make_prediction(REGION, TENURE, MONTANT, FREQUENCE_RECH, REVENUE, ARPU_SEGMENT, FREQUENCE, DATA_VOLUME, ON_NET, ORANGE, TIGO, ZONE1, ZONE2,MRG, REGULARITY, FREQ_TOP_PACK):
    #make a dataframe from input data
    input_data = pd.DataFrame({'REGION':[REGION], 
                               'TENURE':[TENURE], 
                               'MONTANT':[MONTANT], 
                               'FREQUENCE_RECH':[FREQUENCE_RECH], 
                               'REVENUE':[REVENUE],
                               'ARPU_SEGMENT':[ARPU_SEGMENT], 
                               'FREQUENCE':[FREQUENCE], 
                               'DATA_VOLUME':[DATA_VOLUME], 
                               'ON_NET':[ON_NET],
                               'ORANGE':[ORANGE], 
                               'TIGO':[TIGO], 
                               'ZONE1':[ZONE1], 
                               'ZONE2':[ZONE2],
                               'MRG':[MRG],
                               'REGULARITY':[REGULARITY], 
                               'FREQ_TOP_PACK':[FREQ_TOP_PACK]})
    
    transformer = preprocessor.transform(input_data)
   
    predt = Final_model.predict(transformer) 
    #return prediction
    if predt[0]==1:
        return "Customer will Churn" 
    return "Customer will not Churn"
    

#create the input components for gradio
REGION = gr.Dropdown(choices =['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA' 'KAFFRINE,KOLDA', 'FATICK', 'MATAM', 'ZIGUINCHOR', 'SEDHIOU', 'KEDOUGOU']) 
TENURE = gr.Dropdown(choices =['K > 24 month', 'I 18-21 month', 'H 15-18 month', 'G 12-15 month', 'J 21-24 month', 'F 9-12 month', 'E 6-9 month', 'D 3-6 month']) 
MONTANT = gr.Number()
FREQUENCE_RECH = gr.Number()
REVENUE = gr.Number()
ARPU_SEGMENT = gr.Number() 
FREQUENCE = gr.Number() 
DATA_VOLUME = gr.Number() 
ON_NET = gr.Number()
ORANGE = gr.Number()
TIGO = gr.Number()
ZONE1 = gr.Number() 
ZONE2 = gr.Number()
MRG = gr.Dropdown(choices =['NO'])    
REGULARITY = gr.Number()
FREQ_TOP_PACK = gr.Number()

output = gr.Textbox(label='Prediction')
#create the interface component

app = gr.Interface(fn =make_prediction,inputs =[REGION, 
                                                TENURE, 
                                                MONTANT, 
                                                FREQUENCE_RECH, 
                                                REVENUE, 
                                                ARPU_SEGMENT, 
                                                FREQUENCE, 
                                                DATA_VOLUME, 
                                                ON_NET, 
                                                ORANGE, 
                                                TIGO, 
                                                ZONE1, 
                                                ZONE2,
                                                MRG, 
                                                REGULARITY, 
                                                FREQ_TOP_PACK],
                                                 title ="Customer Churn Predictor", 
                                                  description="Enter the feilds Below and click the submit button to Make Your Prediction",
                                                 outputs = output)

app.launch(debug = True)