Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<prepare_x_and_y>
%matplotlib inline
X_train = train_data.copy()
y_train = train_data['label']
del X_train['label']
X_val = val_data.copy()
y_val = val_data['label']
del X_val['label']
X_test = test_data.copy()
del X_test['id']
y_train = to_categorical(y_train, num_classes = 10)
 y_val = to_categorical(y_val, num_classes = 10 )<data_type_conversions>
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv' )
X_train = X_train.astype('float32')/255
X_val = X_val.astype('float32')/255
X_test = X_test.astype('float32')/255<split>
def transform_df(df):
return df
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size = 0.1, random_state=2020 )<choose_model_class>
train_df[['Sex', 'Survived']].groupby(['Sex'], as_index=False ).mean().sort_values(by='Survived', ascending=False )
model = Sequential()
model.add(Conv2D(filters=64, kernel_size=3, padding='same', activation='relu', input_shape=(28,28,1)))
 model.add(Conv2D(filters=128, kernel_size=3, padding='same', activation='relu'))
model.add(MaxPool2D(pool_size=2))
model.add(Conv2D(filters=128, kernel_size=3, padding='same', activation='relu'))
model.add(Conv2D(filters=256, kernel_size=3, padding='same', activation='relu'))
model.add(MaxPool2D(pool_size=2, padding='same'))
model.add(Conv2D(filters=256, kernel_size=3, padding='same', activation='relu'))
model.add(Conv2D(filters=512, kernel_size=3, padding='same', activation='relu'))
model.add(MaxPool2D(pool_size=2, padding='same'))
model.add(Dropout(0.5))
model.add(Flatten())
 model.add(Dense(512, activation='relu'))
model.add(Dense(10, activation='softmax'))<choose_model_class>
train_df[['Pclass', 'Survived']].groupby(['Pclass'], as_index=False ).mean().sort_values(by='Survived', ascending=False )
optimizer = RMSprop(lr=0.001 )<choose_model_class>
train_df[['Embarked','Survived']].groupby(['Embarked'], as_index=False ).mean().sort_values(by='Survived', ascending=False )
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['acc'] )<define_variables>
train_df.drop(['PassengerId','Ticket', 'Cabin'], 1, inplace=True)
 train_df.head()
epochs = 50
batch_size = 512<train_model>
test_df.drop(['PassengerId', 'Ticket', 'Cabin'], 1, inplace=True)
 test_df.head()
datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.10,
width_shift_range=0.15,
height_shift_range=0.15,
horizontal_flip=False,
vertical_flip=False)
 datagen.fit(X_train )<train_model>
print('Count:', train_df.shape[0])
 print('Null age count:', train_df['Age'].isnull().sum())
 print(train_df['Age'].isnull().sum() / train_df.shape[0] * 100,'% of ages are NAN', sep="" )
history = model.fit(datagen.flow(X_train, y_train, batch_size=batch_size),
epochs=epochs,
validation_data=(X_val,y_val),
steps_per_epoch=X_train.shape[0] // batch_size )<predict_on_test>
rand_ages = np.random.randint(age_mean - age_std, age_mean + age_std, age_nan_count )
y_test = model.predict(X_test )<prepare_output>
print('Now there are {} null values!'.format(train_df['Age'].isnull().sum()))
y_test_classes = np.argmax(y_test, axis = 1 )<save_to_csv>
train_df['AgeCategorical'] = pd.cut(train_df['Age'], bins=8)
 train_df['AgeCategorical'].value_counts()
relation_age_survived = train_df[['AgeCategorical', 'Survived']].groupby('AgeCategorical', as_index=False ).mean()
output = pd.DataFrame({'id': samp_subm['id'],
'label': y_test_classes})
 output.to_csv('submission.csv', index=False )<drop_column>
train_df.loc[train_df['Age'] < 10.367, 'Age'] = 0
train_df.loc[(train_df['Age'] >= 10.367)&(train_df['Age'] < 20.315), 'Age'] = 1
train_df.loc[(train_df['Age'] >= 20.315)&(train_df['Age'] < 30.263), 'Age'] = 2
train_df.loc[(train_df['Age'] >= 30.263)&(train_df['Age'] < 40.21), 'Age'] = 3
train_df.loc[(train_df['Age'] >= 40.21)&(train_df['Age'] < 50.157), 'Age'] = 4
train_df.loc[(train_df['Age'] >= 50.157)&(train_df['Age'] < 60.105), 'Age'] = 5
train_df.loc[(train_df['Age'] >= 60.105)&(train_df['Age'] < 70.0525), 'Age'] = 6
train_df.loc[(train_df['Age'] >= 70.0525)&(train_df['Age'] <= 80), 'Age'] = 7
train_df['Age'] = train_df['Age'].astype(int)
 train_df.drop('AgeCategorical', 1, inplace=True)
 train_df.head()
del model<import_modules>
train_df['Name'] = train_df.Name.str.extract('([A-Za-z]+)\.', expand=False )
import random
import keras
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.patches as mpatches
from skimage.filters import threshold_otsu
from skimage.segmentation import clear_border
from skimage.measure import label, regionprops
from skimage.morphology import closing, square
from skimage.color import label2rgb
from math import sqrt
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
import itertools
from keras.utils.np_utils import to_categorical
from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D, Input, BatchNormalization
from keras.optimizers import RMSprop, Adam
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau
from keras.callbacks import LearningRateScheduler
from keras.callbacks import ModelCheckpoint<drop_column>
train_df['Name'].value_counts()
keras.backend.clear_session()<load_from_csv>
train_df['Name'] = train_df['Name'].replace(['Capt', 'Dr','Rev','Mile','Col','Major','Countess','Jonkheer','Mme',\
'Don', 'Ms','Sir','Capt','Lady', 'Mlle'], 'Low Appearence' )
train = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv')
 test = pd.read_csv('/kaggle/input/Kannada-MNIST/test.csv')
 y_train = train['label']
X = train.drop(['label'],axis=1)
 del train
Id = test['id']
test = test.drop(['id'],axis=1 )<count_unique_values>
train_df['Name'].value_counts()
first_1000 = y_train[:10]
np.unique(first_1000, return_counts=True )<create_dataframe>
train_df[['Name','Survived']].groupby('Name', as_index=False ).mean().sort_values(by='Survived', ascending=False )
labels =[]
frequencies = []
for i in range(len(y_train)) :
lab, freq = str(y_train[i]), len([n for n in X.values[i] if n > 0])
 labels.append(lab)
 frequencies.append(freq)
 data = {'Labels':labels, 'Frequencies':frequencies}
df = pd.DataFrame(data )<groupby>
train_df['Name'] = train_df['Name'].map({'Mr':0, 'Low Appearence': 1, 'Master': 2, 'Miss': 3, 'Mrs': 4} )
df.groupby('Labels' ).mean()<prepare_x_and_y>
train_df['Family'] = train_df['SibSp'] + train_df['Parch']
train_df.drop(['SibSp','Parch'], 1, inplace=True )
test_y = df['Labels']
test_x = df
test_x.drop('Labels', axis =1, inplace = True)
<split>
family_survived_relation = train_df[['Family','Survived']].groupby('Family', as_index=False ).mean()
X_train1, X_val1, y_train1, y_val1 = train_test_split(test_x, test_y, test_size=0.1, random_state=1337 )<train_model>
family_survived_relation.sort_values(by='Survived', ascending=False )
clf_rfc = RandomForestClassifier(n_estimators = 100)
 clf_rfc.fit(X_train1,y_train1)
 accuracy_score(clf_rfc.predict(X_val1), y_val1)
<train_model>
train_df['Alone'] = train_df['Family'].copy()
train_df['Alone'].loc[train_df['Alone'] == 0] = -1
train_df['Alone'].loc[train_df['Alone'] > 0] = 0
train_df['Alone'].loc[train_df['Alone'] == -1] = 1
X = X.values.reshape(X.shape[0], 28, 28,1)
 test = test.values.reshape(test.shape[0], 28, 28,1)
 X = X / 255.0
test = test / 255.0<init_hyperparams>
relation_alone_survived = train_df[['Alone','Survived']].groupby('Alone', as_index=False ).mean() \ 
.sort_values(by='Alone', ascending=False )
datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.25,
width_shift_range=0.25,
height_shift_range=0.25,
horizontal_flip=False,
vertical_flip=False)
 valid_datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.25,
width_shift_range=0.25,
height_shift_range=0.25,
horizontal_flip=False,
vertical_flip=False )<categorify>
train_df['Alone'].value_counts()
y_train = to_categorical(y_train,num_classes=10 )<choose_model_class>
train_df.drop('Alone', 1, inplace=True)
 train_df.head()
learning_rate_reduction = ReduceLROnPlateau(monitor='accuracy',
patience=3,
verbose=10,
factor=0.33,
min_lr=0.00001)
 checkpoint=ModelCheckpoint('bestweights.md5', monitor='accuracy', verbose=1, save_best_only=True)
<define_variables>
print('There are {} null values in Embarked'.format(train_df['Embarked'].isnull().sum()))
train_df['Embarked'].value_counts()
epochs = 40
initial_learningrate=2e-3
batch_size = 100<split>
embarked_most_common = train_df['Embarked'].value_counts().idxmax()
train_df['Embarked'].fillna(embarked_most_common, inplace=True)
 print('Now there are {} null values in Embarked'.format(train_df['Embarked'].isnull().sum()))
X_train, X_val, y_train, y_val = train_test_split(X, y_train, test_size=0.1, random_state=1 )<choose_model_class>
train_df[['Embarked','Survived']].groupby('Embarked', as_index=False ).mean().sort_values(by='Survived', ascending=False )
def build_model1(input_shape=(28, 28, 1), classes = 10):
activation = 'relu'
padding = 'same'
gamma_initializer = 'uniform'
input_layer = Input(shape=input_shape)
 hidden=Conv2D(32,(11,11), strides=1, padding =padding, activation = activation, name = 'conv1' )(input_layer)
 hidden=BatchNormalization()(hidden)
 hidden=Conv2D(32,(11,11), strides=1, padding =padding, activation = activation, name = 'conv2' )(hidden)
 hidden=BatchNormalization()(hidden)
 hidden=Conv2D(32,(5,5), strides=1, padding =padding, activation = activation, name = 'conv3' )(hidden)
 hidden=BatchNormalization()(hidden)
 hidden=MaxPool2D()(hidden)
 hidden=Dropout(0.35 )(hidden)
 hidden=Conv2D(64,(3,3), strides=1, padding =padding, activation = activation, name = 'conv4' )(input_layer)
 hidden=BatchNormalization()(hidden)
 hidden=Conv2D(64,(3,3), strides=1, padding =padding, activation = activation, name = 'conv5' )(hidden)
 hidden=BatchNormalization()(hidden)
 hidden=Conv2D(64,(5,5), strides=1, padding =padding, activation = activation, name = 'conv6' )(hidden)
 hidden=BatchNormalization()(hidden)
 hidden=MaxPool2D()(hidden)
 hidden=Dropout(0.3 )(hidden)
 hidden=Flatten()(hidden)
 hidden=Dense(250,activation = activation, name="Dense1" )(hidden)
 hidden=Dropout(0.3 )(hidden)
 output = Dense(classes, activation = "softmax" )(hidden)
 model = Model(inputs=input_layer, outputs=output)
 return model
optimizer = Adam(learning_rate=initial_learningrate, beta_1=0.9, beta_2=0.999, amsgrad=False )<choose_model_class>
train_df['Embarked'] = train_df['Embarked'].map({'S': 0, 'Q': 1, 'C': 2} ).astype(int )
model = build_model1(input_shape=(28, 28, 1), classes = 10)
 model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )<train_model>
test_df['Fare'].fillna(test_df['Fare'].dropna().median() , inplace=True )
datagen.fit(X_train)
 datagen.fit(X_val)
 callbacks = [checkpoint,learning_rate_reduction]
history = model.fit_generator(datagen.flow(X_train,y_train, batch_size=batch_size),
epochs = epochs,
validation_data=valid_datagen.flow(X_val,y_val),
verbose = 1,
callbacks = callbacks)
<prepare_output>
train_df['FareCategorical'] = pd.qcut(train_df['Fare'], 4)
 train_df['FareCategorical'].value_counts()
y_pre_test=model.predict(X_val)
 y_pre_test=np.argmax(y_pre_test,axis=1)
 y_test=np.argmax(y_val,axis=1)
 conf=confusion_matrix(y_test,y_pre_test)
 conf=pd.DataFrame(conf,index=range(0,10),columns=range(0,10)) 
<train_model>
train_df[['FareCategorical','Survived']].groupby('FareCategorical', as_index=False ).mean().\
sort_values(by='Survived',ascending=False )
print('out of {} samples, we got {} incorrect'.format(len(X_train), round(len(X_train)- history.history['accuracy'][-1] * len(X_train))))<predict_on_test>
train_df.loc[train_df['Fare'] < 7.91, 'Fare'] = 0
train_df.loc[(train_df['Fare'] >= 7.91)&(train_df['Fare'] < 14.454), 'Fare'] = 1
train_df.loc[(train_df['Fare'] >= 14.454)&(train_df['Fare'] < 31), 'Fare'] = 2
train_df.loc[train_df['Fare'] >= 31, 'Fare'] = 3
train_df['Fare'] = train_df['Fare'].astype(int)
 train_df.drop('FareCategorical', 1, inplace=True )
Y_pred = model.predict(X_val)
 Y_pred_classes = np.argmax(Y_pred,axis = 1)
 Y_true = np.argmax(y_val,axis = 1)
 errors =(Y_pred_classes - Y_true != 0)
 Y_pred_classes_errors = Y_pred_classes[errors]
Y_pred_errors = Y_pred[errors]
Y_true_errors = Y_true[errors]
X_val_errors = X_val[errors]
def display_errors(errors_index,img_errors,pred_errors, obs_errors):

 n = 0
nrows = 3
ncols = 3
fig, ax = plt.subplots(nrows,ncols,sharex=True,sharey=True,figsize =(10,10))
fig.tight_layout()
for row in range(nrows):
for col in range(ncols):
error = errors_index[n]
ax[row,col].imshow(( img_errors[error] ).reshape(( 28,28)))
 ax[row,col].set_title("Predicted label :{}
True label :{}".format(pred_errors[error],obs_errors[error]))
n += 1
Y_pred_errors_prob = np.max(Y_pred_errors,axis = 1)
 true_prob_errors = np.diagonal(np.take(Y_pred_errors, Y_true_errors, axis=1))
delta_pred_true_errors = Y_pred_errors_prob - true_prob_errors
sorted_dela_errors = np.argsort(delta_pred_true_errors)
 most_important_errors = sorted_dela_errors[-18:-9]
display_errors(most_important_errors, X_val_errors, Y_pred_classes_errors, Y_true_errors)
<predict_on_test>
train_df['Sex'] = train_df['Sex'].map({'male': 0, 'female': 1} )
predictions = model.predict(test )<prepare_output>
def transform_df(df):
df.drop(['PassengerId','Ticket', 'Cabin'], 1, inplace=True)
 age_mean = df['Age'].mean()
age_std = df['Age'].std()
age_nan_count = df['Age'].isnull().sum()
rand_ages = np.random.randint(age_mean - age_std, age_mean + age_std, age_nan_count)
 df['Age'][np.isnan(df['Age'])] = rand_ages
df.loc[df['Age'] < 10.367, 'Age'] = 0
df.loc[(df['Age'] >= 10.367)&(df['Age'] < 20.315), 'Age'] = 1
df.loc[(df['Age'] >= 20.315)&(df['Age'] < 30.263), 'Age'] = 2
df.loc[(df['Age'] >= 30.263)&(df['Age'] < 40.21), 'Age'] = 3
df.loc[(df['Age'] >= 40.21)&(df['Age'] < 50.157), 'Age'] = 4
df.loc[(df['Age'] >= 50.157)&(df['Age'] < 60.105), 'Age'] = 5
df.loc[(df['Age'] >= 60.105)&(df['Age'] < 70.0525), 'Age'] = 6
df.loc[(df['Age'] >= 70.0525)&(df['Age'] <= 80), 'Age'] = 7
df['Age'] = df['Age'].astype(int)
 df['Name'] = df.Name.str.extract('([A-Za-z]+)\.', expand=False)
 df['Name'] = df['Name'].replace(['Capt', 'Dr','Rev','Mile','Col','Major','Countess','Jonkheer','Mme',\
'Don', 'Ms','Sir','Capt','Lady', 'Mlle'], 'Low Appearence')
 df['Name'] = df['Name'].map({'Mr':0, 'Low Appearence': 1, 'Master': 2, 'Miss': 3, 'Mrs': 4})
 df['Name'] = df['Name'].fillna(4 ).astype(int)
 df['Family'] = df['SibSp'] + df['Parch']
df.drop(['SibSp','Parch'], 1, inplace=True)

embarked_most_common = df['Embarked'].value_counts().idxmax()
df['Embarked'].fillna(embarked_most_common, inplace=True)
 df['Embarked'] = df['Embarked'].map({'S': 0, 'Q': 1, 'C': 2} ).astype(int)
 df['Fare'].fillna(df['Fare'].dropna().median() , inplace=True)
 df.loc[df['Fare'] < 7.91, 'Fare'] = 0
df.loc[(df['Fare'] >= 7.91)&(df['Fare'] < 14.454), 'Fare'] = 1
df.loc[(df['Fare'] >= 14.454)&(df['Fare'] < 31), 'Fare'] = 2
df.loc[df['Fare'] >= 31, 'Fare'] = 3
df['Fare'] = df['Fare'].astype(int)
 df['Sex'] = df['Sex'].map({'male': 0, 'female': 1})
 return df
predictions = predictions.argmax(axis = -1)
 predictions<save_to_csv>
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv' )
submission = pd.DataFrame({ 'id': Id,
'label': predictions })
 submission.to_csv(path_or_buf ="submission.csv", index=False )<import_modules>
train_df = transform_df(train_df)
 test_df = transform_df(test_df )
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Conv2D,MaxPool2D,Dropout,Dense,Flatten,Activation,BatchNormalization
from keras.models import Sequential
from keras.optimizers import Adam
from keras.losses import categorical_crossentropy
from sklearn.metrics import classification_report
from IPython.display import FileLink<import_modules>
from sklearn.model_selection import cross_val_score
from sklearn.dummy import DummyClassifier
from sklearn.naive_bayes import GaussianNB, MultinomialNB
from sklearn.svm import SVC, LinearSVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.cluster import KMeans
from xgboost import XGBClassifier
tensorflow_backend._get_available_gpus()<load_from_csv>
X_train = train_df.drop('Survived', 1)
 y_train = train_df['Survived']
cv_value = 4
model_results = {}
X_train.head()
train=pd.read_csv(r'.. /input/Kannada-MNIST/train.csv')
 test=pd.read_csv(r'.. /input/Kannada-MNIST/test.csv')
 val=pd.read_csv(r'.. /input/Kannada-MNIST/Dig-MNIST.csv' )<train_model>
X_train = X_train.as_matrix()
y_train = y_train.as_matrix()
test_df = test_df.as_matrix()
data=train.iloc[:,1:].values
data=data.reshape(-1,28,28,1)/255
print('Total training data shape:',data.shape )<categorify>
clf_dummy = DummyClassifier(strategy='most_frequent')
 scores = cross_val_score(clf_dummy, X=X_train, y=y_train, cv=cv_value)
 model_results['DummyClassifier'] = np.mean(scores)
 np.mean(scores )
labels=pd.get_dummies(train.iloc[:,0] ).values<prepare_x_and_y>
clf_m_naive_bayes = MultinomialNB()
scores = cross_val_score(clf_m_naive_bayes, X=X_train, y=y_train, cv=cv_value)
 model_results['MultinomialNB'] = np.mean(scores)
 np.mean(scores )
x_val=val.iloc[:,1:].values
x_val=x_val.reshape(-1,28,28,1)/255<prepare_x_and_y>
clf_svc = SVC()
scores = cross_val_score(clf_svc, X=X_train, y=y_train, cv=cv_value)
 model_results['SVC'] = np.mean(scores)
 np.mean(scores )
y_val=pd.get_dummies(val.iloc[:,0] ).values<create_dataframe>
clf_forest = RandomForestClassifier(n_estimators=200, max_depth=4, n_jobs=-1)
 scores = cross_val_score(clf_forest, X=X_train, y=y_train, cv=cv_value)
 model_results['RandomForest'] = np.mean(scores)
 np.mean(scores )
aug_data=ImageDataGenerator(
 rotation_range=10,
zoom_range = 0.10,
width_shift_range=0.1,
height_shift_range=0.1 )<concatenate>
clf_ada = AdaBoostClassifier()
scores = cross_val_score(clf_ada, X=X_train, y=y_train, cv=cv_value)
 model_results['AdaBoost'] = np.mean(scores)
 np.mean(scores )
generator=aug_data.flow(data,labels,batch_size=64 )<choose_model_class>
clf_knn = KNeighborsClassifier(n_neighbors=5)
 scores = cross_val_score(clf_knn, X=X_train, y=y_train, cv=cv_value)
 model_results['KNN'] = np.mean(scores)
 np.mean(scores )
def create_model() :
model=Sequential()
model.add(Conv2D(64,(3,3),input_shape=(28,28,1),activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(64,(3,3),activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(64,(5,5),strides=(2,2),padding='same',activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.4))
model.add(Conv2D(128,(3,3),activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(128,(3,3),activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(128,(5,5),strides=(2,2),padding='same',activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.4))
model.add(Conv2D(256,(3,3),activation='relu'))
model.add(BatchNormalization())
 model.add(Flatten())
 model.add(Dense(1024,activation='relu'))
model.add(Dropout(0.4))
model.add(Dense(10,activation='softmax'))
model.compile(optimizer='adam',loss=categorical_crossentropy,metrics=['accuracy'])
 return model<choose_model_class>
clf_nn = MLPClassifier(hidden_layer_sizes=(5,3), max_iter=300, learning_rate_init=0.01, random_state=101)
 scores = cross_val_score(clf_nn, X=X_train, y=y_train, cv=cv_value)
 model_results['Neural Network'] = np.mean(scores)
 np.mean(scores )
model=create_model()<train_model>
clf_xgb = XGBClassifier(learning_rate=0.01)
 scores = cross_val_score(clf_xgb, X=X_train, y=y_train, cv=cv_value)
 model_results['XGBoost'] = np.mean(scores)
 np.mean(scores )
history=model.fit_generator(generator,epochs=50,validation_data=(x_val,y_val),steps_per_epoch=data.shape[0]//64,shuffle=True )<concatenate>
results = pd.DataFrame(list(model_results.items()), columns=['Model','Score'])
 results.sort_values(by='Score', ascending=False )
data=np.concatenate(( data,x_val))
labels=np.concatenate(( labels,y_val))<concatenate>
models_list = [clf_xgb, clf_forest, clf_nn, clf_svc, clf_knn]
for model in models_list:
model.fit(X_train, y_train )
generator=aug_data.flow(data,labels,batch_size=64 )<choose_model_class>
original_test_df = pd.read_csv('.. /input/test.csv')
 passengers_id = original_test_df['PassengerId']
len(passengers_id )
model=create_model()<train_model>
y_predict = []
y = []
for model in models_list:
y.append(model.predict(test_df[:]))
y = np.array(y)
 print(y.shape )
history=model.fit_generator(generator,epochs=50,validation_data=(x_val,y_val),steps_per_epoch=data.shape[0]//64,shuffle=True )<compute_test_metric>
print(y[:,0], Counter(y[:,0] ).most_common(1))
print(y[:,1], Counter(y[:,1] ).most_common(1))
print(classification_report(np.argmax(y_val,1),np.argmax(model.predict(x_val),1)) )<define_variables>
submission = pd.DataFrame(data=y_predict, columns=['PassengerId', 'Survived'])
 submission.head()
test_id=test['id'].values<drop_column>
submission.to_csv('submission.csv', header=True, index=False )