-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_plotly.py
More file actions
330 lines (307 loc) · 9.4 KB
/
app_plotly.py
File metadata and controls
330 lines (307 loc) · 9.4 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import numpy as np
import pandas as pd
import pickle
import streamlit as st
import plotly_express as px
from sklearn.preprocessing import StandardScaler
st.set_option('deprecation.showfileUploaderEncoding', False)
sc=StandardScaler()
X_train=pd.read_csv('x_train.csv')
X_train=X_train.iloc[:,1:]
x_train=sc.fit_transform(X_train)
global df
df=pd.read_csv('data.csv')
global numeric_columns
global non_numeric_columns
from PIL import Image
pickle_in = open("project.pkl","rb")
classifier=pickle.load(pickle_in)
page_bg_img = '''
<style>
body {
background-image: url("https://images.unsplash.com/photo-1590283603385-17ffb3a7f29f?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8c3RvY2slMjBtYXJrZXR8ZW58MHx8MHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60");
background-size: cover;
}
</style>
'''
# st.markdown(page_bg_img, unsafe_allow_html=True)
def function(offer_type,gender,days_of_membership,total_amount,year,age_in_range,income_in_range):
l=[]
if(offer_type==1):
reward=10
difficulty=10
duration=168
mobile=1
social=1
web=0
bogo=1
discount=0
informational=0
elif(offer_type==2):
reward=10
difficulty=10
duration=120
mobile=1
social=1
web=1
bogo=1
discount=0
informational=0
elif(offer_type==3):
reward=0
difficulty=0
duration=96
mobile=1
social=0
web=1
bogo=0
discount=0
informational=1
elif(offer_type==4):
reward=5
difficulty=5
duration=168
mobile=1
social=0
web=1
bogo=1
discount=0
informational=0
elif(offer_type==5):
reward=5
difficulty=20
duration=240
mobile=0
social=0
web=1
bogo=0
discount=1
informational=0
elif(offer_type==6):
reward=3
difficulty=7
duration=168
mobile=1
social=1
web=1
bogo=0
discount=1
informational=0
elif(offer_type==7):
reward=2
difficulty=10
duration=240
mobile=1
social=1
web=1
bogo=0
discount=1
informational=0
elif(offer_type==8):
reward=0
difficulty=0
duration=72
mobile=1
social=1
web=0
bogo=0
discount=0
informational=1
elif(offer_type==9):
reward=5
difficulty=5
duration=120
mobile=1
social=1
web=1
bogo=1
discount=0
informational=0
elif(offer_type==10):
reward=2
difficulty=10
duration=168
mobile=1
social=0
web=1
bogo=0
discount=1
informational=0
M=0
F=0
O=0
if(gender=='F'):
F=1
elif(gender=='M'):
M=1
elif(gender=='O'):
O=1
y_2013=0
y_2014=0
y_2015=0
y_2016=0
y_2017=0
y_2018=0
if(year==2013):
y_2013=1
elif(year==2014):
y_2014=1
elif(year==2015):
y_2015=1
elif(year==2016):
y_2016=1
elif(year==2017):
y_2017=1
elif(year==2018):
y_2018=1
age_10s=0
age_20s=0
age_30s=0
age_40s=0
age_50s=0
age_60s=0
age_70s=0
age_80s=0
age_90s=0
age_100s=0
if(age_in_range=='10s'):
age_10s=1
elif(age_in_range=='20s'):
age_20s=1
elif(age_in_range=='30s'):
age_30s=1
elif(age_in_range=='40s'):
age_40s=1
elif(age_in_range=='50s'):
age_50s=1
elif(age_in_range=='60s'):
age_60s=1
elif(age_in_range=='70s'):
age_70s=1
elif(age_in_range=='80s'):
age_80s=1
elif(age_in_range=='90s'):
age_90s=1
elif(age_in_range=='100s'):
age_100s=1
in_40=0
in_50=0
in_60=0
in_70=0
in_80=0
in_100=0
in_110=0
in_120=0
if(income_in_range=='40k'):
in_40=1
if(income_in_range=='50k'):
in_50=1
if(income_in_range=='60k'):
in_60=1
if(income_in_range=='70k'):
in_70=1
if(income_in_range=='80k'):
in_80=1
if(income_in_range=='100k'):
in_100=1
if(income_in_range=='110k'):
in_110=1
if(income_in_range=='120k'):
in_120=1
l=[[reward,difficulty,duration,mobile,social,web,bogo,discount,informational,F,M,O,days_of_membership,total_amount,y_2013,y_2014,y_2015,y_2016,y_2017,y_2018,age_100s,age_10s,age_20s,age_30s,age_40s,age_50s,age_60s,age_70s,age_80s,age_90s,in_100,in_110,in_120,in_40,in_50,in_60,in_70,in_80]]
return l
def welcome():
return "Welcome All"
def membership_predict(offer_type,gender,days_of_membership,total_amount,year,age_in_range,income_in_range):
prediction=classifier.predict(sc.transform(function(offer_type,gender,days_of_membership,total_amount,year,age_in_range,income_in_range)))
print(prediction)
# print(sc.transform(function(offer_type,gender,days_of_membership,total_amount,year,age_in_range,income_in_range)))
return prediction
def main():
st.title("Infographs")
html_temp = """
<div style="background-color:Red;padding:10px">
<h1 style="color:orange;text-align:center;"><em>Infographs</em> </h1>
</div>
<br></br>
"""
offer=('Offer-Type-1','Offer-Type-2','Offer-Type-3','Offer-Type-4','Offer-Type-5','Offer-Type-6','Offer-Type-7','Offer-Type-8','Offer-Type-9','Offer-Type-10')
option_offer=list(range(len(offer)))
offer_type = st.selectbox("Offer_type",option_offer,format_func=lambda x:offer[x])
offer_type=offer_type+1
gender_box=('M','F','O')
gender = st.selectbox("Gender",options=list(gender_box))
days_of_membership = st.number_input("Days Of Memebership");
total_amount = st.number_input("Amount(Bill of the customer)")
year = st.number_input("year")
age_in_range = st.slider("Age",0,100);
age_in_range=str(age_in_range)+"s";
income_in_range = st.text_input("Income Of The Customer")
result=""
if st.button("Predict"):
result=membership_predict(offer_type,gender,days_of_membership,total_amount,year,age_in_range,income_in_range)
if(result ==1):
st.success("The Customer Will Take Member Ship")
elif(result==0):
st.warning("He wont Take")
agree=st.checkbox("Hide Graphs")
if (not agree):
st.sidebar.subheader("Visualization Settings")
try:
st.write(df)
# numeric_columns = list(df.select_dtypes(['float', 'int']).columns)
numeric_columns=list(['income','total_amount','days_of_membership'])
non_numeric_columns = list(df.select_dtypes(['object']).columns)
non_numeric_columns.append(None)
print(numeric_columns)
except Exception as e:
print(e)
st.write("Please upload file to the application.")
# add a select widget to the side bar
chart_select = st.sidebar.selectbox(
label="Select the chart type",
options=['Histogram', 'Lineplots','Scatterplots', 'Boxplot'])
if chart_select == 'Scatterplots':
st.sidebar.subheader("Scatterplot Settings")
try:
x_values = st.sidebar.selectbox('X axis', options=numeric_columns)
y_values = st.sidebar.selectbox('Y axis', options=numeric_columns)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.scatter(data_frame=df, x=x_values, y=y_values, color=color_value)
# display the chart
st.plotly_chart(plot)
except Exception as e:
print(e)
if chart_select == 'Lineplots':
st.sidebar.subheader("Line Plot Settings")
try:
x_values = st.sidebar.selectbox('X axis', options=numeric_columns)
y_values = st.sidebar.selectbox('Y axis', options=numeric_columns)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.line(data_frame=df, x=x_values, y=y_values, color=color_value)
st.plotly_chart(plot)
except Exception as e:
print(e)
if chart_select == 'Histogram':
st.sidebar.subheader("Histogram Settings")
try:
x = st.sidebar.selectbox('Feature', options=numeric_columns)
bin_size = st.sidebar.slider("Number of Bins", min_value=10,
max_value=100, value=40)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.histogram(x=x, data_frame=df, color=color_value)
st.plotly_chart(plot)
except Exception as e:
print(e)
if chart_select == 'Boxplot':
st.sidebar.subheader("Boxplot Settings")
try:
y = st.sidebar.selectbox("Y axis", options=numeric_columns)
x = st.sidebar.selectbox("X axis", options=non_numeric_columns)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.box(data_frame=df, y=y, x=x, color=color_value)
st.plotly_chart(plot)
except Exception as e:
print(e)
if __name__=='__main__':
main()