Skip to content

Instantly share code, notes, and snippets.

@notha99y
Created December 21, 2018 10:25
Show Gist options
  • Save notha99y/a47f8fc7270bec09e34cf973b22534bd to your computer and use it in GitHub Desktop.
Save notha99y/a47f8fc7270bec09e34cf973b22534bd to your computer and use it in GitHub Desktop.
def simple_preprocessing(dataframe, train=True):
le = LabelEncoder()
X = dataframe.drop(['PassengerId', 'Cabin', 'Name', 'Ticket'], axis=1)
X['Age'] = X['Age'].fillna(value=X['Age'].mode()[0])
X['Embarked'] = le.fit_transform(X['Embarked'].fillna(value=X['Embarked'].mode()[0]))
X['Sex'] = np.where(X['Sex'] == 'male', 1, 0)
if train:
X = X.drop(['Survived'], axis=1)
y = np.where(dataframe['Survived'] == 1, 'Alive', 'Dead')
y = pd.get_dummies(y, columns=['Survived'])
return X, y
else:
return X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment