-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
148 lines (113 loc) · 3.91 KB
/
app.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
import streamlit as st
import pandas as pd
import numpy as np
import time
import module.titanic as modu
from PIL import Image
from sklearn.preprocessing import StandardScaler
#st.set_page_config(
#page_title="Survivor Classificator",
#page_icon="🧊",
#layout="wide",
#initial_sidebar_state="expanded",
#)
hide_footer_style = """
<style>
.reportview-container .main footer {visibility: hidden;}
"""
st.markdown(hide_footer_style, unsafe_allow_html=True)
def show_footer():
st.markdown("***")
st.markdown("**© 2021 Developed by Daniele Grotti **")
st.markdown("**Like this tool?** Follow me on "
"[Linkedin](https://www.linkedin.com/in/daniele-grotti-38681146)")
def main():
#streamlit
st.title("Titanic Survivor Classificator")
################ css background #########################
with open("style.css") as f:
st.markdown('<style>{}</style>'.format(f.read()), unsafe_allow_html=True)
# Add a placeholder
latest_iteration = st.empty()
bar = st.progress(0)
for i in range(100):
# Update the progress bar with each iteration.
latest_iteration.text(f'Iteration {i+1}')
bar.progress(i + 1)
time.sleep(0.01)
image = Image.open('titanic.jpg')
st.image(image, caption='Titanic',use_column_width=True)
zero_list=(0,0,0,0,0,0,0,0,0,0)
test_df=pd.DataFrame([zero_list],columns=['Pclass_1','Pclass_2','Pclass_3','Fare','Sex','Age','SibSp','Parch','Child','Mother'])
#pclass/fare,pclass=1&2&3 £2100 & £1900 & £600,£84/£21/£14
fare_option=st.selectbox(' Welcome to Titanic ! Choose your class and start journey. ',
('Economy Class-£600','Bussiness Class-£1900','First Class-£2100'))
'You selected:', fare_option
if (fare_option=='First Class-£2100'):
test_df.loc[0,'Pclass_1']=1
test_df.loc[0,'Pclass_2']=0
test_df.loc[0,'Pclass_3']=0
test_df.loc[0,'Fare']=84
elif (fare_option=='Bussiness Class-£1900'):
test_df.loc[0,'Pclass_2']=1
test_df.loc[0,'Pclass_1']=0
test_df.loc[0,'Pclass_3']=0
test_df.loc[0,'Fare']=21
else:
test_df.loc[0,'Pclass_3']=1
test_df.loc[0,'Pclass_1']=0
test_df.loc[0,'Pclass_2']=0
test_df.loc[0,'Fare']=14
#gender
gender_option = st.selectbox('Please select your gender.',('Male','Female'))
'You selected:', gender_option
if (gender_option=='Male'):
test_df['Sex_male']=1
test_df['Sex_female']=0
else:
test_df['Sex_male']=0
test_df['Sex_female']=1
#Age
Age = st.slider('How old are you?', 0, 100, 1)
st.write("I'm ", Age, 'years old')
test_df.loc[0,'Age']=Age
#SibSp
spouse_option = st.selectbox('Are you married?',('No','Yes'))
if (spouse_option=='Yes'):
test_df['spouse']=1
else:
test_df['spouse']=0
sibling = st.number_input('How many sibling do you have?',value=0,max_value=20,step=1)
SibSp=test_df['spouse']+sibling
#children
children=st.number_input('How many children do you have?',value=0,max_value=20,step=1)
st.write('The current number is ', children)
#parents
parent_option=st.selectbox('Do you want to bring your parents?',('No','Yes'))
if (parent_option=='Yes'):
test_df['parent']=2
if (parent_option=='No'):
parent_num=st.selectbox('Choose the number of parents that you would like to bring.',(' Ok , I will ask one of them. - 1' , 'No , I do NOT play with them! - 0' ))
if (parent_num==' Ok , I will ask one of them. - 1'):
test_df['parent']=1
else:
test_df['parent']=0
test_df=modu.preprocessing(test_df)
#parch
test_df['Parch']=children+test_df['parent']
#mother
if (test_df.iloc[0]['Sex_female']==1) & (test_df.iloc[0]['Parch']>0):
test_df['Mother']=int(1)
#familysize
test_df['Familysize']=test_df['Parch']+test_df['SibSp']
test_df.drop(['spouse','Sex','parent'],axis=1,inplace=True)
st.write("Please check your data.")
st.write(test_df)
prob=modu.makeprediction(test_df)
#Result
if st.checkbox(' Show the Result ! '):
st.subheader('Result')
st.write('Your Survivability is %0.2f , Mortality is %0.2f'%(prob[1],prob[0]))
show_footer()
if __name__ == '__main__':
main()