Kaggle competition: Titanic - Machine Learning from Disaster
combined_data = pd.concat([train[['posts']], test[['posts']]] )<categorify>
train = pd.read_csv("/kaggle/input/titanic/train.csv")
 test = pd.read_csv("/kaggle/input/titanic/test.csv")
 train
def clean_text(text):

 text = re.sub('https?\S+', 'URL', text)
 text = re.sub('[0-9]+','', text)
 text = re.sub('@[a-z0-9]+', 'user', text)
 text = re.sub('\|\|\|', ' ', text)
 text = re.sub('[%s]*' % string.punctuation, '',text)
 text = text.lower()
tokenized_text = word_tokenize(text)
 lemmatizer = WordNetLemmatizer()
text = ' '.join([lemmatizer.lemmatize(a)for a in tokenized_text])
 return text<feature_engineering>
submission=pd.read_csv("/kaggle/input/titanic/gender_submission.csv")
 print(train.columns)
 print(test.shape)
 train.drop(['Name', 'Ticket', 'Fare', 'Embarked'], axis=1, inplace=True)
 test.drop(['Name', 'Ticket', 'Fare', 'Embarked'], axis=1, inplace=True)
 train['Sex'].replace({'male':0, 'female':1}, inplace=True)
 test['Sex'].replace({'male':0, 'female':1}, inplace=True)
 train.drop(['Cabin'], axis=1,inplace=True)
 test.drop(['Cabin'], axis=1,inplace=True )
combined_data['clean_posts'] = combined_data['posts'].apply(clean_text )<feature_engineering>
X = train.drop(['Survived', 'PassengerId'], axis=1)
 y = train['Survived']
X_test = test.drop(['PassengerId'], axis=1)
vectorizer = TfidfVectorizer()
combined_X = vectorizer.fit_transform(combined_data['clean_posts'] )<feature_engineering>
model=RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)
 model.fit(X,y)
 prediction=model.predict(X_test)
<split><EOS> 
result=pd.DataFrame()
result['PassengerId'] = test['PassengerId']
result['Survived']=prediction
result.to_csv("submission.csv", index=False )