Kaggle competition: Titanic - Machine Learning from Disaster
def return_chunk_indices(start, end, nrows, chunks=3):
'Maps the indices to chunk indices for data loading'
chunk_size =(nrows//chunks)
 indices = []
start_chunk = start // chunk_size
end_chunk =(end-1)// chunk_size
start_chunk_start = start - chunk_size * start_chunk
end_chunk_end = end - chunk_size * end_chunk
start_chunk_end = chunk_size if end_chunk != start_chunk else end_chunk_end
end_chunk_start = 0 if end_chunk != start_chunk else start_chunk_start
indices.append(( start_chunk+1, start_chunk_start, start_chunk_end))
if start_chunk != end_chunk:
for i in range(end_chunk - start_chunk - 1):
indices.append(( start_chunk + i + 2, 0, chunk_size))
indices.append(( end_chunk+1, end_chunk_start, end_chunk_end))
return indices<define_variables>
dataset = pd.read_csv('.. /input/train.csv' )
%%time
ALL_FEATURES = [
'repeat_c', 'tagF', 'tagS', 'tagL', 'tagT', 'response_time', 'prior_question_elapsed_time',
'up_mean', 'up_count', 'uq_per_hr', 'uwrong_sum', 'lec_recent', 'pqet_mean', 'seen_ratio',
'tmed', 'up_recency', 'ts_recency_10', 'ts_recency_5', 'timestamp', 'task_container_id',
'content_c', 'che_sum', 'seen_exp_when_wrong', 'seen_exp_when_right', 'sessions', 'sess_event_count',
'pqetmr_10', 'uf_bundle', 'u_mean', 'ummr_10', 'rt_per_task', 'c_mean', 'c_std', 'h_mean', 'uph_mean',
'wrong_et_med', 'right_et_med'
]
CORE = ['repeat_c', 'tagF', 'tagS', 'tagL', 'response_time', 'up_mean', 'up_count', 'pqet_mean',
'seen_ratio', 'tmed', 'up_recency', 'ts_recency_5', 'content_c', 'pqetmr_10', 'u_mean',
'rt_per_task', 'c_mean', 'c_std', 'h_mean', 'ts_recency_10', 'uph_mean']
N_FEATURES = 30
BATCH_SIZE = int(2.5e7)
 STRIDE = int(1e7)
 HOLD_OUT = int(2.5e6)
 models = []
COL_SAMPLING = False
ALREADY_TRAINED = 8
TRAIN_FOR = 0
ITERATIVE_TRAIN = False
OOF_VALIDATE = False
N_ROUNDS = 3000
LOC1 = ".. /input/riiid-final-model-inputs/model_train_c1.feather"
LOC2 = ".. /input/riiid-final-model-inputs/model_train_c2.feather"
LOC3 = ".. /input/riiid-final-model-inputs/model_train_c3.feather"
SIZE1 = len(pd.read_feather(LOC1, columns=['answered_correctly']))
SIZE2 = len(pd.read_feather(LOC2, columns=['answered_correctly']))
SIZE3 = len(pd.read_feather(LOC3, columns=['answered_correctly']))
N_ROWS = SIZE1 + SIZE2 + SIZE3
CHUNKS =(( N_ROWS - BATCH_SIZE - HOLD_OUT)// STRIDE)+ 1
if TRAIN_FOR is None:
TRAIN_FOR = CHUNKS - ALREADY_TRAINED
assert TRAIN_FOR + ALREADY_TRAINED <= CHUNKS
if ALREADY_TRAINED:
OOF = np.load(".. /input/riiid-final-model-inputs/OOF.npy")
 for j in range(ALREADY_TRAINED):
model = lgb.Booster(model_file=f".. /input/riiid-final-model-inputs/trained_model_c{j+1}.txt")
 model.save_model(f"trained_model_c{j+1}.txt")
 models.append(model)
 print(f"Successfully loaded {len(models)} model(s)!")
 if TRAIN_FOR:
if not ALREADY_TRAINED:
print("Beginning Model Training from Scratch!")
 OOF = np.arange(N_ROWS)
 if ITERATIVE_TRAIN and ALREADY_TRAINED:
pre_model = model
else:
pre_model = None
print(f"{BATCH_SIZE} rows would be used for {CHUNKS} model(s)!", end=' ')
 print(f"{TRAIN_FOR} model(s)would be trained for {N_ROUNDS} rounds!")
 print(f"The models would {'BE' if ITERATIVE_TRAIN else 'NOT BE'} iteratively built!")
 print(f"Col sampling has been {'ENABLED' if COL_SAMPLING else 'DISABLED'}!")
 print(f"{HOLD_OUT + N_ROWS -(( CHUNKS - 1)* STRIDE + BATCH_SIZE)} rows goes straight to OOF!")
 print("Space Req.For One Chunk: {:.2f} GB({})".format(
(N_FEATURES + 1 if COL_SAMPLING else len(ALL_FEATURES)) * BATCH_SIZE * 64 / 8e+9, 'float64'))
for j in range(ALREADY_TRAINED, ALREADY_TRAINED + TRAIN_FOR):
front, rear = j * STRIDE, j * STRIDE + BATCH_SIZE
print(f"
Beginning chunk {j + 1}/{ALREADY_TRAINED + TRAIN_FOR}! Loading the Feather File to Memory => ")
 if COL_SAMPLING:
FEATURES =(CORE + np.random.choice(list(set(ALL_FEATURES)- set(CORE)) ,
size=(N_FEATURES - len(CORE)) ,
replace=False ).tolist())
 print(f"Selected Features({N_FEATURES}/{len(ALL_FEATURES)}): {list(set(FEATURES)- set(CORE)) }")
 cat_cols = np.intersect1d(['tagF', 'tagS', 'tagT', 'tagL'], FEATURES ).tolist()
COLUMNS = ['user_id', *FEATURES, 'answered_correctly']
if 'timestamp' not in COLUMNS:
COLUMNS += ['timestamp']
else:
FEATURES = ALL_FEATURES
COLUMNS = ['user_id', *FEATURES, 'answered_correctly']
cat_cols = ['tagF', 'tagS', 'tagT', 'tagL']
print(f"Slicing from {front} to {rear}!")
 data = pd.DataFrame()
for file, start, end in return_chunk_indices(front, rear, nrows=N_ROWS):
data = pd.concat([
data, 
(pd.read_feather(f".. /input/riiid-final-model-inputs/model_train_c{file}.feather", columns=COLUMNS)
.iloc[start: end])
 ])
 data.index = range(front, rear)
 gc.collect()
time.sleep(3)
 print("Generating train/val Masks for the data...")
 mask = generate_train_val(data, return_mask=True, tp=0.95, dyn_p=True ).values.astype(bool)
 print("Done generating masks! Saving to intermediate train/val files.. ")
 OOF = np.setdiff1d(OOF, data.index[mask])
 data.drop(['user_id'], axis=1, inplace=True)
 gc.collect()
time.sleep(3)
 data.loc[mask].reset_index(drop=True ).to_feather("train_intermediate.feather")
 data.loc[~mask].reset_index(drop=True ).to_feather("val_intermediate.feather")
 del data, mask
gc.collect()
time.sleep(3)
 print("Done saving! Beginning logic for LGB dataset creation.. ")
 chunk_per = 0.025
tr_data = pd.read_feather("train_intermediate.feather")
 tr_data = tr_data[FEATURES + ['answered_correctly']]
tr_result = np.empty(shape=(len(tr_data), len(FEATURES)+ 1), dtype='float64')
 step = int(len(tr_data)* chunk_per)
 end =(len(tr_data)// step)+ 1
for i in tqdm.tqdm(range(1, end + 1)) :
tr_result[(i - 1)* step: i * step] = tr_data.iloc[:step]
tr_data = tr_data.iloc[step:]
gc.collect()
time.sleep(3)
 del tr_data
gc.collect()
! rm./train_intermediate.feather
time.sleep(3)
 tr_data = lgb.Dataset(
 tr_result[:, :-1], label=tr_result[:, -1], feature_name=FEATURES,
categorical_feature=cat_cols, free_raw_data=not ITERATIVE_TRAIN)
 tr_data.construct()
del tr_result
gc.collect()
time.sleep(2)
 vl_data = pd.read_feather("./val_intermediate.feather")
 vl_data = vl_data[FEATURES + ['answered_correctly']]
vl_result = np.empty(shape=(len(vl_data), len(FEATURES)+ 1), dtype='float64')
 step = int(len(vl_data)* chunk_per)
 end =(len(vl_data)// step)+ 1
for i in tqdm.tqdm(range(1, end + 1)) :
vl_result[(i - 1)* step: i * step] = vl_data.iloc[:step]
vl_data = vl_data.iloc[step:]
gc.collect()
time.sleep(3)
 del vl_data
gc.collect()
! rm./val_intermediate.feather
time.sleep(3)
 vl_data = lgb.Dataset(
 vl_result[:, :-1], label=vl_result[:, -1], feature_name=FEATURES,
categorical_feature=cat_cols, reference=tr_data,
free_raw_data=not ITERATIVE_TRAIN)
 vl_data.construct()
del vl_result
gc.collect()
time.sleep(2)
 print("Done generating LGB datasets! Starting training.. ")
 model = lgb.train(
 params={'metric': 'auc', 'objective': 'binary',
'num_leaves': 200, 'learning_rate': 0.075},
train_set=tr_data,
feature_name=FEATURES,
categorical_feature=cat_cols,
num_boost_round=N_ROUNDS,
valid_sets=[tr_data, vl_data],
init_model=pre_model,
early_stopping_rounds=50,
verbose_eval=50 
)
 del tr_data, vl_data
gc.collect()
print(f"Done training chunk {j + 1}!")
 model.save_model(f"trained_model_c{j + 1}.txt")
 models.append(model)
 if ITERATIVE_TRAIN:
pre_model = model
if OOF_VALIDATE:
print(f"
We would be evaluating the model on {HOLD_OUT} rows out of {len(OOF)} OOF rows.")
 data = pd.read_feather(LOC3 ).iloc[-HOLD_OUT:]
actual = data['answered_correctly']
data.drop(['user_id', 'answered_correctly'], axis=1, inplace=True)
 preds = np.zeros(shape=(len(actual), len(models)))
 print("
Individual Model's OOF Scores:")
 for i in range(len(models)) :
FEATURES = models[i].feature_name()
cat_cols = np.intersect1d(['tagF', 'tagS', 'tagT', 'tagL'], FEATURES)
 preds[:, i] = models[i].predict(data[FEATURES], categorical_feature=cat_cols)
 print(f"\tModel
print(f"
The Ensemble's Score: {roc_auc_score(actual, preds.mean(1)) :.4f}")
 del data, actual, preds
gc.collect()
if ITERATIVE_TRAIN:
models = models[-1:]
np.save("OOF.npy", OOF)
 print(f"
Number of Models: {len(models)}
" )<load_pretrained>
features= [ 'Pclass','Sex','Age','SibSp','Parch','Fare','Embarked']
x = dataset[features]
y = dataset['Survived']
class ensemble(object):
def __init__(self, models, weights=None, treelite=True):
self.n_models = len(models)
 self.models = models
self.weights = [1 / self.n_models] * self.n_models if not weights else weights
self.cat_cols = ['tagF', 'tagS', 'tagL', 'tagT']
self.treelite = treelite
self.feats = ['repeat_c', 'tagF', 'tagS', 'tagL', 'tagT', 'response_time', 'prior_question_elapsed_time',
'up_mean', 'up_count', 'uq_per_hr', 'uwrong_sum', 'lec_recent', 'pqet_mean', 'seen_ratio',
'tmed', 'up_recency', 'ts_recency_10', 'ts_recency_5', 'timestamp', 'task_container_id',
'content_c', 'che_sum', 'seen_exp_when_wrong', 'seen_exp_when_right', 'sessions',
'sess_event_count', 'pqetmr_10', 'uf_bundle', 'u_mean', 'ummr_10', 'rt_per_task', 'c_mean',
'c_std', 'h_mean', 'uph_mean', 'wrong_et_med', 'right_et_med']
if not self.treelite:
assert len(np.setdiff1d(self.feats, self.models[0].feature_name())) == 0
def __getattr__(self, attr):

 return getattr(self.models[0], attr)
 def feature_name(self):
return self.feats
def predict(self, x, **kwargs):
if not self.treelite:
return self.predict_lgb(x[self.feats])
 else:
return self.predict_treelite(x[self.feats].values)
 def predict_treelite(self, x):
X = treelite_runtime.Batch.from_npy2d(x)
 pred = np.zeros(len(x))
for m, w in zip(self.models, self.weights):
pred += m.predict(X)* w
return pred
def predict_lgb(self, x):
pred = np.zeros(len(x))
for m, w in zip(self.models, self.weights):
pred += m.predict(x, categorical_feature=self.cat_cols)* w
return pred<define_variables>
x.isnull().sum()
%%time
start_time = time.time()
if not os.path.exists(".. /input/col-sampled-train-dataset/lgb_pred_1.npy"):
models = [models[3], models[6]]
BATCH_SIZE = int(3.0e7)
 CHUNKS = list(range(0, N_ROWS, BATCH_SIZE))
print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Predictions will be chunked for", len(CHUNKS), "Chunks!")
 print(CHUNKS)
 for j, front in enumerate(CHUNKS):
rear = front + BATCH_SIZE
print(f"
Beginning chunk {j+1}! Loading the Feather File to Memory => ")
 print(f"Slicing from {front} to {rear}!")
 data = pd.DataFrame()
for file, start, end in return_chunk_indices(front, rear, nrows=N_ROWS):
file = f".. /input/riiid-final-model-inputs/model_train_c{file}.feather"
if not os.path.exists(file):
continue
data = pd.concat([data, pd.read_feather(file ).iloc[start: end]])
 gc.collect()
time.sleep(2)
 data = data[LGB_COLS]
data_shape = data.shape
print(f"Time Elapsed: {time.time() - start_time:10.2f} s |", end=' ')
 print(f"Done loading! Data Dimensions: {data_shape}")
 print("Beginning logic for treelite batch dataset creation.. ")
 gc.collect()
time.sleep(2)
 chunk_per = 0.025
darray = np.empty(shape=(data_shape[0], data_shape[1]), dtype='float64')
 step = int(data_shape[0] * chunk_per)
 end =(data_shape[0] // step)+ 1
for i in tqdm.tqdm(range(1, end + 1)) :
darray[(i - 1)* step: i * step] = data.iloc[:step]
data = data.iloc[step:]
gc.collect()
time.sleep(3)
 del data
gc.collect()
time.sleep(3)
 darray = treelite_runtime.Batch.from_npy2d(darray)
 gc.collect()
time.sleep(3)
 lgb_pred = np.zeros(shape=data_shape[0], dtype='float32')
 print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Making Predictions using Treelite models =>")
 for k, model in enumerate(models):
lgb_pred = lgb_pred + model.predict(darray)
 print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Done with model
lgb_pred = lgb_pred / len(models)
 print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Done with Chunk {j+1}! Saving predictions to Disk!")
 np.save(f"lgb_pred_{j+1}.npy", lgb_pred)
 del darray, lgb_pred
gc.collect()
else:
print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Copying LGB pred numpy arrays back to Disk!")
 for i in glob.glob(".. /input/col-sampled-train-dataset/lgb_pred_*"):
! cp {i} {i.split("/")[-1]}
print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Done copying to Disk!" )<define_variables>
x['Age'] = x['Age'].fillna(x['Age'].median())
 x['Embarked']= x['Embarked'].fillna(x['Embarked'].value_counts().index[0] )
%%time
start_time = time.time()
if not os.path.exists(".. /input/col-sampled-train-dataset/lgb2_pred_1.npy"):
models = [models[1], models[4]]
BATCH_SIZE = int(3.0e7)
 CHUNKS = list(range(0, N_ROWS, BATCH_SIZE))
print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Predictions will be chunked for", len(CHUNKS), "Chunks!")
 print(CHUNKS)
 for j, front in enumerate(CHUNKS):
rear = front + BATCH_SIZE
print(f"
Beginning chunk {j+1}! Loading the Feather File to Memory => ")
 print(f"Slicing from {front} to {rear}!")
 data = pd.DataFrame()
for file, start, end in return_chunk_indices(front, rear, nrows=N_ROWS):
file = f".. /input/riiid-final-model-inputs/model_train_c{file}.feather"
if not os.path.exists(file):
continue
data = pd.concat([data, pd.read_feather(file ).iloc[start: end]])
 gc.collect()
time.sleep(2)
 data = data[LGB_COLS]
data_shape = data.shape
print(f"Time Elapsed: {time.time() - start_time:10.2f} s |", end=' ')
 print(f"Done loading! Data Dimensions: {data_shape}")
 print("Beginning logic for treelite batch dataset creation.. ")
 gc.collect()
time.sleep(2)
 chunk_per = 0.025
darray = np.empty(shape=(data_shape[0], data_shape[1]), dtype='float64')
 step = int(data_shape[0] * chunk_per)
 end =(data_shape[0] // step)+ 1
for i in tqdm.tqdm(range(1, end + 1)) :
darray[(i - 1)* step: i * step] = data.iloc[:step]
data = data.iloc[step:]
gc.collect()
time.sleep(3)
 del data
gc.collect()
time.sleep(3)
 darray = treelite_runtime.Batch.from_npy2d(darray)
 gc.collect()
time.sleep(3)
 lgb_pred = np.zeros(shape=data_shape[0], dtype='float32')
 print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Making Predictions using Treelite models =>")
 for k, model in enumerate(models):
lgb_pred = lgb_pred + model.predict(darray)
 print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Done with model
lgb_pred = lgb_pred / len(models)
 print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Done with Chunk {j+1}! Saving predictions to Disk!")
 np.save(f"lgb2_pred_{j+1}.npy", lgb_pred)
 del darray, lgb_pred
gc.collect()
else:
print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Copying LGB pred numpy arrays back to Disk!")
 for i in glob.glob(".. /input/col-sampled-train-dataset/lgb_pred_*"):
! cp {i} {i.split("/")[-1]}
print(f"Time Elapsed: {time.time() - start_time:10.2f} s | Done copying to Disk!" )<create_dataframe>
x.isnull().sum()
%%time
data = pd.read_feather(
 ".. /input/riiid-train-data-multiple-formats/riiid_train.feather",
columns=['content_id', 'content_type_id'])
 data = data.loc[~data['content_type_id']].iloc[:N_ROWS]
data = data.merge(
 ques[['question_id', 'part']].set_index("question_id"),
left_on=['content_id'], right_index=True, how='left')
 data.drop(['content_type_id'], axis=1, inplace=True)
 data.reset_index(drop=True, inplace=True)
 data.to_feather("./intermediate_train.feather")
 del data
gc.collect()
data = pd.DataFrame()
for LOC in [LOC1, LOC2, LOC3]:
data = pd.concat([
data, 
(pd.read_feather(LOC, columns=['user_id', 'task_container_id', 'content_c', 'c_mean', 'h_mean',
'answered_correctly', 'ummr_10']))
], axis=0)
 data.reset_index(drop=True, inplace=True)
 data['ummr_10_50'] = data['ummr_10'] > 0
data['h_mean_50'] = data['h_mean'] > 0.5
data['c_mean_50'] = data['c_mean'] > 0.5
data['c_mean_25'] = data['c_mean'] > 0.25
data['c_mean_75'] = data['c_mean'] > 0.75
data.drop(['ummr_10', 'c_mean', 'h_mean'], axis=1, inplace=True)
 data = pd.concat([
data, pd.read_feather("./intermediate_train.feather")
 ], axis=1)
 ! rm./intermediate_train.feather
lgb_pred = np.array([])
 for file in sorted(glob.glob(".. /input/col-sampled-train-dataset/lgb_pred_*")) :
lgb_pred = np.concatenate([lgb_pred, np.load(file)])
 lgb2_pred = np.array([])
 for file in sorted(glob.glob(".. /input/col-sampled-train-dataset/lgb2_pred_*")) :
lgb2_pred = np.concatenate([lgb2_pred, np.load(file)])
 assert len(lgb_pred)== len(lgb2_pred)
 lgb_pred =(lgb_pred + lgb2_pred)/ 2
del lgb2_pred
gc.collect()
data['lgb_pred'] = lgb_pred
data['lgb_75'] = data['lgb_pred'] > 0.75
data['lgb_50'] = data['lgb_pred'] > 0.5
data['lgb_25'] = data['lgb_pred'] > 0.25
del lgb_pred
gc.collect()
print(data.shape)
 print(data.columns )<data_type_conversions>
LE = LabelEncoder()
x['Sex'] = LE.fit_transform(x['Sex'])
 x['Embarked'] = LE.fit_transform(x['Embarked'] )
def df_to_dt_format(df):
for i in df.columns:
org = str(df[i].dtype)
 converted = org.lstrip("u")
 if org != converted:
converted = converted[:3] + str(int(converted.lstrip("int")) * 2)
 df[i] = df[i].astype(converted )<create_dataframe>
y.isnull().sum()
df_to_dt_format(data)
 data = dt.Frame(data )<define_variables>
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = 0.1,random_state =0 )
FTRL_COLS = [
'user_id', 'task_container_id', 'content_c', 'ummr_10_50', 'h_mean_50',
'c_mean_50', 'c_mean_25', 'c_mean_75', 'content_id', 'part', 'lgb_pred', 'lgb_75',
'lgb_50', 'lgb_25'
]
INTERACTIONS = None<train_model>
classifier = XGBClassifier(colsample_bylevel= 0.9,
colsample_bytree = 0.8,
gamma=0.99,
max_depth= 5,
min_child_weight= 1,
n_estimators= 10,
nthread= 4,
random_state= 2,
silent= True)
 classifier.fit(x_train,y_train)
 classifier.score(x_test,y_test )
%%time
ftrl = Ftrl(
 nepochs=1, interactions=INTERACTIONS,
alpha=0.005, double_precision=True, 
)
 ftrl.fit(data[:int(9.5e7), FTRL_COLS], data[:int(9.5e7), ['answered_correctly']] )<compute_train_metric>
test_data = pd.read_csv('.. /input/test.csv')
 test_x = test_data[features]
%%time
preds = ftrl.predict(data[int(9.5e7):, FTRL_COLS] ).to_pandas()
actual = data[int(9.5e7):, 'answered_correctly'].to_numpy()
print("Baseline Score to beat: {:.4f}".format(roc_auc_score(
 actual, data[int(9.5e7):, 'lgb_pred'].to_pandas() 
)))
 roc_auc_score(actual, preds )<choose_model_class>
test_x.isnull().sum()
model = ensemble(models, treelite=False)
 model, type(model.models[0] )<predict_on_test>
test_x['Age'] = test_x['Age'].fillna(test_x['Age'].median())
 test_x['Fare'] = test_x['Fare'].fillna(test_x['Fare'].median() )
if not os.path.exists(".. /input/treelite-converted-ensemble-8-models-25m/lgb_pred_final.npy"):
temp = pd.read_feather(LOC3 ).iloc[-(N_ROWS - int(9.5e7)) :][model.feature_name() ]
lgb_pred = model.predict(temp)
 del temp
gc.collect()
else:
lgb_pred = np.load(".. /input/treelite-converted-ensemble-8-models-25m/lgb_pred_final.npy" )<predict_on_test>
test_x.isnull().sum()
data[int(9.5e7):, 'lgb_pred'] = lgb_pred
data[int(9.5e7):, 'lgb_75'] = data[int(9.5e7):, dt.f.lgb_pred > 0.75]
data[int(9.5e7):, 'lgb_50'] = data[int(9.5e7):, dt.f.lgb_pred > 0.50]
data[int(9.5e7):, 'lgb_25'] = data[int(9.5e7):, dt.f.lgb_pred > 0.25]
preds = ftrl.predict(data[int(9.5e7):, FTRL_COLS])
 print("Baseline Score to beat: {:.4f}".format(roc_auc_score(
 actual, data[int(9.5e7):, 'lgb_pred'].to_pandas() 
)))
 roc_auc_score(data[int(9.5e7):, 'answered_correctly'].to_pandas() , preds )<set_options>
test_x['Sex'] = LE.fit_transform(test_x['Sex'])
 test_x['Embarked'] = LE.fit_transform(test_x['Embarked'] )
ol_ftrl = deepcopy(ftrl)
 ol_ftrl.alpha = 0.005<predict_on_test>
prediction = classifier.predict(test_x )
%%time
ol_preds = []
preds = []
BATCH_SIZE = 1000
for front in range(int(9.5e7), N_ROWS, BATCH_SIZE):
pred = ol_ftrl.predict(data[front:front+BATCH_SIZE, FTRL_COLS] ).to_list() [0]
ol_preds.append(pred)
 pred = ftrl.predict(data[front:front+BATCH_SIZE, FTRL_COLS] ).to_list() [0]
preds.append(pred)
 ol_ftrl.fit(data[front:front+BATCH_SIZE, FTRL_COLS], data[front:front+BATCH_SIZE, 'answered_correctly'] )<compute_test_metric>
output = pd.DataFrame({'PassengerId': test_data.PassengerId,'Survived': prediction})
 output.to_csv('submission.csv', index=False)
 output.head()