File size: 3,941 Bytes
4a965b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pickle
import pandas as pd
from tensorflow.keras.models import load_model
import numpy as np
# from sklearn.pipeline import make_pipeline
# from sklearn.preprocessing import StandardScaler, OneHotEncoder
# from sklearn.svm import SVC
# from sklearn.linear_model import LogisticRegression
# from sklearn.tree import DecisionTreeClassifier
# from sklearn.ensemble import RandomForestClassifier


# Load the Models

with open('final_pipeline.pkl', 'rb') as file_1:
  model_pipeline = pickle.load(file_1)

model_ann = load_model('churn_model.h5')

def run():
    with st.form(key='form_prediksi'):
        name = st.text_input('Nama', value='')
        sex = st.radio('Kelamin', ('Perempuan', 'Laki-Laki'))
        if sex=='Laki-Laki':
            gender='M'
        else: gender='F'
        age= st.number_input('Umur', min_value=16, max_value=80, value=50, step=1)
        regcat=st.selectbox('Kategori Daerah: ',('Village','Town', 'City'))
        memcat=st.selectbox('Kategori Membership: ',('No Membership','Basic Membership', 'Gold Membership', 'Premium Membership','Platinum Membership'))
        ref = st.radio('apakah bergabung melalui referal?', ('Yes', 'No'))
        medium=st.selectbox('Medium Akses: ',('Smartphone','Desktop', 'Both'))
        preferensi=st.selectbox('Preferensi Penawaran: ',('Credit/Debit Card Offers', 'Gift Vouchers/Coupons','Without Offers'))
        internet=st.selectbox('Preferensi Penawaran: ',('Fiber_Optic', 'Wi-Fi', 'Mobile_Data'))
        daylast= st.number_input('Hari dari login terakhir', min_value=0, max_value=100, value=50, step=1)
        avgday= st.number_input('Waktu pemakaiwn rata rata', min_value=0, max_value=100, value=50, step=1)
        avgtran= st.number_input('Rata rata jumlah transaksi', min_value=0, max_value=50000, value=10000, step=1)
        avgfreq= st.number_input('Hari dari login terakhit', min_value=0, max_value=30, value=10, step=1)
        point= st.number_input('Point dalam Wallet', min_value=0, max_value=2000, value=50, step=1)
        diskon= st.radio('Pernah menggunakan diskon spesial?', ('Yes', 'No'))
        offer= st.radio('offer aplication prefrence?', ('Yes', 'No'))
        past=st.radio('Pernah komplain?', ('Yes', 'No'))
        complain= st.selectbox('Preferensi Penawaran: ',('Not Applicable', 'Unsolved', 'Solved', 'No Information Available','Solved in Follow-up'))
        feedback= st.selectbox('Preferensi Penawaran: ',('Too many ads', 'No reason specified', 'Reasonable Price','Quality Customer Care', 'Poor Website', 'Poor Customer Service','Poor Product Quality', 'User Friendly Website', 'Products always in Stock'))

        submitted = st.form_submit_button('Predict')

    data_inf = {
        'age': age,
        'gender': gender,
        'region_category':regcat,
        'membership_category':memcat,
        'joined_through_referral':ref, 
        'preferred_offer_types':preferensi,
        'medium_of_operation':medium, 
        'internet_option':internet, 
        'days_since_last_login':daylast,
        'avg_time_spent':avgday, 
        'avg_transaction_value': avgtran, 
        'avg_frequency_login_days':avgfreq,
        'points_in_wallet':point, 
        'used_special_discount':diskon,
        'offer_application_preference':offer, 
        'past_complaint':past, 
        'complaint_status':complain,
        'feedback': feedback
    }



    if submitted:
        data_inf = pd.DataFrame([data_inf])
        # Transform Inference-Set

        data_inf_transform = model_pipeline.transform(data_inf)
        data_inf_transform
        y_pred_inf = model_ann.predict(data_inf_transform)
        y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
        value = y_pred_inf[0][0]
        print(value)
        if value==1:
            result= "Pelanggan diprediksi akan Churn"
        else: result= "Pelanggan diprediksi tidak akan Churn"
        st.write(result)

if __name__== '__main__':
    run()