Spaces:
Sleeping
Sleeping
File size: 4,411 Bytes
be34d0f |
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 |
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import json
import datetime
import tensorflow as tf
from tensorflow.keras.models import load_model
# Load 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='from_fifa_2022'):
user_Id = st.text_input('UserID', value='')
age = st.number_input('Age', min_value=10, max_value=80, step=1, help='Usia Prediksi')
st.write('M = Male | F = Female')
gender = st.selectbox('Gender', ('M', 'F'), index=1)
region_category = st.selectbox('Region', ('Town', 'City', 'Village'), index=1)
membership_category = st.selectbox('Membership', ('No Membership', 'Basic Membership', 'Gold Membership', 'Silver Membership', 'Premium Membership', 'Platinum Membership'), index=1)
st.markdown('---')
joining_date = st.date_input('JoiningDate', datetime.date(2019, 7, 6))
joined_through_referral = st.selectbox('Referral', ('Yes', 'No'), index=1)
preferred_offer_types = st.selectbox('Offer', ('Gift Vouchers/Coupons', 'Credit/Debit Card Offers', 'Without Offers'), index=1)
medium_of_operation = st.selectbox('Devices', ('Desktop', 'Smartphone', 'Both'), index=1)
internet_option = st.selectbox('InternetOption', ('Wi-Fi', 'Mobile_Data', 'Fiber_Optic'), index=1)
last_visit_time = st.date_input('LastVisit', datetime.date(2019, 7, 6))
st.markdown('---')
days_since_last_login = st.number_input('DaysLastLogin', min_value=1, max_value=100)
avg_time_spent = st.number_input('AverageTimeSpent', min_value=1, max_value=1000)
avg_transaction_value = st.number_input('Transaction', min_value=1, max_value=100000)
avg_frequency_login_days = st.number_input('FrequencyLogin', min_value=1, max_value=31)
points_in_wallet = st.number_input('WalletPoint', min_value=10, max_value=10000)
st.markdown('---')
used_special_discount = st.selectbox('UsedDiscount', ('Yes', 'No'), index=1)
offer_application_preference = st.selectbox('OfferAplication', ('Yes', 'No'), index=1)
past_complaint = st.selectbox('PastComplaint', ('Yes', 'No'), index=1)
complaint_status = st.selectbox('ComplaintStatus', ('Not Applicable', 'Unsolved', 'Solved', 'Solved in Follow-up', 'No Information Available'), index=1)
feedback = st.selectbox('Feedback', ('Poor Product Quality', 'No reason specified', 'Too many ads', 'Poor Website',
'Poor Customer Service', 'Reasonable Price', 'User Friendly Website', 'Products always in Stock', 'Quality Customer Care'), index=1)
submitted = st.form_submit_button('Prediction')
data_inf = {
'user_Id': user_Id,
'age': age,
'gender': gender,
'region_category': region_category,
'membership_category': membership_category,
'joining_date': joining_date,
'joined_through_referral': joined_through_referral,
'preferred_offer_types': preferred_offer_types,
'medium_of_operation': medium_of_operation,
'internet_option': internet_option,
'last_visit_time': last_visit_time,
'days_since_last_login': days_since_last_login,
'avg_time_spent': avg_time_spent,
'avg_transaction_value': avg_transaction_value,
'avg_frequency_login_days': avg_frequency_login_days,
'points_in_wallet': points_in_wallet,
'used_special_discount': used_special_discount,
'offer_application_preference': offer_application_preference,
'past_complaint': past_complaint,
'complaint_status': complaint_status,
'feedback': feedback
}
data_inf = pd.DataFrame([data_inf])
st.dataframe(data_inf)
if submitted:
# input pipeline
data_inf_final = model_pipeline.transform(data_inf)
# Predict Model
y_pred_inf = model_ann.predict(data_inf_final)
y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
if y_pred_inf == 0:
hasil_prediksi = "Not Churn"
else:
hasil_prediksi = "Churn"
# Print Hasil prediksi
st.write('Prediksi Kemungkinan : ', hasil_prediksi)
if __name__== '__main__':
run() |