Spaces:
Runtime error
Runtime error
File size: 3,255 Bytes
971bc47 6a5b679 5610cc7 6a5b679 02d331f 6a5b679 efe82c1 02d331f b337966 02d331f efe82c1 2fdd5dd 02d331f 6a5b679 93b0219 6a5b679 edcda0c 6a5b679 edcda0c fec118d 6a5b679 edcda0c fec118d efe82c1 edcda0c 6a5b679 edcda0c fec118d 6a5b679 93b0219 02d331f 93b0219 02d331f 93b0219 6a5b679 02d331f 5610cc7 02d331f 5610cc7 02d331f 5610cc7 02d331f |
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import streamlit as st
import streamlit.components.v1 as components
import pandas as pd
import pickle
import matplotlib.pyplot as plt
from pybanking.churn_prediction import model_churn
from pybanking.EDA import data_analysis
import sklearn.metrics as metrics
from mlxtend.plotting import plot_confusion_matrix
import streamlit.components.v1 as components
from PIL import Image
st.set_page_config(page_title="Customer Churn Prediction Model", layout="wide")
col1,col2 = st.columns([1,2])
with col1:
image = Image.open('Shorthills.png')
st.image(image)
with col2:
st.title('Customer Churn Prediction Model')
df = model_churn.get_data()
option2 = st.selectbox(
'Which dataset would you like to use for prediction?',
['Sample Dataset', 'Upload Custom']
)
if option2 == 'Upload Custom':
file = st.file_uploader("Choose a file")
if file is not None:
#read csv
df = pd.read_csv(file)
else:
st.warning("you need to upload a csv file.")
st.subheader('This is the Selected Data')
st.dataframe(df.head(5))
analysis_class = data_analysis.Analysis()
option3 = st.selectbox(
'Select Exploratory Data Analysis type',
['None', 'DataPrep', 'SweetViz', 'PandasProfiling']
)
if option3 == 'SweetViz':
res = analysis_class.sweetviz_analysis(df)
res.show_html(filepath='SweetViz.html', open_browser=True, layout='widescreen', scale=None)
HtmlFile = open('SweetViz.html', 'r', encoding='utf-8')
source_code = HtmlFile.read()
with st.expander("See Report"):
components.html(source_code, height=600, scrolling=True)
elif option3 == 'DataPrep':
res = analysis_class.dataprep_analysis(df)
# res.show_browser()
res.save('DataPrep.html')
HtmlFile = open('DataPrep.html', 'r', encoding='utf-8')
source_code = HtmlFile.read()
with st.expander("See Report"):
components.html(source_code, height=600, scrolling=True)
elif option3 == 'PandasProfiling':
res = analysis_class.pandas_analysis(df)
res.to_file("PandasProfiling.html")
HtmlFile = open('PandasProfiling.html', 'r', encoding='utf-8')
source_code = HtmlFile.read()
with st.expander("See Report"):
components.html(source_code, height=600, scrolling=True)
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
)
model = pickle.load(open(option+'.pkl', 'rb'))
st.write("Model Loaded : ", option)
X, y = model_churn.preprocess_inputs(df, option)
if option2 == 'Upload custom':
model = model_churn.train(df, model)
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) |