-
Notifications
You must be signed in to change notification settings - Fork 1
/
streamlit-app.py
43 lines (35 loc) · 1.3 KB
/
streamlit-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
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import joblib
st.title('Titanic Survival Prediction')
st.markdown('**Please provide passenger information**:') # you can use markdown like this
# load models
tree_clf = joblib.load('clf-best.pickle')
# get inputs
sex = st.selectbox('Sex', ['female', 'male'])
age = int(st.number_input('Age:', 0, 120, 20))
sib_sp = int(st.number_input('# of siblings / spouses aboard:', 0, 10, 0))
#par_ch = int(st.number_input('# of parents / children aboard:', 0, 10, 0))
pclass = st.selectbox('Ticket class (1 = 1st, 2 = 2nd, 3 = 3rd)', [1, 2, 3])
fare = int(st.number_input('# of parents / children aboard:', 0, 100, 0))
#embarked = st.selectbox('Port of Embarkation (C = Cherbourg, Q = Queenstown, S = Southampton)', ['C', 'Q', 'S'])
# this is how to dynamically change text
prediction_state = st.markdown('calculating...')
passenger = pd.DataFrame(
{
'Pclass': [pclass],
'Sex': [sex],
'Age': [age],
'SibSp': [sib_sp],
# 'Parch': [par_ch],
'Fare': [fare],
# 'Embarked': [embarked],
}
)
y_pred = tree_clf.predict(passenger)
if y_pred[0] == 0:
msg = 'This passenger is predicted to be: **died**'
else:
msg = 'This passenger is predicted to be: **survived**'
prediction_state.markdown(msg)