Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from utils import PrepProcesor, columns
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
import joblib
|
7 |
+
|
8 |
+
model = joblib.load('xgbpipe.joblib')
|
9 |
+
st.title('Will you survive if you were among Titanic passengers or not :ship:')
|
10 |
+
# PassengerId,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
|
11 |
+
passengerid = st.text_input("Input Passenger ID", '8585')
|
12 |
+
pclass = st.selectbox("Choose class", [1,2,3])
|
13 |
+
name = st.text_input("Input Passenger Name", 'Soheil Tehranipour')
|
14 |
+
sex = st.select_slider("Choose sex", ['male','female'])
|
15 |
+
age = st.slider("Choose age",0,100)
|
16 |
+
sibsp = st.slider("Choose siblings",0,10)
|
17 |
+
parch = st.slider("Choose parch",0,10)
|
18 |
+
ticket = st.text_input("Input Ticket Number", "8585")
|
19 |
+
fare = st.number_input("Input Fare Price", 0,1000)
|
20 |
+
cabin = st.text_input("Input Cabin", "C52")
|
21 |
+
embarked = st.select_slider("Did they Embark?", ['S','C','Q'])
|
22 |
+
|
23 |
+
def predict():
|
24 |
+
row = np.array([passengerid,pclass,name,sex,age,sibsp,parch,ticket,fare,cabin,embarked])
|
25 |
+
X = pd.DataFrame([row], columns = columns)
|
26 |
+
prediction = model.predict(X)
|
27 |
+
if prediction[0] == 1:
|
28 |
+
st.success('Passenger Survived :thumbsup:')
|
29 |
+
else:
|
30 |
+
st.error('Passenger did not Survive :thumbsdown:')
|
31 |
+
|
32 |
+
trigger = st.button('Predict', on_click=predict)
|
33 |
+
|
utils.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sklearn.base import BaseEstimator, TransformerMixin
|
2 |
+
from sklearn.impute import SimpleImputer
|
3 |
+
import re
|
4 |
+
|
5 |
+
class PrepProcesor(BaseEstimator, TransformerMixin):
|
6 |
+
def fit(self, X, y=None):
|
7 |
+
self.ageImputer = SimpleImputer()
|
8 |
+
self.ageImputer.fit(X[['Age']])
|
9 |
+
return self
|
10 |
+
|
11 |
+
def transform(self, X, y=None):
|
12 |
+
X['Age'] = self.ageImputer.transform(X[['Age']])
|
13 |
+
X['CabinClass'] = X['Cabin'].fillna('M').apply(lambda x: str(x).replace(" ", "")).apply(lambda x: re.sub(r'[^a-zA-Z]', '', x))
|
14 |
+
X['CabinNumber'] = X['Cabin'].fillna('M').apply(lambda x: str(x).replace(" ", "")).apply(lambda x: re.sub(r'[^0-9]', '', x)).replace('', 0)
|
15 |
+
X['Embarked'] = X['Embarked'].fillna('M')
|
16 |
+
X = X.drop(['PassengerId', 'Name', 'Ticket','Cabin'], axis=1)
|
17 |
+
return X
|
18 |
+
|
19 |
+
columns = ['PassengerId', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp', 'Parch','Ticket', 'Fare', 'Cabin', 'Embarked']
|