Kaggle competition: Titanic - Machine Learning from Disaster
test_df = pd.read_csv('.. /input/test.csv')
 proc_test_df = generate_df(test_df.copy() )<create_dataframe>
%matplotlib inline
test_full = pd.read_csv(".. /input/titanic/test.csv",index_col="PassengerId")
 train_full = pd.read_csv(".. /input/titanic/train.csv",index_col = "PassengerId")
 target = train_full.Survived
train = train_full.drop(['Name','Survived'],axis=1)
 test = test_full.drop(['Name'],axis=1)
 sns.pairplot(train_full)
data_test = MultiChannelImageList.from_df(df=proc_test_df,path='.. /input/test/')
 learn.data.add_test(data_test )<predict_on_test>
[(col,train[col].nunique())for col in train.select_dtypes('object')]
preds, _ = learn.get_preds(DatasetType.Test )<prepare_output>
train.isnull().sum()
preds_ = preds.argmax(dim=-1 )<load_from_csv>
train.isnull().sum()
submission_df = pd.read_csv('.. /input/sample_submission.csv' )<data_type_conversions>
imputer = SimpleImputer(missing_values=np.nan,strategy='most_frequent',add_indicator=True)
 train_preprocessed = pd.DataFrame(imputer.fit_transform(train),columns=[col for col in train] + ['Age_na','Cabin_na','Embarked_na'],index = train.index)
 test_preprocessed = pd.DataFrame(imputer.transform(test),columns=[col for col in test] + ['Age_na','Cabin_na','Embarked_na'],index = test.index)
 train_preprocessed
submission_df.sirna = preds_.numpy().astype(int)
 submission_df.head(10 )<save_to_csv>
LE = LabelEncoder()
for col in [col for col in train.select_dtypes('object')]:
train_preprocessed[col] = LE.fit_transform(train_preprocessed[col])
 test_preprocessed[col] = LE.fit_transform(test_preprocessed[col])
 train_preprocessed = train_preprocessed.astype('float64')
 test_preprocessed = test_preprocessed.astype('float64')
 train_preprocessed
submission_df.to_csv('submission.csv',index=False )<import_modules>
X_train,X_test,y_train,y_test = train_test_split(train_preprocessed,target,test_size=0.2)
 display(X_train )
import os
import time
import numpy as np
import pandas as pd
from tqdm import tqdm
import math
from sklearn.model_selection import train_test_split
from sklearn import metrics
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.layers import Dense, Input, CuDNNLSTM, Embedding, Dropout, Activation, CuDNNGRU, Conv1D
from keras.layers import Bidirectional, GlobalMaxPool1D
from keras.optimizers import Adam
from keras.models import Model
from keras import backend as K
from keras.engine.topology import Layer
from keras import initializers, regularizers, constraints, optimizers, layers<load_from_csv>
model = XGBClassifier(n_estimators=90,n_jobs=5,random_state=0)
 model.fit(X_train,y_train)
 preds = model.predict(X_test)
 'Accuracy Score is %f' % accuracy_score(y_pred=preds,y_true=y_test )
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv")
 print("Train shape : ",train_df.shape)
 print("Test shape : ",test_df.shape )<split>
mean_absolute_error(preds,y_test )
train_df, val_df = train_test_split(train_df, test_size=0.08, random_state=2018)
 embed_size = 300
max_features = 95000
maxlen = 70
train_X = train_df["question_text"].fillna("_
val_X = val_df["question_text"].fillna("_
test_X = test_df["question_text"].fillna("_
tokenizer = Tokenizer(num_words=max_features)
 tokenizer.fit_on_texts(list(train_X))
train_X = tokenizer.texts_to_sequences(train_X)
 val_X = tokenizer.texts_to_sequences(val_X)
 test_X = tokenizer.texts_to_sequences(test_X)
 train_X = pad_sequences(train_X, maxlen=maxlen)
 val_X = pad_sequences(val_X, maxlen=maxlen)
 test_X = pad_sequences(test_X, maxlen=maxlen)
 train_y = train_df['target'].values
val_y = val_df['target'].values<randomize_order>
f1_score(preds,y_test )
<statistical_test><EOS> 
submission_preds = model.predict(test_preprocessed)
 output = pd.read_csv(".. /input/titanic/gender_submission.csv")
 output.Survived = submission_preds
output.to_csv('submission.csv',index=False)
 output.head()