-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitanic_app.py
46 lines (34 loc) · 1.73 KB
/
titanic_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
import streamlit as st
import pickle
from datetime import datetime
startTime = datetime.now()
filename ="model.sv"
model = pickle.load(open(filename,'rb'))
sex_d = {0:"Female",1:"Male"}
pclass_d = {0:"First",1:"Second", 2:"Third"}
embarked_d = {0:"Cherbourg", 1:"Queenstown", 2:"Southampton"}
def main():
st.set_page_config(page_title="Titanic Survival App")
overview = st.beta_container()
left, right = st.beta_columns(2)
prediction = st.beta_container()
with overview:
st.title("Titanic App")
st.markdown("Model: Random Forest Classifier, trained on titanic training dataset from [Kaggle](https://www.kaggle.com/c/titanic/data). See associated notebook for details on how the model was trained.")
with left:
sex_radio = st.radio( "Sex", list(sex_d.keys()), format_func=lambda x : sex_d[x] )
pclass_radio = st.radio( "Ticket Class", list(pclass_d.keys()), format_func=lambda x: pclass_d[x])
embarked_radio = st.radio( "Port of Embarkment", list(embarked_d.keys()), index=2, format_func= lambda x: embarked_d[x] )
with right:
age_slider = st.slider("Age", value=50, min_value=1, max_value=100)
sibsp_slider = st.slider( "# Siblings / Spouses on board", min_value=0, max_value=8)
parch_slider = st.slider( "# Parents / Children on board", min_value=0, max_value=6)
fare_slider = st.slider( "Passenger Fare", min_value=0, max_value=500, step=10)
data = [[pclass_radio, sex_radio, age_slider, sibsp_slider, parch_slider, fare_slider, embarked_radio]]
survival = model.predict(data)
s_confidence = model.predict_proba(data)
with prediction:
st.header("Survived? {0}".format("Yes" if survival[0] == 1 else "No"))
st.subheader("Confidence {0:.2f} %".format(s_confidence[0][survival][0] * 100))
if __name__ == "__main__":
main()