CoolFace
Apppublic

DevanPutra/Churn_Prediction

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py56 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import numpy as np4import joblib5import tensorflow as tf6from tensorflow.keras.models import Sequential, Model, load_model7 8# Load model and feature names9with open('pipeline.pkl', 'rb') as file_1:10    pipeline= joblib.load(file_1)11 12model_func_tune= load_model('model.h5')13 14# Set up app title and header image15st.set_page_config(page_title='Churn Rate Prediction')16st.title('Churn Rate Prediction')17st.image('https://i.imgur.com/rToAL0W.png', use_column_width=True)18 19# Collect user input using sliders20st.subheader('Enter Customers Information:')21membership_category = st.selectbox('membership_category', tuple(['Silver Membership', 'Gold Membership', 'No Membership',22                                                                 'Basic Membership', 'Platinum Membership', 'Premium Membership']))23joined_through_referral = st.selectbox('joined_through_referral', tuple(['Yes', 'No']))24feedback = st.selectbox('feedback', tuple(['Poor Product Quality', 'Poor Website', 'No reason specified',25       'Quality Customer Care', 'Poor Customer Service',26       'Reasonable Price', 'User Friendly Website', 'Too many ads',27       'Products always in Stock']))28avg_transaction_value = st.slider ('avg_transaction_value $', 0, 100000)29avg_frequency_login_days = st.slider ('avg_frequency_login_days ', 0, 50)30points_in_wallet = st.slider ('points_in_wallet $', 0, 1500)31 32 33# Generate new DataFrame based on user input34new_data = pd.DataFrame({35    'membership_category': [membership_category],36    'joined_through_referral': [joined_through_referral],37    'feedback': [feedback],38    'avg_transaction_value': [avg_transaction_value],39    'avg_frequency_login_days': [avg_frequency_login_days],40    'points_in_wallet': [points_in_wallet]41})42df= pipeline.transform(new_data)43# Make prediction and display result44if st.button('Predict'):45    y_pred_func_tuned = model_func_tune.predict(df)46    y_pred_func_tuned = np.where(y_pred_func_tuned >=0.5, 1, 0)  47    if y_pred_func_tuned == 1:48        message = "From the Customers information, it seems that the customers is churn."49        color = 'red'50    else:51        message = "From the Customers information, it seems that the customers is not churn."52        color = 'green'53    st.subheader('Prediction:')54    st.write(message, unsafe_allow_html=True, )55    st.markdown(f'<h1 style="color:{color};text-align:center">{y_pred_func_tuned}</h1>', unsafe_allow_html=True)56