Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- __pycache__/utils.cpython-312.pyc +0 -0
- app.py +50 -0
- ru.txt +5 -0
- utils.py +19 -0
- xgbpipe.joblib +3 -0
__pycache__/utils.cpython-312.pyc
ADDED
Binary file (2.57 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import joblib
|
5 |
+
from sklearn.base import BaseEstimator, TransformerMixin
|
6 |
+
from sklearn.impute import SimpleImputer
|
7 |
+
import re
|
8 |
+
|
9 |
+
class PrepProcesor(BaseEstimator, TransformerMixin):
|
10 |
+
def fit(self, X, y=None):
|
11 |
+
self.ageImputer = SimpleImputer()
|
12 |
+
self.ageImputer.fit(X[['Age']])
|
13 |
+
return self
|
14 |
+
|
15 |
+
def transform(self, X, y=None):
|
16 |
+
X['Age'] = self.ageImputer.transform(X[['Age']])
|
17 |
+
X['CabinClass'] = X['Cabin'].fillna('M').apply(lambda x: str(x).replace(" ", "")).apply(lambda x: re.sub(r'[^a-zA-Z]', '', x))
|
18 |
+
X['CabinNumber'] = X['Cabin'].fillna('M').apply(lambda x: str(x).replace(" ", "")).apply(lambda x: re.sub(r'[^0-9]', '', x)).replace('', 0)
|
19 |
+
X['Embarked'] = X['Embarked'].fillna('M')
|
20 |
+
X = X.drop(['PassengerId', 'Name', 'Ticket','Cabin'], axis=1)
|
21 |
+
return X
|
22 |
+
|
23 |
+
columns = ['PassengerId', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp', 'Parch','Ticket', 'Fare', 'Cabin', 'Embarked']
|
24 |
+
|
25 |
+
model = joblib.load('xgbpipe.joblib')
|
26 |
+
st.title('Will you survive if you were among Titanic passengers or not :ship:')
|
27 |
+
# PassengerId,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
|
28 |
+
passengerid = st.text_input("Input Passenger ID", '0000')
|
29 |
+
pclass = st.selectbox("Choose class", [1,2,3])
|
30 |
+
name = st.text_input("Input Passenger Name", 'radman omrani')
|
31 |
+
sex = st.selectbox("Choose sex", ['male','female'])
|
32 |
+
age = st.slider("Choose age",0,100)
|
33 |
+
sibsp = st.slider("Choose siblings",0,10)
|
34 |
+
parch = st.slider("Choose parch",0,10)
|
35 |
+
ticket = st.text_input("Input Ticket Number", "0000")
|
36 |
+
fare = st.number_input("Input Fare Price", 0,1000)
|
37 |
+
cabin = st.text_input("Input Cabin", "C52")
|
38 |
+
embarked = st.selectbox("Did they Embark?", ['S','C','Q'])
|
39 |
+
|
40 |
+
def predict():
|
41 |
+
row = np.array([passengerid,pclass,name,sex,age,sibsp,parch,ticket,fare,cabin,embarked])
|
42 |
+
X = pd.DataFrame([row], columns = columns)
|
43 |
+
prediction = model.predict(X)
|
44 |
+
if prediction[0] == 1:
|
45 |
+
st.success('Passenger Survived :thumbsup:')
|
46 |
+
else:
|
47 |
+
st.error('Passenger did not Survive :thumbsdown:')
|
48 |
+
|
49 |
+
trigger = st.button('Will i survude?', on_click=predict)
|
50 |
+
|
ru.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
seaborn
|
3 |
+
scikit-learn
|
4 |
+
xgboost==1.5.0
|
5 |
+
streamlit==1.11.1
|
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']
|
xgbpipe.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8117b0f8e5f9c01468c6e2bdf6e6115f00cdaf2ad407244292a88dfdd72a9807
|
3 |
+
size 275462
|