-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_seg.py
174 lines (97 loc) · 3.51 KB
/
main_seg.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import streamlit as st
import numpy as np
import pandas as pd
import pickle
# In[7]:
import sklearn
print(sklearn.__version__)
# In[ ]:
# Load the trained model from a file
with open('model.pkl', 'rb') as f:
model = pickle.load(f)
# In[8]:
#read the template
template = pd.read_csv("BankChurners.csv")
# In[ ]:
# Add a sidebar to the app
st.sidebar.title('K-Means Model')
#add a title
st.title("Bank of Offer Customer Segmentation")
# In[ ]:
beha_c = ['Card_Category',]
beha_n = [ 'Months_on_book', 'Total_Relationship_Count',
'Credit_Limit','Months_Inactive_12_mon', 'Contacts_Count_12_mon',
'Total_Revolving_Bal', 'Total_Amt_Chng_Q4_Q1', 'Total_Trans_Amt', 'Total_Trans_Ct',
'Total_Ct_Chng_Q4_Q1', 'Avg_Utilization_Ratio' ]
# In[ ]:
# Display a radio button group
option = st.radio("Choose an option:", ["Upload a csv file", "Enter data"])
# In[ ]:
if option == "Upload a csv file":
# Allow the user to upload a file
uploaded_file = st.file_uploader("Upload a file")
if uploaded_file is not None:
# Process the uploaded file
df = pd.read_csv(uploaded_file)
# Use the model to make predictions on the DataFrame
predictions = model.predict(df)
# Display the predictions
st.write(predictions)
# In[ ]:
elif option == "Enter data":
# Allow the user to enter data
#Card_Category
card = st.selectbox('Card Category',template['Card_Category'].unique())
#month on book
month_on_book = st.number_input('Months_on_book')
#total relationship
relationship = st.number_input('Total_Relationship_Count')
#credit limit
limit = st.number_input('Credit_Limit')
#month inactive
month_inactive = st.number_input('Months_Inactive_12_mon')
#contacts counts
contacts = st.number_input('Contacts_Count_12_mon')
#total revolving bal
balance = st.number_input('Total_Revolving_Bal')
#total amount change 4 to 1
amount_c41 = st.number_input('Total_Amt_Chng_Q4_Q1')
#total transaction amount
amount = st.number_input('Total_Trans_Amt')
#total transaction counts
count = st.number_input('Total_Trans_Ct')
#total count hange 4 to 1
count_c41 = st.number_input('Total_Ct_Chng_Q4_Q1')
#avg utilization ratio
ratio = st.number_input('Avg_Utilization_Ratio')
df = pd.DataFrame()
df['Card_Category'] = [card]
df['Months_on_book'] = [month_on_book]
df['Total_Relationship_Count'] = [relationship]
df['Credit_Limit'] = [limit]
df['Months_Inactive_12_mon'] = [month_inactive]
df['Contacts_Count_12_mon'] = [contacts]
df['Total_Revolving_Bal'] = [balance]
df['Total_Amt_Chng_Q4_Q1'] = [amount_c41]
df['Total_Trans_Amt'] = [amount]
df['Total_Trans_Ct'] = [count]
df['Total_Ct_Chng_Q4_Q1'] = [count_c41]
df['Avg_Utilization_Ratio'] = [ratio]
# Use the model to make predictions on the DataFrame
predictions = model.predict(df)
# Display the predictions
st.write(predictions)
# In[ ]:
# In[ ]:
uploaded_file = st.file_uploader("Upload a CSV file", type="csv")
# In[3]:
if uploaded_file is not None:
# Read the CSV file into a pandas DataFrame
df = pd.read_csv(uploaded_file)
# Use the model to make predictions on the DataFrame
predictions = model.predict(df)
# Display the predictions
st.write(predictions)