Spaces:
Runtime error
Runtime error
File size: 2,554 Bytes
68d3508 |
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 |
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import json
import joblib as jb
from tensorflow.keras.models import load_model
from feature_engine.outliers import Winsorizer
#load models
final_pipeline = jb.load('final_pipeline.pkl')
model_ann = load_model('model.h5')
#load data
df = pd.read_csv('https://raw.githubusercontent.com/FerdiErs/SQL/main/churn.csv')
def run():
st.markdown("<h1 style='text-align: center;'>Churn predictor</h1>", unsafe_allow_html=True)
# description
st.subheader('Will youre customer churn?.')
with st.form('key=form_prediction') :
Age = st.number_input('AGE',min_value=10,max_value=70,step=1)
Region = st.selectbox('Region', df['region_category'].unique())
Member = st.selectbox('Membership Type', df['membership_category'].unique())
offer = st.selectbox('Preferred Offer', sorted(df['preferred_offer_types'].unique()))
Internet = st.selectbox('Your Connectivity', sorted(df['internet_option'].unique()))
last_login = st.number_input('last login',min_value=0,max_value=365,step=7)
time_spent = st.slider('TimeSpent',min_value=0,max_value=10000)
transaction_value = st.number_input('Money spent',min_value=10,max_value=99999999,step=1)
login_days = st.number_input('login streak',min_value=0,max_value=99999999)
points_in_wallet= st.number_input('wallet money',min_value=0,max_value=99999999)
past_complaint= st.selectbox('complaint', sorted(df['past_complaint'].unique()))
feedback = st.selectbox('feedback', sorted(df['feedback'].unique()))
submitted = st.form_submit_button('Predict')
data_inf = {
'age': Age,
'region_category': Region,
'membership_category': Member,
'preferred_offer_types': offer,
'internet_option': Internet,
'days_since_last_login': last_login,
'avg_time_spent': time_spent,
'avg_transaction_value': transaction_value,
'avg_frequency_login_days': login_days,
'points_in_wallet': points_in_wallet,
'past_complaint': past_complaint,
'feedback':feedback
}
data_inf = pd.DataFrame([data_inf])
st.dataframe(data_inf)
if submitted:
# transfrom data
data_inf_transform = final_pipeline.transform(data_inf)
# Predict using bagging
y_pred_inf = model_ann.predict(data_inf_transform)
y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
y_pred_inf
if __name__=='__main__':
run() |