import streamlit as st from pybanking.churn_prediction import model_churn import pickle import sklearn.metrics as metrics from mlxtend.plotting import plot_confusion_matrix import matplotlib.pyplot as plt st.set_page_config(page_title="Customer Churn Prediction Model") st.title('Customer Churn Prediction Model') # x = st.slider('Select a value') st.subheader('This is the Sample Data') df = model_churn.get_data() st.dataframe(df.head(5)) model_names = [ "Logistic_Regression", "Support_Vector_Machine", "Support_Vector_Machine_Optimized", "Decision_Tree", "Neural_Network", "Random_Forest", "Pycaret_Best" ] option = st.selectbox( 'Select a model to be used', model_names ) st.write("Model Loaded : ", option) X, y = model_churn.preprocess_inputs(df, option) model = pickle.load(open(option+'.pkl', 'rb')) option2 = st.selectbox( 'Which dataset would you like to use for prediction?', ['Sample Dataset', 'Upload Custom'] ) if option2 == 'Upload custom': model = model_churn.train(df, model) st.dataframe(X.head(5)) y_pred = model.predict(X) st.write("Accuracy:",metrics.accuracy_score(y, y_pred)) st.write("Precision:",metrics.precision_score(y, y_pred)) st.write("Recall:",metrics.recall_score(y, y_pred)) fig, ax = plot_confusion_matrix(conf_mat=metrics.confusion_matrix(y, y_pred), figsize=(6, 6), cmap=plt.cm.Reds, colorbar=True) plt.xlabel('Predictions', fontsize=18) plt.ylabel('Actuals', fontsize=18) plt.title('Confusion Matrix', fontsize=18) st.pyplot(fig)