Kaggle competition: Titanic - Machine Learning from Disaster
del sample_sub<load_from_csv>
sub_data = pd.read_csv('/kaggle/input/titanic/gender_submission.csv')
 sub_data.head()
train_identity = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_identity.csv')
 train_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_transaction.csv')
 test_identity = pd.read_csv('/kaggle/input/ieee-fraud-detection/test_identity.csv')
 test_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/test_transaction.csv' )<merge>
train_data = pd.read_csv('/kaggle/input/titanic/train.csv')
 train_data.head()
train = pd.merge(train_transaction, train_identity, on='TransactionID', how='left')
 test = pd.merge(test_transaction, test_identity, on='TransactionID', how='left' )<train_model>
test_data = pd.read_csv('/kaggle/input/titanic/test.csv')
 test_data.head()
print(f'Train dataset: {train.shape[0]} rows & {train.shape[1]} columns')
 print(f'Test dataset: {test.shape[0]} rows & {test.shape[1]} columns' )<drop_column>
train_data.drop_duplicates(keep='first',inplace=True)
 train_data.shape
train = reduce_mem_usage(train)
 test = reduce_mem_usage(test )<drop_column>
train_survived = train_data['Survived'].value_counts()
not_surv =(train_survived[0]/(train_survived[1]+train_survived[0])) *100
print('Not survived %: ',"{:.2f}".format(not_surv))
print('Survived %: ',"{:.2f}".format(100-not_surv))
del train_identity, train_transaction, test_identity, test_transaction<prepare_output>
train_data['PassengerId'][train_data['Age']>20][train_data['Age']<55].count()
data_null = train.isnull().sum() /len(train)* 100
data_null = data_null.drop(data_null[data_null == 0].index ).sort_values(ascending=False)[:500]
missing_data = pd.DataFrame({'Missing Ratio': data_null})
 missing_data.head()<count_missing_values>
train_data['Cabin'].isnull().sum()
def get_too_many_null_attr(data):
many_null_cols = [col for col in data.columns if data[col].isnull().sum() / data.shape[0] > 0.9]
return many_null_cols<count_values>
train_df = train_data.copy()
train_df.drop(columns=['PassengerId','Cabin','Name'],inplace=True)
 train_df.head()
def get_too_many_repeated_val(data):
big_top_value_cols = [col for col in train.columns if train[col].value_counts(dropna=False, normalize=True ).values[0] > 0.9]
return big_top_value_cols<count_values>
test_df = test_data.copy()
test_df.drop(columns=['PassengerId','Cabin','Name'],inplace=True)
 test_df.head()
train['id_03'].value_counts(dropna=False, normalize=True ).head()<count_values>
test_df.isnull().sum()
train['id_11'].value_counts(dropna=False, normalize=True ).head()<define_variables>
train_df.isnull().sum()
for i in range(1, 10):
print(train['M' + str(i)].value_counts(dropna=False, normalize=True ).head())
 print('
' )<drop_column>
x_df = train_df.iloc[:,1:11]
y_df = train_df.iloc[:,0:1]
x_df.head(10)
 print(type(x_df))
del charts<define_variables>
x_train,x_val,y_train,y_val = train_test_split(x_df,y_df,test_size=.20,random_state=1,stratify=y_df)
 x_train.head()
def seed_everything(seed=0):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
<define_variables>
print(x_train.isnull().sum() )
SEED = 42
seed_everything(SEED)
 TARGET = 'isFraud'
START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d' )<data_type_conversions>
x_val.isnull().sum()
def addNewFeatures(data):
data['uid'] = data['card1'].astype(str)+'_'+data['card2'].astype(str)
 data['uid2'] = data['uid'].astype(str)+'_'+data['card3'].astype(str)+'_'+data['card5'].astype(str)
 data['uid3'] = data['uid2'].astype(str)+'_'+data['addr1'].astype(str)+'_'+data['addr2'].astype(str)
 return data<feature_engineering>
values_age = x_train['Age'].values.reshape(-1,1)
 num_imputer = SimpleImputer(missing_values=np.nan,strategy='mean')
 x_train[['Age']] = num_imputer.fit_transform(values_age)
 values_embarked = x_train[['Embarked']].values
alpha_imputer = SimpleImputer(missing_values=np.nan,strategy='most_frequent')
 x_train[['Embarked']] = alpha_imputer.fit_transform(values_embarked)
 x_train.head()
train = addNewFeatures(train)
 test = addNewFeatures(test )<data_type_conversions>
x_train.isnull().sum()
i_cols = ['card1','card2','card3','card5','uid','uid2','uid3']
for col in i_cols:
for agg_type in ['mean','std']:
new_col_name = col+'_TransactionAmt_'+agg_type
temp_df = pd.concat([train[[col, 'TransactionAmt']], test[[col,'TransactionAmt']]])
 temp_df = temp_df.groupby([col])['TransactionAmt'].agg([agg_type] ).reset_index().rename(
 columns={agg_type: new_col_name})
 temp_df.index = list(temp_df[col])
 temp_df = temp_df[new_col_name].to_dict()
train[new_col_name] = train[col].map(temp_df)
 test[new_col_name] = test[col].map(temp_df )<categorify>
print(x_val.isnull().sum() )
train = train.replace(np.inf,999)
 test = test.replace(np.inf,999 )<feature_engineering>
def imputer_null(df):
for cols in df.columns.values:
if df[cols].values.dtype=='object':
df[[cols]]=alpha_imputer.transform(df[cols].values.reshape(-1,1))
else:
df[[cols]]=num_imputer.transform(df[cols].values.reshape(-1,1))
return df
train['TransactionAmt'] = np.log1p(train['TransactionAmt'])
 test['TransactionAmt'] = np.log1p(test['TransactionAmt'] )<define_variables>
x_val = imputer_null(x_val)
 print(x_val.isnull().sum() )
emails = {'gmail': 'google', 'att.net': 'att', 'twc.com': 'spectrum', 'scranton.edu': 'other', 'optonline.net': 'other',
'hotmail.co.uk': 'microsoft', 'comcast.net': 'other', 'yahoo.com.mx': 'yahoo', 'yahoo.fr': 'yahoo',
'yahoo.es': 'yahoo', 'charter.net': 'spectrum', 'live.com': 'microsoft', 'aim.com': 'aol', 'hotmail.de': 'microsoft',
'centurylink.net': 'centurylink', 'gmail.com': 'google', 'me.com': 'apple', 'earthlink.net': 'other',
'gmx.de': 'other', 'web.de': 'other', 'cfl.rr.com': 'other', 'hotmail.com': 'microsoft', 'protonmail.com': 'other',
'hotmail.fr': 'microsoft', 'windstream.net': 'other', 'outlook.es': 'microsoft', 'yahoo.co.jp': 'yahoo',
'yahoo.de': 'yahoo', 'servicios-ta.com': 'other', 'netzero.net': 'other', 'suddenlink.net': 'other',
'roadrunner.com': 'other', 'sc.rr.com': 'other', 'live.fr': 'microsoft', 'verizon.net': 'yahoo',
'msn.com': 'microsoft', 'q.com': 'centurylink', 'prodigy.net.mx': 'att', 'frontier.com': 'yahoo',
'anonymous.com': 'other', 'rocketmail.com': 'yahoo', 'sbcglobal.net': 'att', 'frontiernet.net': 'yahoo',
'ymail.com': 'yahoo', 'outlook.com': 'microsoft', 'mail.com': 'other', 'bellsouth.net': 'other',
'embarqmail.com': 'centurylink', 'cableone.net': 'other', 'hotmail.es': 'microsoft', 'mac.com': 'apple',
'yahoo.co.uk': 'yahoo', 'netzero.com': 'other', 'yahoo.com': 'yahoo', 'live.com.mx': 'microsoft', 'ptd.net': 'other',
'cox.net': 'other', 'aol.com': 'aol', 'juno.com': 'other', 'icloud.com': 'apple'}
us_emails = ['gmail', 'net', 'edu']
for c in ['P_emaildomain', 'R_emaildomain']:
train[c + '_bin'] = train[c].map(emails)
 test[c + '_bin'] = test[c].map(emails)
 train[c + '_suffix'] = train[c].map(lambda x: str(x ).split('.')[-1])
 test[c + '_suffix'] = test[c].map(lambda x: str(x ).split('.')[-1])
 train[c + '_suffix'] = train[c + '_suffix'].map(lambda x: x if str(x)not in us_emails else 'us')
 test[c + '_suffix'] = test[c + '_suffix'].map(lambda x: x if str(x)not in us_emails else 'us' )<feature_engineering>
x_train.reset_index(drop=True,inplace=True)
 x_train
x_val.reset_index(drop=True,inplace=True)
 x_val
p = 'P_emaildomain'
r = 'R_emaildomain'
uknown = 'email_not_provided'
def setDomain(df):
df[p] = df[p].fillna(uknown)
 df[r] = df[r].fillna(uknown)
 df['email_check'] = np.where(( df[p]==df[r])&(df[p]!=uknown),1,0)
 df[p+'_prefix'] = df[p].apply(lambda x: x.split('.')[0])
 df[r+'_prefix'] = df[r].apply(lambda x: x.split('.')[0])
 return df
train=setDomain(train)
 test=setDomain(test )<feature_engineering>
y_train.reset_index(drop=True,inplace=True)
 y_train
y_val.reset_index(drop=True,inplace=True )
def setTime(df):
df['TransactionDT'] = df['TransactionDT'].fillna(df['TransactionDT'].median())
 df['DT'] = df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 df['DT_M'] =(df['DT'].dt.year-2017)*12 + df['DT'].dt.month
df['DT_W'] =(df['DT'].dt.year-2017)*52 + df['DT'].dt.weekofyear
df['DT_D'] =(df['DT'].dt.year-2017)*365 + df['DT'].dt.dayofyear
df['DT_hour'] = df['DT'].dt.hour
df['DT_day_week'] = df['DT'].dt.dayofweek
df['DT_day'] = df['DT'].dt.day
df['D9_not_na'] = np.where(df['D9'].isna() ,0,1)
 df['D8_not_same_day'] = np.where(df['D8']>=1,1,0)
 df['D8_D9_decimal_dist'] = df['D8'].fillna(0)-df['D8'].fillna(0 ).astype(int)
 df['D8_D9_decimal_dist'] =(( df['D8_D9_decimal_dist']-df['D9'])**2)**0.5
df['D8'] = df['D8'].fillna(-1 ).astype(int)
 return df
train=setTime(train)
 test=setTime(test )<feature_engineering>
ticket_new = x_train['Ticket'].str.split(" ",n=1,expand=True)
 print(ticket_new)
 print(type(ticket_new))
print(x_train.head() )
train["lastest_browser"] = np.zeros(train.shape[0])
 test["lastest_browser"] = np.zeros(test.shape[0])
 def setBrowser(df):
df.loc[df["id_31"]=="samsung browser 7.0",'lastest_browser']=1
df.loc[df["id_31"]=="opera 53.0",'lastest_browser']=1
df.loc[df["id_31"]=="mobile safari 10.0",'lastest_browser']=1
df.loc[df["id_31"]=="google search application 49.0",'lastest_browser']=1
df.loc[df["id_31"]=="firefox 60.0",'lastest_browser']=1
df.loc[df["id_31"]=="edge 17.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 69.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 67.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 63.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 63.0 for ios",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 64.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 64.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 64.0 for ios",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 65.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 65.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 65.0 for ios",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 66.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 66.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 66.0 for ios",'lastest_browser']=1
return df
train=setBrowser(train)
 test=setBrowser(test )<feature_engineering>
x_train_new = pd.concat([x_train,ticket_new],axis=1 ).drop(['Ticket'],axis=1)
 x_train_new
def setDevice(df):
df['DeviceInfo'] = df['DeviceInfo'].fillna('unknown_device' ).str.lower()
df['device_name'] = df['DeviceInfo'].str.split('/', expand=True)[0]
df.loc[df['device_name'].str.contains('SM', na=False), 'device_name'] = 'Samsung'
df.loc[df['device_name'].str.contains('SAMSUNG', na=False), 'device_name'] = 'Samsung'
df.loc[df['device_name'].str.contains('GT-', na=False), 'device_name'] = 'Samsung'
df.loc[df['device_name'].str.contains('Moto G', na=False), 'device_name'] = 'Motorola'
df.loc[df['device_name'].str.contains('Moto', na=False), 'device_name'] = 'Motorola'
df.loc[df['device_name'].str.contains('moto', na=False), 'device_name'] = 'Motorola'
df.loc[df['device_name'].str.contains('LG-', na=False), 'device_name'] = 'LG'
df.loc[df['device_name'].str.contains('rv:', na=False), 'device_name'] = 'RV'
df.loc[df['device_name'].str.contains('HUAWEI', na=False), 'device_name'] = 'Huawei'
df.loc[df['device_name'].str.contains('ALE-', na=False), 'device_name'] = 'Huawei'
df.loc[df['device_name'].str.contains('-L', na=False), 'device_name'] = 'Huawei'
df.loc[df['device_name'].str.contains('Blade', na=False), 'device_name'] = 'ZTE'
df.loc[df['device_name'].str.contains('BLADE', na=False), 'device_name'] = 'ZTE'
df.loc[df['device_name'].str.contains('Linux', na=False), 'device_name'] = 'Linux'
df.loc[df['device_name'].str.contains('XT', na=False), 'device_name'] = 'Sony'
df.loc[df['device_name'].str.contains('HTC', na=False), 'device_name'] = 'HTC'
df.loc[df['device_name'].str.contains('ASUS', na=False), 'device_name'] = 'Asus'
df.loc[df.device_name.isin(df.device_name.value_counts() [df.device_name.value_counts() < 200].index), 'device_name'] = "Others"
df['had_id'] = 1
gc.collect()
return df
train=setDevice(train)
 test=setDevice(test )<data_type_conversions>
x_train_new.rename(columns={0:"Ticket_ind",1:"Ticket_no"},inplace=True)
 x_train=x_train_new.copy()
x_train.head()
i_cols = ['card1','card2','card3','card5',
'C1','C2','C3','C4','C5','C6','C7','C8','C9','C10','C11','C12','C13','C14',
'D1','D2','D3','D4','D5','D6','D7','D8',
'addr1','addr2',
'dist1','dist2',
'P_emaildomain', 'R_emaildomain',
'DeviceInfo','device_name',
'id_30','id_33',
'uid','uid2','uid3',
]
for col in i_cols:
temp_df = pd.concat([train[[col]], test[[col]]])
 fq_encode = temp_df[col].value_counts(dropna=False ).to_dict()
train[col+'_fq_enc'] = train[col].map(fq_encode)
 test[col+'_fq_enc'] = test[col].map(fq_encode)
 for col in ['DT_M','DT_W','DT_D']:
temp_df = pd.concat([train[[col]], test[[col]]])
 fq_encode = temp_df[col].value_counts().to_dict()
train[col+'_total'] = train[col].map(fq_encode)
 test[col+'_total'] = test[col].map(fq_encode)
 periods = ['DT_M','DT_W','DT_D']
i_cols = ['uid']
for period in periods:
for col in i_cols:
new_column = col + '_' + period
temp_df = pd.concat([train[[col,period]], test[[col,period]]])
 temp_df[new_column] = temp_df[col].astype(str)+ '_' +(temp_df[period] ).astype(str)
 fq_encode = temp_df[new_column].value_counts().to_dict()
train[new_column] =(train[col].astype(str)+ '_' + train[period].astype(str)).map(fq_encode)
 test[new_column] =(test[col].astype(str)+ '_' + test[period].astype(str)).map(fq_encode)
 train[new_column] /= train[period+'_total']
test[new_column] /= test[period+'_total']<drop_column>
x_train['Ticket_no'].values
x_train.drop(columns=['Ticket_no'],axis=1,inplace=True)
 x_train.head()
train = train.drop(cols_to_drop, axis=1 )<categorify>
x_num = x_train[x_train['Ticket_ind'].str.isnumeric() ]
x_num
class ModifiedLabelEncoder(LabelEncoder):
def fit_transform(self, y, *args, **kwargs):
return super().fit_transform(y ).reshape(-1, 1)
 def transform(self, y, *args, **kwargs):
return super().transform(y ).reshape(-1, 1 )<train_model>
x_alpha = x_train[x_train['Ticket_ind'].str.isalpha() ]
x_alpha.head(30 )
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self, attr):
self.attributes = attr
def fit(self, X, y=None):
return self
def transform(self, X):
return X[self.attributes].values<drop_column>
x_train.drop(columns=['Ticket_ind'],axis=1,inplace=True )
cat_attr = list(train.select_dtypes(include=['object'] ).columns)
 num_attr = list(train.select_dtypes(exclude=['object'] ).columns)
 num_attr.remove('isFraud')
 for col in noisy_cat_cols:
if col in cat_attr:
print("Deleting " + col)
 cat_attr.remove(col)
 for col in noisy_num_cold:
if col in num_attr:
print("Deleting " + col)
 num_attr.remove(col )<create_dataframe>
x_val.drop(columns=['Ticket'],axis=1,inplace=True )
num_pipeline = Pipeline([ 
('selector', DataFrameSelector(num_attr)) , 
('imputer', SimpleImputer(strategy="median")) , 
('scaler', StandardScaler()),
])
 cat_pipeline = Pipeline([ 
('selector', DataFrameSelector(cat_attr)) , 
('imputer', SimpleImputer(strategy="most_frequent")) ,
])
 full_pipeline = FeatureUnion(transformer_list=[ 
('num_pipeline', num_pipeline), 
('cat_pipeline', cat_pipeline),
] )<categorify>
one_enc = OneHotEncoder(handle_unknown='ignore')
 df_new=pd.DataFrame()
col_names={}
to_be_enc_cols = ['Pclass','Sex','Embarked']
for column_ind in range(len(to_be_enc_cols)) :
one_hot_enc = one_enc.fit_transform(np.array(x_train[to_be_enc_cols[column_ind]] ).reshape(-1,1)).toarray()
col_names[to_be_enc_cols[column_ind]] = one_enc.get_feature_names([to_be_enc_cols[column_ind]])
 df = pd.DataFrame(one_hot_enc,columns=col_names[to_be_enc_cols[column_ind]])
 df_new = pd.concat([df,df_new], axis = 1)
 x_train = pd.concat([x_train,df_new], axis = 1 ).drop(['Pclass','Sex','Embarked'],axis=1)
 print(x_train)
def encodeCategorical(df_train, df_test):
for f in df_train.drop('isFraud', axis=1 ).columns:
if df_train[f].dtype=='object' or df_test[f].dtype=='object':
lbl = preprocessing.LabelEncoder()
lbl.fit(list(df_train[f].values)+ list(df_test[f].values))
df_train[f] = lbl.transform(list(df_train[f].values))
df_test[f] = lbl.transform(list(df_test[f].values))
return df_train, df_test<prepare_x_and_y>
def one_hot(df):
df2=pd.DataFrame()
col_names={}
to_be_enc_cols = ['Pclass','Sex','Embarked']
for column_ind in range(len(to_be_enc_cols)) :
one_hot_enc = one_enc.fit_transform(np.array(df[to_be_enc_cols[column_ind]] ).reshape(-1,1)).toarray()
col_names[to_be_enc_cols[column_ind]] = one_enc.get_feature_names([to_be_enc_cols[column_ind]])
 df1 = pd.DataFrame(one_hot_enc,columns=col_names[to_be_enc_cols[column_ind]])
 df2 = pd.concat([df1,df2], axis = 1)
 one_hot_df = pd.concat([df,df2], axis = 1 ).drop(['Pclass','Sex','Embarked'],axis=1)
 return one_hot_df
y_train = train['isFraud']
train, test = encodeCategorical(train, test )<create_dataframe>
X_train = pd.DataFrame(full_pipeline.fit_transform(train))
gc.collect()<drop_column>
del train<create_dataframe>
test = test.drop(cols_to_drop, axis=1)
 test = pd.DataFrame(full_pipeline.transform(test))<find_best_model_class>
x_val = one_hot(x_val)
 x_val
def makePredictions(tr_df, tt_df, target, lgb_params, NFOLDS=2):
folds = KFold(n_splits=NFOLDS, shuffle=True, random_state=SEED)
 X,y = tr_df, y_train
P = tt_df
predictions = np.zeros(len(tt_df))
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y)) :
print('Fold:',fold_)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, vl_y = X.iloc[val_idx,:], y[val_idx]
print(len(tr_x),len(vl_x))
tr_data = lgb.Dataset(tr_x, label=tr_y)
 vl_data = lgb.Dataset(vl_x, label=vl_y)
 estimator = lgb.train(
 lgb_params,
tr_data,
valid_sets = [tr_data, vl_data],
verbose_eval = 200, 
)
 pp_p = estimator.predict(P)
 predictions += pp_p/NFOLDS
del tr_x, tr_y, vl_x, vl_y, tr_data, vl_data
gc.collect()
tt_df['prediction'] = predictions
return tt_df<init_hyperparams>
def add_family_feature(df):
df['Family'] = df['SibSp']+df['Parch']
df.drop(['SibSp','Parch'],axis=1,inplace=True)
 return df
lgb_params = {
'objective':'binary',
'boosting_type':'gbdt',
'metric':'auc',
'n_jobs':-1,
'learning_rate':0.064,
'num_leaves': 2**8,
'max_depth':-1,
'tree_learner':'serial',
'colsample_bytree': 0.7,
'subsample_freq':1,
'subsample':0.7,
'n_estimators':800,
'max_bin':255,
'verbose':-1,
'seed': SEED,
'early_stopping_rounds':100,
}<predict_on_test>
x_train = add_family_feature(x_train)
 x_val = add_family_feature(x_val)
 x_val.head()
lgb_params['learning_rate'] = 0.005
lgb_params['n_estimators'] = 1800
lgb_params['early_stopping_rounds'] = 100
test_predictions = makePredictions(X_train, test, TARGET, lgb_params, NFOLDS=8 )<create_dataframe>
normalize = MinMaxScaler()
normalize_col = ['Age','Fare']
df_new = pd.DataFrame()
for cols in normalize_col:
x_train_scaled = normalize.fit_transform(np.array(x_train[cols] ).reshape(-1,1))
df_scaled = pd.DataFrame(x_train_scaled,columns=[cols+'_new'])
 df_new = pd.concat([df_new,df_scaled],axis=1)
 print(df_new)
 x_train = pd.concat([x_train,df_new],axis=1)
 x_train.drop(columns=['Age','Fare'],axis=1,inplace=True)
 x_train.head()
lgb_submission = pd.DataFrame({
"isFraud": test_predictions['prediction'],
} )<save_to_csv>
def normalize_feature(df):
normalize_col = ['Age','Fare']
df_new = pd.DataFrame()
for cols in normalize_col:
x_scaled = normalize.fit_transform(np.array(df[cols] ).reshape(-1,1))
df_scaled = pd.DataFrame(x_scaled,columns=[cols+'_new'])
 df_new = pd.concat([df_new,df_scaled],axis=1)
 df = pd.concat([df,df_new],axis=1)
 df.drop(columns=['Age','Fare'],axis=1,inplace=True)
 return df
lgb_submission.insert(0, "TransactionID", np.arange(3663549, 3663549 + 506691))
lgb_submission.to_csv('prediction.csv', index=False )<set_options>
x_val = normalize_feature(x_val)
 x_val.head()
warnings.filterwarnings('ignore' )<init_hyperparams>
x_train_data = x_train.copy()
x_train_data.head()
x_val_data = x_val.copy()
def seed_everything(seed=0):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 def reduce_mem_usage(df, verbose=True):
numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
start_mem = df.memory_usage().sum() / 1024**2
for col in df.columns:
col_type = df[col].dtypes
if col_type in numerics:
c_min = df[col].min()
c_max = df[col].max()
if str(col_type)[:3] == 'int':
if c_min > np.iinfo(np.int8 ).min and c_max < np.iinfo(np.int8 ).max:
df[col] = df[col].astype(np.int8)
 elif c_min > np.iinfo(np.int16 ).min and c_max < np.iinfo(np.int16 ).max:
df[col] = df[col].astype(np.int16)
 elif c_min > np.iinfo(np.int32 ).min and c_max < np.iinfo(np.int32 ).max:
df[col] = df[col].astype(np.int32)
 elif c_min > np.iinfo(np.int64 ).min and c_max < np.iinfo(np.int64 ).max:
df[col] = df[col].astype(np.int64)
 else:
if c_min > np.finfo(np.float16 ).min and c_max < np.finfo(np.float16 ).max:
df[col] = df[col].astype(np.float16)
 elif c_min > np.finfo(np.float32 ).min and c_max < np.finfo(np.float32 ).max:
df[col] = df[col].astype(np.float32)
 else:
df[col] = df[col].astype(np.float64)
 end_mem = df.memory_usage().sum() / 1024**2
if verbose: print('Mem.usage decreased to {:5.2f} Mb({:.1f}% reduction)'.format(end_mem, 100 *(start_mem - end_mem)/ start_mem))
return df
def get_memory_usage() :
return np.round(psutil.Process(os.getpid() ).memory_info() [0]/2.**30, 2)
 def sizeof_fmt(num, suffix='B'):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(num)< 1024.0:
return "%3.1f%s%s" %(num, unit, suffix)
 num /= 1024.0
return "%.1f%s%s" %(num, 'Yi', suffix )<predict_on_test>
train_all = pd.concat([x_train,y_train],axis=1)
 train_all.head()
def make_predictions(tr_df, tt_df, features_columns, target, cat_params, NFOLDS=2, kfold_mode='grouped'):
X,y = tr_df[features_columns], tr_df[target]
P,P_y = tt_df[features_columns], tt_df[target]
split_groups = tr_df['DT_M']
tt_df = tt_df[['TransactionID',target]]
tr_df = tr_df[['TransactionID',target]]
predictions = np.zeros(len(tt_df))
oof = np.zeros(len(tr_df))
if kfold_mode=='grouped':
folds = GroupKFold(n_splits=NFOLDS)
 folds_split = folds.split(X, y, groups=split_groups)
 else:
folds = KFold(n_splits=NFOLDS, shuffle=True, random_state=SEED)
 folds_split = folds.split(X, y)
 for fold_,(trn_idx, val_idx)in enumerate(folds_split):
print('Fold:',fold_)
 estimator = CatBoostClassifier(**cat_params)
 estimator.fit(
 X.iloc[trn_idx,:],y[trn_idx],
eval_set=(X.iloc[val_idx,:], y[val_idx]),
cat_features=categorical_features,
use_best_model=True,
verbose=True)
 pp_p = estimator.predict_proba(P)[:,1]
predictions += pp_p/NFOLDS
oof_preds = estimator.predict_proba(X.iloc[val_idx,:])[:,1]
oof[val_idx] =(oof_preds - oof_preds.min())/(oof_preds.max() - oof_preds.min())
 del estimator
gc.collect()
tt_df['prediction'] = predictions
print('OOF AUC:', metrics.roc_auc_score(y, oof))
if LOCAL_TEST:
print('Holdout AUC:', metrics.roc_auc_score(tt_df[TARGET], tt_df['prediction']))
return tt_df 
<define_variables>
clf_log_reg = LogisticRegression(penalty='l2',random_state=1,solver='lbfgs',tol=0.001 ).fit(x_train,y_train )
SEED = 42
seed_everything(SEED)
 LOCAL_TEST = False
TARGET = 'isFraud'
START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d' )<init_hyperparams>
clf_log_reg.predict(x_val )
cat_params = {
'n_estimators':5000,
'learning_rate': 0.07,
'eval_metric':'AUC',
'loss_function':'Logloss',
'random_seed':SEED,
'metric_period':500,
'od_wait':500,
'task_type':'GPU',
'depth': 8,
}<load_pretrained>
print(clf_log_reg.decision_function(x_val))
print('Load Data')
 if LOCAL_TEST:
train_df = pd.read_pickle('.. /input/ieee-fe-for-local-test/train_df.pkl')
 test_df = pd.read_pickle('.. /input/ieee-fe-for-local-test/test_df.pkl')
 else:
train_df = pd.read_pickle('.. /input/ieee-fe-with-some-eda/train_df.pkl')
 test_df = pd.read_pickle('.. /input/ieee-fe-with-some-eda/test_df.pkl')
 remove_features = pd.read_pickle('.. /input/ieee-fe-with-some-eda/remove_features.pkl')
 remove_features = list(remove_features['features_to_remove'].values)
 print('Shape control:', train_df.shape, test_df.shape )<feature_engineering>
clf_log_reg.predict_proba(x_val )
nans_groups = {}
temp_df = train_df.isna()
temp_df2 = test_df.isna()
nans_df = pd.concat([temp_df, temp_df2])
 for col in list(nans_df):
cur_group = nans_df[col].sum()
if cur_group>0:
try:
nans_groups[cur_group].append(col)
 except:
nans_groups[cur_group]=[col]
add_category = []
for col in nans_groups:
if len(nans_groups[col])>1:
train_df['nan_group_'+str(col)] = np.where(temp_df[nans_groups[col]].sum(axis=1)>0,1,0 ).astype(np.int8)
 test_df['nan_group_'+str(col)] = np.where(temp_df2[nans_groups[col]].sum(axis=1)>0,1,0 ).astype(np.int8)
 add_category.append('nan_group_'+str(col))
del temp_df, temp_df2, nans_df, nans_groups<load_pretrained>
clf_log_reg.get_params()
categorical_features = ['ProductCD','M4',
'card1','card2','card3','card4','card5','card6',
'addr1','addr2','dist1','dist2',
'P_emaildomain','R_emaildomain',
]
o_trans = pd.concat([pd.read_pickle('.. /input/ieee-data-minification/train_transaction.pkl'),
pd.read_pickle('.. /input/ieee-data-minification/test_transaction.pkl')])
 o_ident = pd.concat([pd.read_pickle('.. /input/ieee-data-minification/train_identity.pkl'),
pd.read_pickle('.. /input/ieee-data-minification/test_identity.pkl')])
 o_trans = o_trans.merge(o_ident, on=['TransactionID'], how='left')
 o_trans = o_trans[['TransactionID'] + categorical_features]
o_features = categorical_features.copy()
categorical_features = [col+'_cat' for col in categorical_features]
o_trans.columns = ['TransactionID'] + categorical_features
del o_ident
temp_df = train_df[['TransactionID']]
temp_df = temp_df.merge(o_trans, on=['TransactionID'], how='left')
 del temp_df['TransactionID']
train_df = pd.concat([train_df, temp_df], axis=1)
 temp_df = test_df[['TransactionID']]
temp_df = temp_df.merge(o_trans, on=['TransactionID'], how='left')
 del temp_df['TransactionID']
test_df = pd.concat([test_df, temp_df], axis=1)
 del temp_df, o_trans
for col in o_features:
if train_df[col].equals(train_df[col+'_cat']):
print('No transformation(keep only categorical)', col)
 del train_df[col], test_df[col]
col = col+'_cat'
train_df[col] = train_df[col].fillna(-999)
 test_df[col] = test_df[col].fillna(-999)
 categorical_features += add_category<feature_engineering>
clf_log_reg.score(x_val,y_val )
total_items = len(train_df)
 keep_cols = [TARGET,'C3_fq_enc']
for col in list(train_df):
if train_df[col].dtype.name!='category':
cur_dominator = list(train_df[col].fillna(-999 ).value_counts())[0]
if(cur_dominator/total_items > 0.85)and(col not in keep_cols):
cur_dominator = train_df[col].fillna(-999 ).value_counts().index[0]
print('Column:', col, ' | Dominator:', cur_dominator)
 train_df[col] = np.where(train_df[col].fillna(-999)==cur_dominator,1,0)
 test_df[col] = np.where(test_df[col].fillna(-999)==cur_dominator,1,0)
 train_df[col] = train_df[col].fillna(-999 ).astype(int)
 test_df[col] = test_df[col].fillna(-999 ).astype(int)
 if col not in categorical_features:
categorical_features.append(col)
 categorical_features +=['D8_not_same_day','TransactionAmt_check']<drop_column>
test_df = imputer_null(test_df)
 test_df = one_hot(test_df)
 test_df = add_family_feature(test_df)
 test_df = normalize_feature(test_df)
 test_df.head()
restore_features = [
'uid','uid2','uid3','uid4','uid5','bank_type',
]
for col in restore_features:
categorical_features.append(col)
 remove_features.remove(col )<define_variables>
test_df.drop(columns=['Ticket'],axis=1,inplace=True)
 test_pred = clf_log_reg.predict(test_df)
 test_pred_df = pd.DataFrame(test_pred,columns=['Survived'])
 test_pred_df
y_test = pd.concat([test_data[['PassengerId']],test_pred_df],axis=1)
 y_test.head()
cols_sum = {}
bad_types = ['datetime64[ns]', 'category','object']
for col in list(train_df):
if train_df[col].dtype.name not in bad_types:
cur_col = train_df[col].values
cur_sum = cur_col.mean()
try:
cols_sum[cur_sum].append(col)
 except:
cols_sum[cur_sum] = [col]
cols_sum = {k:v for k,v in cols_sum.items() if len(v)>1}
for k,v in cols_sum.items() :
for col in v[1:]:
if train_df[v[0]].equals(train_df[col]):
print('Duplicate', col)
 del train_df[col], test_df[col]<categorify>
val_prob = np.array(clf_log_reg.predict_proba(x_val))
print(val_prob[:,1] )
for col in list(train_df):
if train_df[col].dtype=='O':
print(col)
 train_df[col] = train_df[col].fillna('unseen_before_label')
 test_df[col] = test_df[col].fillna('unseen_before_label')
 train_df[col] = train_df[col].astype(str)
 test_df[col] = test_df[col].astype(str)
 le = LabelEncoder()
le.fit(list(train_df[col])+list(test_df[col]))
train_df[col] = le.transform(train_df[col])
 test_df[col] = le.transform(test_df[col])
 elif col in categorical_features:
train_df[col] = train_df[col].astype(float ).fillna(-999)
 test_df[col] = test_df[col].astype(float ).fillna(-999)
 le = LabelEncoder()
le.fit(list(train_df[col])+list(test_df[col]))
train_df[col] = le.transform(train_df[col])
 test_df[col] = le.transform(test_df[col] )<init_hyperparams>
val_score = clf_log_reg.score(x_val,y_val)
 print("Score of Validation set is :" "{:.2f}".format(val_score*100))
features_columns = [col for col in list(train_df)if col not in remove_features]
categorical_features = [col for col in categorical_features if col in features_columns]
if not LOCAL_TEST:
train_df = reduce_mem_usage(train_df)
 test_df = reduce_mem_usage(test_df)
 train_df = train_df[['TransactionID','DT_M',TARGET]+features_columns]
test_df = test_df[['TransactionID','DT_M',TARGET]+features_columns]
gc.collect()<find_best_model_class>
roc_auc = "{:.2f}".format(roc_auc_score(y_val,val_prob[:,1])*100)
 print(roc_auc )
if LOCAL_TEST:
test_predictions = make_predictions(train_df, test_df, features_columns, TARGET, cat_params,
NFOLDS=4, kfold_mode='grouped')
 else:
NFOLDS = 6
folds = GroupKFold(n_splits=NFOLDS)
 X,y = train_df[features_columns], train_df[TARGET]
P,P_y = test_df[features_columns], test_df[TARGET]
split_groups = train_df['DT_M']
train_df = train_df[['TransactionID',TARGET]]
test_df = test_df[['TransactionID',TARGET]]
test_df['prediction'] = 0
gc.collect()
oof = np.zeros(len(train_df))
predictions = np.zeros(len(test_df))
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y, groups=split_groups)) :
print('Fold:',fold_)
 estimator = CatBoostClassifier(**cat_params)
 estimator.fit(
 X.iloc[trn_idx,:],y[trn_idx],
eval_set=(X.iloc[val_idx,:], y[val_idx]),
cat_features=categorical_features,
use_best_model=True,
verbose=True)
 oof_preds = estimator.predict_proba(X.iloc[val_idx,:])[:,1]
oof[val_idx] =(oof_preds - oof_preds.min())/(oof_preds.max() - oof_preds.min())
 test_df['prediction'] += estimator.predict_proba(P)[:,1]/NFOLDS
del estimator
gc.collect()
print('OOF AUC:', metrics.roc_auc_score(y, oof))<save_to_csv>
from sklearn.metrics import roc_curve
if not LOCAL_TEST:
test_df['isFraud'] = test_df['prediction']
test_df[['TransactionID','isFraud']].to_csv('submission.csv', index=False )<set_options>
y_test.to_csv("logistic_submission.csv",index=False )
warnings.filterwarnings('ignore' )<init_hyperparams>
clf_svc = svm.NuSVC().fit(x_train,y_train )
def seed_everything(seed=0):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 def reduce_mem_usage(df, verbose=True):
numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
start_mem = df.memory_usage().sum() / 1024**2
for col in df.columns:
col_type = df[col].dtypes
if col_type in numerics:
c_min = df[col].min()
c_max = df[col].max()
if str(col_type)[:3] == 'int':
if c_min > np.iinfo(np.int8 ).min and c_max < np.iinfo(np.int8 ).max:
df[col] = df[col].astype(np.int8)
 elif c_min > np.iinfo(np.int16 ).min and c_max < np.iinfo(np.int16 ).max:
df[col] = df[col].astype(np.int16)
 elif c_min > np.iinfo(np.int32 ).min and c_max < np.iinfo(np.int32 ).max:
df[col] = df[col].astype(np.int32)
 elif c_min > np.iinfo(np.int64 ).min and c_max < np.iinfo(np.int64 ).max:
df[col] = df[col].astype(np.int64)
 else:
if c_min > np.finfo(np.float16 ).min and c_max < np.finfo(np.float16 ).max:
df[col] = df[col].astype(np.float16)
 elif c_min > np.finfo(np.float32 ).min and c_max < np.finfo(np.float32 ).max:
df[col] = df[col].astype(np.float32)
 else:
df[col] = df[col].astype(np.float64)
 end_mem = df.memory_usage().sum() / 1024**2
if verbose: print('Mem.usage decreased to {:5.2f} Mb({:.1f}% reduction)'.format(end_mem, 100 *(start_mem - end_mem)/ start_mem))
return df<split>
clf_svc.predict(x_val )
def make_predictions(tr_df, tt_df, features_columns, target, lgb_params, NFOLDS=2):
folds = GroupKFold(n_splits=NFOLDS)
 X,y = tr_df[features_columns], tr_df[target]
P,P_y = tt_df[features_columns], tt_df[target]
split_groups = tr_df['DT_M']
tt_df = tt_df[['TransactionID',target]]
predictions = np.zeros(len(tt_df))
oof = np.zeros(len(tr_df))
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y, groups=split_groups)) :
print('Fold:',fold_)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, vl_y = X.iloc[val_idx,:], y[val_idx]
print(len(tr_x),len(vl_x))
tr_data = lgb.Dataset(tr_x, label=tr_y)
 vl_data = lgb.Dataset(vl_x, label=vl_y)
 estimator = lgb.train(
 lgb_params,
tr_data,
valid_sets = [tr_data, vl_data],
verbose_eval = 200, 
)
 pp_p = estimator.predict(P)
 predictions += pp_p/NFOLDS
oof_preds = estimator.predict(vl_x)
 oof[val_idx] =(oof_preds - oof_preds.min())/(oof_preds.max() - oof_preds.min())
 if LOCAL_TEST:
feature_imp = pd.DataFrame(sorted(zip(estimator.feature_importance() ,X.columns)) , columns=['Value','Feature'])
 print(feature_imp)
 del tr_x, tr_y, vl_x, vl_y, tr_data, vl_data
gc.collect()
tt_df['prediction'] = predictions
print('OOF AUC:', metrics.roc_auc_score(y, oof))
if LOCAL_TEST:
print('Holdout AUC:', metrics.roc_auc_score(tt_df[TARGET], tt_df['prediction']))
return tt_df 
<define_variables>
clf_svc.score(x_val,y_val )
SEED = 42
seed_everything(SEED)
 LOCAL_TEST = False
TARGET = 'isFraud'
START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d' )<init_hyperparams>
test_pred = clf_svc.predict(test_df)
 test_pred_df = pd.DataFrame(test_pred,columns=['Survived'])
 test_pred_df
y_test = pd.concat([test_data[['PassengerId']],test_pred_df],axis=1)
 y_test.head()
lgb_params = {
'objective':'binary',
'boosting_type':'gbdt',
'metric':'auc',
'n_jobs':-1,
'learning_rate':0.01,
'num_leaves': 2**8,
'max_depth':-1,
'tree_learner':'serial',
'colsample_bytree': 0.5,
'subsample_freq':1,
'subsample':0.7,
'n_estimators':800,
'max_bin':255,
'verbose':-1,
'seed': SEED,
'early_stopping_rounds':100,
}<load_pretrained>
y_test.to_csv("svc.submission.csv",index=False )
print('Load Data')
 if LOCAL_TEST:
train_df = pd.read_pickle('.. /input/ieee-fe-for-local-test/train_df.pkl')
 test_df = pd.read_pickle('.. /input/ieee-fe-for-local-test/test_df.pkl')
 else:
train_df = pd.read_pickle('.. /input/ieee-fe-with-some-eda/train_df.pkl')
 test_df = pd.read_pickle('.. /input/ieee-fe-with-some-eda/test_df.pkl')
 remove_features = pd.read_pickle('.. /input/ieee-fe-with-some-eda/remove_features.pkl')
 remove_features = list(remove_features['features_to_remove'].values)
 print('Shape control:', train_df.shape, test_df.shape )<categorify>
clf_nb = GaussianNB().fit(x_train,y_train)
 clf_nb.predict(x_val )
features_columns = [col for col in list(train_df)if col not in remove_features]
if not LOCAL_TEST:
train_df = reduce_mem_usage(train_df)
 test_df = reduce_mem_usage(test_df )<predict_on_test>
clf_nb.score(x_val,y_val )
if LOCAL_TEST:
lgb_params['learning_rate'] = 0.01
lgb_params['n_estimators'] = 10000
lgb_params['early_stopping_rounds'] = 100
test_predictions = make_predictions(train_df, test_df, features_columns, TARGET, lgb_params, NFOLDS=4)
 else:
lgb_params['learning_rate'] = 0.007
lgb_params['n_estimators'] = 10000
lgb_params['early_stopping_rounds'] = 100
test_predictions = make_predictions(train_df, test_df, features_columns, TARGET, lgb_params, NFOLDS=6 )<save_to_csv>
y_test = clf_nb.predict(test_df)
 y_test
if not LOCAL_TEST:
test_predictions['isFraud'] = test_predictions['prediction']
test_predictions[['TransactionID','isFraud']].to_csv('submission.csv', index=False )<prepare_x_and_y>
y_pred_df = pd.DataFrame(y_test,columns=['Survived'])
 test_data = pd.concat([test_data[['PassengerId']],y_pred_df],axis=1)
 test_data.head()
train, test = amazon()
print(train.shape, test.shape)
 target = "ACTION"
col4train = [x for x in train.columns if x not in [target, "ROLE_TITLE"]]
y = train[target].values<import_modules>
test_data.to_csv("naive_bayes_submission.csv",index=False )
def get_model() :
params = {
"n_estimators":300,
"n_jobs": 3,
"random_state":5436,
}
return ExtraTreesClassifier(**params)
 def validate_model(model, data):
skf = StratifiedKFold(n_splits=5, random_state = 4141, shuffle = True)
 stats = cross_validate(
 model, data[0], data[1],
groups=None, scoring='roc_auc',
cv=skf, n_jobs=None, return_train_score = True 
)
 stats = pd.DataFrame(stats)
 return stats.describe().transpose()
def transform_dataset(train, test, func, func_params = {}):
dataset = pd.concat([train, test], ignore_index = True)
 dataset = func(dataset, **func_params)
 if isinstance(dataset, pd.DataFrame):
new_train = dataset.iloc[:train.shape[0],:].reset_index(drop = True)
 new_test = dataset.iloc[train.shape[0]:,:].reset_index(drop = True)
 else:
new_train = dataset[:train.shape[0]]
new_test = dataset[train.shape[0]:]
return new_train, new_test<prepare_x_and_y>
clf_dt = tree.DecisionTreeClassifier(max_depth=3,min_samples_split=15,min_samples_leaf=3,random_state=1 ).fit(x_train,y_train)
 clf_dt.predict(x_val)
new_train, new_test = transform_dataset(
 train[col4train], test[col4train],
assign_rnd_integer, {"number_of_times":5} 
)
 print(new_train.shape, new_test.shape)
 new_train.head(5 )<train_model>
clf_dt.score(x_val,y_val )
validate_model(
 model = get_model() ,
data = [new_train.values, y]
)<train_model>
clf_dt.get_params()
new_train, new_test = transform_dataset(
 train[col4train], test[col4train],
assign_rnd_integer, {"number_of_times":1} 
)
 print(new_train.shape, new_test.shape)
 validate_model(
 model = get_model() ,
data = [new_train.values, y]
)<train_model>
y_test = clf_dt.predict(test_df)
 y_test = pd.DataFrame(y_test,columns=['Survived'])
 y_test = pd.concat([test_data[['PassengerId']],y_test],axis=1)
 y_test
new_train, new_test = transform_dataset(
 train[col4train], test[col4train],
assign_rnd_integer, {"number_of_times":10} 
)
 print(new_train.shape, new_test.shape)
 validate_model(
 model = get_model() ,
data = [new_train.values, y]
)<categorify>
y_test.to_csv("dt_submission.csv",index=False )
def one_hot(dataset):
ohe = OneHotEncoder(sparse=True, dtype=np.float32, handle_unknown='ignore')
 return ohe.fit_transform(dataset.values )<prepare_x_and_y>
rf = RandomForestClassifier(n_estimators=200,max_depth=3,min_samples_split=5,random_state=1,oob_score=True)
 clf_rf = rf.fit(x_train,y_train)
 clf_rf
new_train, new_test = transform_dataset(
 train[col4train], test[col4train],
one_hot)
 print(new_train.shape, new_test.shape )<train_model>
clf_rf.predict(x_val )
validate_model(
 model = get_model() ,
data = [new_train, y]
)<feature_engineering>
clf_rf.score(x_val,y_val )
def extract_col_interaction(dataset, col1, col2, tfidf = True):
data = dataset.groupby([col1])[col2].agg(lambda x: " ".join(list([str(y)for y in x])))
 if tfidf:
vectorizer = TfidfVectorizer(tokenizer=lambda x: x.split(" "))
else:
vectorizer = CountVectorizer(tokenizer=lambda x: x.split(" "))
data_X = vectorizer.fit_transform(data)
 dim_red = TruncatedSVD(n_components=1, random_state = 5115)
 data_X = dim_red.fit_transform(data_X)
 result = pd.DataFrame()
result[col1] = data.index.values
result[col1+"_{}_svd".format(col2)] = data_X.ravel()
return result
def get_col_interactions_svd(dataset, tfidf = True):
new_dataset = pd.DataFrame()
for col1,col2 in itertools.permutations(dataset.columns, 2):
data = extract_col_interaction(dataset, col1,col2, tfidf)
 col_name = [x for x in data.columns if "svd" in x][0]
new_dataset[col_name] = dataset[[col1]].merge(data, on = col1, how = 'left')[col_name]
return new_dataset<train_model>
y_test = clf_rf.predict(test_df)
 y_test = pd.DataFrame(y_test,columns=['Survived'])
 y_pred = pd.concat([test_data[['PassengerId']],y_test],axis=1)
 y_pred
validate_model(
 model = get_model() ,
data = [new_train.values, y]
)<merge>
y_pred.to_csv("rf_submission.csv",index=False )