Spaces:
Sleeping
Sleeping
Delete utils.py
Browse files
utils.py
DELETED
@@ -1,19 +0,0 @@
|
|
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']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|