Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<prepare_output>
%matplotlib inline
GradientBoostingClassifier, ExtraTreesClassifier)
 warnings.filterwarnings('ignore')
 df_train=pd.read_csv('.. /input/train.csv',sep=',')
 df_test=pd.read_csv('.. /input/test.csv',sep=',')
 df_data = df_train.append(df_test)
 PassengerId = df_test['PassengerId']
Submission=pd.DataFrame()
Submission['PassengerId'] = df_test['PassengerId']
print('Components imported' )
outlier_id = pd.DataFrame(df_outlier_prob.sort_values(by='target',ascending = False ).head(25000)['card_id'] )<load_from_csv>
df_data["Title"] = df_data.Name.str.extract('([A-Za-z]+)\.', expand=False)
 df_data["Title"] = df_data["Title"].replace('Mlle', 'Miss')
 df_data["Title"] = df_data["Title"].replace('Master', 'Master')
 df_data["Title"] = df_data["Title"].replace(['Mme', 'Dona', 'Ms'], 'Mrs')
 df_data["Title"] = df_data["Title"].replace(['Jonkheer','Don'],'Mr')
 df_data["Title"] = df_data["Title"].replace(['Capt','Major', 'Col','Rev','Dr'], 'Millitary')
 df_data["Title"] = df_data["Title"].replace(['Lady', 'Countess','Sir'], 'Honor')
 df_train["Title"] = df_data['Title'][:891]
df_test["Title"] = df_data['Title'][891:]
titledummies=pd.get_dummies(df_train[['Title']], prefix_sep='_')
 df_train = pd.concat([df_train, titledummies], axis=1)
 ttitledummies=pd.get_dummies(df_test[['Title']], prefix_sep='_')
 df_test = pd.concat([df_test, ttitledummies], axis=1)
 print('Title Feature created' )
best_submission = pd.read_csv('.. /input/predicting-outliers-to-improve-your-score/3.695.csv' )<merge>
df_data["Embarked"]=df_data["Embarked"].fillna('S')
 df_train["Embarked"] = df_data['Embarked'][:891]
df_test["Embarked"] = df_data['Embarked'][891:]
print('Missing Embarkations Added' )
most_likely_liers = best_submission.merge(outlier_id,how='right')
 most_likely_liers.head()<filter>
dummies=pd.get_dummies(df_train[["Embarked"]], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
 dummies=pd.get_dummies(df_test[["Embarked"]], prefix_sep='_')
 df_test = pd.concat([df_test, dummies], axis=1)
 print("Embarked Feature created" )
%%time
for card_id in most_likely_liers['card_id']:
model_without_outliers.loc[model_without_outliers['card_id']==card_id,'target']\
= most_likely_liers.loc[most_likely_liers['card_id']==card_id,'target'].values<save_to_csv>
df_data["Fare"]=df_data["Fare"].fillna(np.median(df_data["Fare"]))
df_train["Fare"] = df_data["Fare"][:891]
df_test["Fare"] = df_data["Fare"][891:]
print('Estimate missing Fare' )
model_without_outliers.to_csv("combining_submission.csv", index=False )<import_modules>
Pclass = [1,2,3]
for aclass in Pclass:
fare_to_impute = df_data.groupby('Pclass')['Fare'].median() [aclass]
df_data.loc[(df_data['Fare'].isnull())&(df_data['Pclass'] == aclass), 'Fare'] = fare_to_impute
df_train["Fare"] = df_data["Fare"][:891]
df_test["Fare"] = df_data["Fare"][891:]
df_train["FareBand"] = pd.qcut(df_train['Fare'], 4, labels = [1, 2, 3, 4] ).astype('category')
 df_test["FareBand"] = pd.qcut(df_test['Fare'], 4, labels = [1, 2, 3, 4] ).astype('category')
 dummies=pd.get_dummies(df_train[["FareBand"]], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
 dummies=pd.get_dummies(df_test[["FareBand"]], prefix_sep='_')
 df_test = pd.concat([df_test, dummies], axis=1)
 print("Fareband categories created" )
import numpy as np
import pandas as pd
import time
import lightgbm as lgb
from sklearn.model_selection import StratifiedKFold, KFold
from sklearn.metrics import mean_squared_error
from sklearn.metrics import log_loss<load_from_csv>
titles = ['Master', 'Miss', 'Mr', 'Mrs', 'Millitary','Honor']
for title in titles:
age_to_impute = df_data.groupby('Title')['Age'].median() [title]
df_data.loc[(df_data['Age'].isnull())&(df_data['Title'] == title), 'Age'] = age_to_impute
df_train["Age"] = df_data['Age'][:891]
df_test["Age"] = df_data['Age'][891:]
print('Missing Ages Estimated' )
%%time
df_train = pd.read_csv('.. /input/predicting-outliers-to-improve-your-score/train_clean.csv')
 df_test = pd.read_csv('.. /input/predicting-outliers-to-improve-your-score/test_clean.csv' )<drop_column>
df_train["Pclass"]=df_train["Pclass"].astype('category')
 df_test["Pclass"]=df_test["Pclass"].astype('category')
 dummies=pd.get_dummies(df_train[["Pclass"]], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
 dummies=pd.get_dummies(df_test[["Pclass"]], prefix_sep='_')
 df_test = pd.concat([df_test, dummies], axis=1)
 print("Pclass Feature created" )
df_train = df_train[df_train['outliers'] == 0]
target = df_train['target']
del df_train['target']
features = [c for c in df_train.columns if c not in ['card_id', 'first_active_month','outliers']]
categorical_feats = [c for c in features if 'feature_' in c]<init_hyperparams>
bins = [0,12,24,45,60,np.inf]
labels = ['Child', 'Young Adult', 'Adult','Older Adult','Senior']
df_train["AgeGroup"] = pd.cut(df_train["Age"], bins, labels = labels)
 df_test["AgeGroup"] = pd.cut(df_test["Age"], bins, labels = labels)
 print('Age Feature created')
 dummies=pd.get_dummies(df_train[["AgeGroup"]], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
 dummies=pd.get_dummies(df_test[["AgeGroup"]], prefix_sep='_')
 df_test = pd.concat([df_test, dummies], axis=1)
 print("AgeGroup categories created" )
param = {'objective':'regression',
'num_leaves': 31,
'min_data_in_leaf': 25,
'max_depth': 7,
'learning_rate': 0.01,
'lambda_l1':0.13,
"boosting": "gbdt",
"feature_fraction":0.85,
'bagging_freq':8,
"bagging_fraction": 0.9 ,
"metric": 'rmse',
"verbosity": -1,
"random_state": 2333}<split>
dummies=pd.get_dummies(df_train[['Sex']], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
 testdummies=pd.get_dummies(df_test[['Sex']], prefix_sep='_')
 df_test = pd.concat([df_test, testdummies], axis=1)
 print('Gender Categories created' )
%%time
folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=2333)
 oof = np.zeros(len(df_train))
predictions = np.zeros(len(df_test))
feature_importance_df = pd.DataFrame()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(df_train,df_train['outliers'].values)) :
print("fold {}".format(fold_))
trn_data = lgb.Dataset(df_train.iloc[trn_idx][features], label=target.iloc[trn_idx])
 val_data = lgb.Dataset(df_train.iloc[val_idx][features], label=target.iloc[val_idx])
 num_round = 10000
clf = lgb.train(param, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval= 100, early_stopping_rounds = 200)
 oof[val_idx] = clf.predict(df_train.iloc[val_idx][features], num_iteration=clf.best_iteration)
 fold_importance_df = pd.DataFrame()
fold_importance_df["Feature"] = features
fold_importance_df["importance"] = clf.feature_importance()
fold_importance_df["fold"] = fold_ + 1
feature_importance_df = pd.concat([feature_importance_df, fold_importance_df], axis=0)
 predictions += clf.predict(df_test[features], num_iteration=clf.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(mean_squared_error(oof, target)**0.5))<create_dataframe>
df_data["Alone"] = np.where(df_data['SibSp'] + df_data['Parch'] + 1 == 1, 1,0)
 df_train["Alone"] = df_data['Alone'][:891]
df_test["Alone"] = df_data['Alone'][891:]
print('Lone Traveller feature created' )
model_without_outliers = pd.DataFrame({"card_id":df_test["card_id"].values})
 model_without_outliers["target"] = predictions<load_from_csv>
df_data["Last_Name"] = df_data['Name'].apply(lambda x: str.split(x, ",")[0])
 DEFAULT_SURVIVAL_VALUE = 0.5
df_data["Family_Survival"] = DEFAULT_SURVIVAL_VALUE
for grp, grp_df in df_data[['Survived','Name', 'Last_Name', 'Fare', 'Ticket', 'PassengerId',
'SibSp', 'Parch', 'Age', 'Cabin']].groupby(['Last_Name', 'Fare']):
if(len(grp_df)!= 1):
for ind, row in grp_df.iterrows() :
smax = grp_df.drop(ind)['Survived'].max()
smin = grp_df.drop(ind)['Survived'].min()
passID = row['PassengerId']
if(smax == 1.0):
df_data.loc[df_data['PassengerId'] == passID, 'Family_Survival'] = 1
elif(smin==0.0):
df_data.loc[df_data['PassengerId'] == passID, 'Family_Survival'] = 0
print("Number of passengers with family survival information:",
df_data.loc[df_data['Family_Survival']!=0.5].shape[0])
 for _, grp_df in df_data.groupby('Ticket'):
if(len(grp_df)!= 1):
for ind, row in grp_df.iterrows() :
if(row['Family_Survival'] == 0)|(row['Family_Survival']== 0.5):
smax = grp_df.drop(ind)['Survived'].max()
smin = grp_df.drop(ind)['Survived'].min()
passID = row['PassengerId']
if(smax == 1.0):
df_data.loc[df_data['PassengerId'] == passID, 'Family_Survival'] = 1
elif(smin==0.0):
df_data.loc[df_data['PassengerId'] == passID, 'Family_Survival'] = 0
print("Number of passenger with family/group survival information: "
+str(df_data[df_data['Family_Survival']!=0.5].shape[0]))
df_train["Family_Survival"] = df_data['Family_Survival'][:891]
df_test["Family_Survival"] = df_data['Family_Survival'][891:]
%%time
df_train = pd.read_csv('.. /input/predicting-outliers-to-improve-your-score/train_clean.csv')
 df_test = pd.read_csv('.. /input/predicting-outliers-to-improve-your-score/test_clean.csv' )<drop_column>
df_data["HadCabin"] =(df_data["Cabin"].notnull().astype('int'))
df_train["HadCabin"] = df_data["HadCabin"][:891]
df_test["HadCabin"] = df_data["HadCabin"][891:]
print('HasCabin feature created' )
target = df_train['outliers']
del df_train['outliers']
del df_train['target']<define_variables>
df_data["Deck"] = df_data.Cabin.str.extract('([A-Za-z])', expand=False)
 deck_mapping = {"0":0,"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
df_data['Deck'] = df_data['Deck'].map(deck_mapping)
 df_data["Deck"] = df_data["Deck"].fillna("0")
 df_data["Deck"]=df_data["Deck"].astype('int')
 df_train["Deck"] = df_data['Deck'][:891]
df_test["Deck"] = df_data['Deck'][891:]
print('Deck feature created')
 dummies=pd.get_dummies(df_train[['Deck']], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
 dummies=pd.get_dummies(df_test[['Deck']], prefix_sep='_')
 df_test = pd.concat([df_test,dummies], axis=1)
 print('Deck Categories created' )
features = [c for c in df_train.columns if c not in ['card_id', 'first_active_month']]
categorical_feats = [c for c in features if 'feature_' in c]<init_hyperparams>
( df_train['SibSp'])=(df_train['SibSp'] ).astype('category')
 dummies=pd.get_dummies(df_train[['SibSp']], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
(df_test['SibSp'])=(df_test['SibSp'] ).astype('category')
 dummies=pd.get_dummies(df_test[['SibSp']], prefix_sep='_')
 df_test = pd.concat([df_test,dummies], axis=1)
 print('Sibsp Categories created' )
param = {'num_leaves': 31,
'min_data_in_leaf': 30,
'objective':'binary',
'max_depth': 6,
'learning_rate': 0.01,
"boosting": "rf",
"feature_fraction": 0.9,
"bagging_freq": 1,
"bagging_fraction": 0.9 ,
"bagging_seed": 11,
"metric": 'binary_logloss',
"lambda_l1": 0.1,
"verbosity": -1,
"random_state": 2333}<split>
( df_train['Parch'])=(df_train['Parch'] ).astype('category')
 dummies=pd.get_dummies(df_train[['Parch']], prefix_sep='_')
 df_train = pd.concat([df_train, dummies], axis=1)
(df_test['Parch'])=(df_test['Parch'] ).astype('category')
 dummies=pd.get_dummies(df_test[['Parch']], prefix_sep='_')
 df_test = pd.concat([df_test,dummies], axis=1)
 print('Parch Categories created' )
%%time
folds = KFold(n_splits=5, shuffle=True, random_state=15)
 oof = np.zeros(len(df_train))
predictions = np.zeros(len(df_test))
feature_importance_df = pd.DataFrame()
start = time.time()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(df_train.values, target.values)) :
print("fold n°{}".format(fold_))
trn_data = lgb.Dataset(df_train.iloc[trn_idx][features], label=target.iloc[trn_idx], categorical_feature=categorical_feats)
 val_data = lgb.Dataset(df_train.iloc[val_idx][features], label=target.iloc[val_idx], categorical_feature=categorical_feats)
 num_round = 10000
clf = lgb.train(param, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=100, early_stopping_rounds = 200)
 oof[val_idx] = clf.predict(df_train.iloc[val_idx][features], num_iteration=clf.best_iteration)
 fold_importance_df = pd.DataFrame()
fold_importance_df["feature"] = features
fold_importance_df["importance"] = clf.feature_importance()
fold_importance_df["fold"] = fold_ + 1
feature_importance_df = pd.concat([feature_importance_df, fold_importance_df], axis=0)
 predictions += clf.predict(df_test[features], num_iteration=clf.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(log_loss(target, oof)) )<prepare_output>
df_data=df_data.drop(['Cabin','Embarked','Title','Age','Sex','Name','Ticket','Deck','Fare'], axis=1)
 df_train=df_train.drop(['Cabin','Embarked','Title','Age','Sex','Name','Ticket','AgeGroup','Deck','Pclass','Fare','FareBand','SibSp','Parch','Parch_7','Parch_8','Parch_9'], axis=1)
 df_test=df_test.drop(['Cabin','Embarked','Title','Age','Sex','Name','Ticket','AgeGroup','Deck','Pclass','Fare','FareBand','SibSp','Parch','Parch_7','Parch_8','Parch_9'], axis=1)
 print('None Numeric Columns droped' )
df_outlier_prob = pd.DataFrame({"card_id":df_test["card_id"].values})
 df_outlier_prob["target"] = predictions
df_outlier_prob.head()<prepare_output>
NUMERIC_COLUMNS=['Alone','Family Size','Sex','Pclass','Fare','FareBand','Age','TitleCat','Embarked']
ORIGINAL_NUMERIC_COLUMNS=['Pclass','Age','SibSp','Parch','Sex_female','Sex_male','Title_Master', 'Title_Miss','Title_Mr', 'Title_Mrs', 'Title_Millitary','Embarked']
REVISED_NUMERIC_COLUMNS=['Title_Master', 'Title_Millitary',
'Title_Miss', 'Title_Mr', 'Title_Mrs', 'Embarked_C', 'Embarked_Q',
'Embarked_S', 'FareBand_1', 'FareBand_2', 'FareBand_3', 'FareBand_4',
'Pclass_1', 'Pclass_2', 'Pclass_3', 'AgeGroup_Child',
'AgeGroup_Young Adult', 'AgeGroup_Adult', 'AgeGroup_Older Adult',
'AgeGroup_Senior', 'Sex_female', 'Sex_male', 'Alone', 'Family_Survival',
'HadCabin','SibSp_0', 'SibSp_1', 'SibSp_2',
'SibSp_3', 'SibSp_4', 'SibSp_5', 'SibSp_8', 'Parch_0', 'Parch_1',
'Parch_2', 'Parch_3', 'Parch_4', 'Parch_5', 'Parch_6', ]
data_to_train = df_train[REVISED_NUMERIC_COLUMNS].fillna(-1000)
 y=df_train['Survived']
X=data_to_train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,random_state=21, stratify=y)
 print('Model Split' )
outlier_id = pd.DataFrame(df_outlier_prob.sort_values(by='target',ascending = False ).head(25000)['card_id'] )<load_from_csv>
clf = SVC()
clf.fit(X_train, y_train)
 y_pred = clf.predict(X_test)
 acc_clf = round(accuracy_score(y_pred, y_test)* 100, 2)
 print(acc_clf )
best_submission = pd.read_csv('.. /input/predicting-outliers-to-improve-your-score/3.695.csv' )<merge>
test = df_test[REVISED_NUMERIC_COLUMNS].fillna(-1000)
 Submission['Survived']=clf.predict(test)
 Submission.set_index('PassengerId', inplace=True)
 Submission.to_csv('baselinemodel01.csv',sep=',')
 print('Submission Created' )
most_likely_liers = best_submission.merge(outlier_id,how='right')
 most_likely_liers.head()<filter>
REVISED_NUMERIC_COLUMNS=['Title_Master', 'Title_Millitary',
'Title_Miss', 'Title_Mr', 'Title_Mrs', 'Embarked_C', 'Embarked_Q',
'Embarked_S', 'FareBand_1', 'FareBand_2', 'FareBand_3', 'FareBand_4',
'Pclass_1', 'Pclass_2', 'Pclass_3', 'AgeGroup_Child',
'AgeGroup_Young Adult', 'AgeGroup_Adult', 'AgeGroup_Older Adult',
'AgeGroup_Senior', 'Sex_female', 'Sex_male', 'Alone', 'Family_Survival',
'HadCabin','SibSp_0', 'SibSp_1', 'SibSp_2',
'SibSp_3', 'SibSp_4', 'SibSp_5', 'SibSp_8', 'Parch_0', 'Parch_1',
'Parch_2', 'Parch_3', 'Parch_4', 'Parch_5', 'Parch_6', ]
predictors = df_train.drop(['Survived', 'PassengerId'], axis=1)
 data_to_train = df_train[REVISED_NUMERIC_COLUMNS].fillna(-1000)
 X=data_to_train
y = df_train["Survived"]
x_train, x_val, y_train, y_val = train_test_split(data_to_train, y, test_size = 0.3,random_state=21, stratify=y)
 print('Data Split' )
%%time
for card_id in most_likely_liers['card_id']:
model_without_outliers.loc[model_without_outliers['card_id']==card_id,'target']\
= most_likely_liers.loc[most_likely_liers['card_id']==card_id,'target'].values<save_to_csv>
param_dist = {"max_depth": np.arange(1, 6),
"max_features": np.arange(1, 10),
"min_samples_leaf": np.arange(1, 6),
"criterion": ["gini","entropy"]}
tree = DecisionTreeClassifier()
tree_cv = RandomizedSearchCV(tree, param_dist, cv=30)
 tree_cv.fit(X,y)
 y_pred = tree_cv.predict(x_val)
 print("Tuned Decision Tree Parameters: {}".format(tree_cv.best_params_))
print("Best score is {}".format(tree_cv.best_score_))
acc_tree_cv = round(accuracy_score(y_pred, y_val)* 100, 2)
 print(acc_tree_cv )
model_without_outliers.to_csv("combining_submission.csv", index=False )<import_modules>
test = df_test[REVISED_NUMERIC_COLUMNS].fillna(-1000)
 tree = DecisionTreeClassifier(max_depth=5,max_features=7,min_samples_leaf=1,criterion="entropy")
 tree.fit(X,y)
 Submission['Survived']=tree.predict(test)
 print(Submission.head(5))
import pandas as pd
import numpy as np
import seaborn as sns<load_from_csv>
Submission.to_csv('Tunedtree1submission.csv',sep=',')
 print("Submission Submitted" )
df1 = pd.read_csv(".. /input/elo-blending/BlendingRLSR.csv")
 df1.head()<save_to_csv>
REVISED_NUMERIC_COLUMNS=['Title_Master', 'Title_Millitary',
'Title_Miss', 'Title_Mr', 'Title_Mrs', 'Embarked_C', 'Embarked_Q',
'Embarked_S', 'FareBand_1', 'FareBand_2', 'FareBand_3', 'FareBand_4',
'Pclass_1', 'Pclass_2', 'Pclass_3', 'AgeGroup_Child',
'AgeGroup_Young Adult', 'AgeGroup_Adult', 'AgeGroup_Older Adult',
'AgeGroup_Senior', 'Sex_female', 'Sex_male', 'Alone', 'Family_Survival',
'HadCabin','SibSp_0', 'SibSp_1', 'SibSp_2',
'SibSp_3', 'SibSp_4', 'SibSp_5', 'SibSp_8', 'Parch_0', 'Parch_1',
'Parch_2', 'Parch_3', 'Parch_4', 'Parch_5', 'Parch_6', ]
predictors = df_train.drop(['Survived', 'PassengerId'], axis=1)
 data_to_train = df_train[REVISED_NUMERIC_COLUMNS].fillna(-1000)
 data_to_predict=df_test[REVISED_NUMERIC_COLUMNS].fillna(-1000)
 y=df_train['Survived']
X=data_to_train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,random_state=21, stratify=y)
 print('Data split' )
df2 = pd.read_csv(".. /input/elo-blending/combining_submission(1 ).csv")
 df2.head()
df3 = pd.read_csv(".. /input/simple-lightgbm-without-blending/submission.csv")
 df3.head()
df2['target'] = df2['target'] * 0.35 + df1['target'] * 0.65
df2['target'] = df2['target'] * 0.57 + df3['target'] * 0.43
df2.to_csv("blend.csv",index = False )<import_modules>
print('Modules imported' )
import numpy as np
import pandas as p
from matplotlib import pyplot as plt
import seaborn as sns
from math import sqrt
from sklearn import metrics<load_from_csv>
model = Sequential()
model.add(Dense(units=56, input_dim=X.shape[1], activation='selu'))
model.add(Dropout(0.5))
model.add(Dense(units=27, activation='selu'))
model.add(Dropout(0.5))
model.add(Dense(units=1, activation='tanh'))
model.compile(loss='mse', optimizer='sgd')
 print('Keras Model Created' )
df_base0 = p.read_csv('.. /input/elo-blending/3.695.csv',names=["card_id","target0"], skiprows=[0],header=None)
 df_base1 = p.read_csv('.. /input/elo-blending/3.696.csv',names=["card_id","target1"], skiprows=[0],header=None)
 df_base2 = p.read_csv('.. /input/elo-blending/3.6999.csv',names=["card_id","targe2"], skiprows=[0],header=None)
 df_base3 = p.read_csv('.. /input/elo-blending/3.69991.csv',names=["card_id","target3"], skiprows=[0],header=None)
 df_base4 = p.read_csv('.. /input/elo-blending/3.699992.csv',names=["card_id","target4"], skiprows=[0],header=None)
 df_base5 = p.read_csv('.. /input/elo-blending/3.70.csv',names=["card_id","target5"], skiprows=[0],header=None)
 df_base6 = p.read_csv('.. /input/elo-blending/3.701.csv',names=["card_id","target6"], skiprows=[0],header=None)
 df_base7 = p.read_csv('.. /input/elo-blending/3.702.csv',names=["card_id","target7"], skiprows=[0],header=None)
 df_base8 = p.read_csv('.. /input/elo-blending/3.703.csv',names=["card_id","target8"], skiprows=[0],header=None)
 df_base9 = p.read_csv('.. /input/elo-blending/3.704.csv',names=["card_id","target9"], skiprows=[0],header=None)
 df_base10 = p.read_csv('.. /input/elo-blending/Blending.csv',names=["card_id","target10"], skiprows=[0],header=None)
 df_base11 = p.read_csv('.. /input/elo-blending/BlendingRLS.csv',names=["card_id","target11"], skiprows=[0],header=None)
 df_base12 = p.read_csv('.. /input/elo-blending/combining_submission(1 ).csv',names=["card_id","target12"], skiprows=[0],header=None)
 df_base13 = p.read_csv('.. /input/elo-blending/BlendingRLSR.csv',names=["card_id","target13"], skiprows=[0],header=None)
 df_base14 = p.read_csv('.. /input/simple-lightgbm-without-blending/submission.csv',names=["card_id","target14"], skiprows=[0],header=None )<merge>
model.fit(X.values, y.values, epochs=500, verbose=0)
 print('Keras model fitted' )
df_base = p.merge(df_base12,df_base0,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base1,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base2,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base3,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base4,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base5,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base6,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base7,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base8,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base9,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base10,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base11,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base12,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base13,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base14,how='inner',on='card_id' )<compute_test_metric>
df_test=df_test.set_index('PassengerId')
 p_survived = model.predict_classes(df_test)
 print('Prediction Completed' )
M = np.zeros([df_base.iloc[:,1:].shape[1],df_base.iloc[:,1:].shape[1]])
 for i in np.arange(M.shape[1]):
for j in np.arange(M.shape[1]):
M[i,j] = sqrt(metrics.mean_squared_error(df_base.iloc[:,i+1], df_base.iloc[:,j+1]))<save_to_csv>
submission = pd.DataFrame()
submission['PassengerId'] = df_test.index
submission['Survived'] = p_survived
print('predictions added to submission' )
df_base['target'] = df_base.iloc[:,1:].mean(axis=1)
 df_base[['card_id','target']].to_csv("Bestoutput.csv",index=False )<load_from_csv>
submission.to_csv('DeepLearning03.csv', index=False)
 print('csv created' )
df_base14 = p.read_csv('.. /input/simple-lightgbm-without-blending/submission.csv',names=["card_id","target14"], skiprows=[0],header=None)
 df_base6 = p.read_csv('.. /input/elo-blending/3.701.csv',names=["card_id","target6"], skiprows=[0],header=None)
 df_base7 = p.read_csv('.. /input/elo-blending/3.702.csv',names=["card_id","target7"], skiprows=[0],header=None)
 df_base = p.merge(df_base12,df_base6,how='inner',on='card_id')
 df_base = p.merge(df_base,df_base7,how='inner',on='card_id')
 plt.figure(figsize=(16,12))
sns.heatmap(df_base.iloc[:,1:].corr() ,annot=True,fmt=".2f" )<compute_test_metric>
seed=70
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
 cvscores = []
for train, test in kfold.split(X, y):
model = Sequential()
model.add(Dense(54, input_dim=X.shape[1], activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(54, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(54, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(1, activation='tanh'))
model.compile(loss='binary_crossentropy', optimizer='Adagrad', metrics=['accuracy'])
 model.fit(X_train, y_train, epochs=150, batch_size=10, verbose=0)
 scores = model.evaluate(X_test, y_test, verbose=0)
 print("%s: %.2f%%" %(model.metrics_names[1], scores[1]*100))
cvscores.append(scores[1] * 100)
 print("%.2f%%(+/- %.2f%%)" %(np.mean(cvscores), np.std(cvscores)) )
M = np.zeros([df_base.iloc[:,1:].shape[1],df_base.iloc[:,1:].shape[1]])
 for i in np.arange(M.shape[1]):
for j in np.arange(M.shape[1]):
M[i,j] = sqrt(metrics.mean_squared_error(df_base.iloc[:,i+1], df_base.iloc[:,j+1]))<save_to_csv>
submission = pd.DataFrame()
submission['PassengerId'] = df_test.index
submission['Survived'] = p_survived
print('predictions added to submission' )
df_base['target'] = df_base.iloc[:,1:].mean(axis=1)
 df_base[['card_id','target']].to_csv("blend2.csv",index=False )<save_to_csv>
submission.to_csv('OptimisedDeepLearning04.csv', index=False)
 print('csv created' )