Kaggle competition: Outbrain Click Prediction
model = Model(input_layer, output_layer)
 model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])
 model.summary()<concatenate>
%matplotlib inline
x_train = np.append(x_train, [np.fliplr(x)for x in x_train], axis=0)
 y_train = np.append(y_train, [np.fliplr(x)for x in y_train], axis=0)
 x_train = np.append(x_train, [np.flipud(x)for x in x_train], axis=0)
 y_train = np.append(y_train, [np.flipud(x)for x in y_train], axis=0)
 x_valid = np.append(x_valid, [np.flipud(x)for x in x_valid], axis=0)
 y_valid = np.append(y_valid, [np.flipud(x)for x in y_valid], axis=0)
 x_valid = np.append(x_valid, [np.flipud(x)for x in x_valid], axis=0)
 y_valid = np.append(y_valid, [np.flipud(x)for x in y_valid], axis=0 )<train_model>
train = pd.read_csv('.. /input/clicks_train.csv',usecols=['ad_id', 'clicked'] )
early_stopping = EarlyStopping(patience=10, verbose=1)
 model_checkpoint = ModelCheckpoint("./keras.model", save_best_only=True, verbose=1)
 reduce_lr = ReduceLROnPlateau(factor=0.1, patience=5, min_lr=0.00001, verbose=1)
 epochs = 200
batch_size = 32
history = model.fit(x_train, y_train,
validation_data=[x_valid, y_valid],
epochs=epochs,
batch_size=batch_size,
callbacks=[early_stopping, model_checkpoint, reduce_lr] )<predict_on_test>
ad_train_likelehood = train.groupby('ad_id')['clicked'].agg(['count', 'sum', 'mean'] ).reset_index()
preds_valid = model.predict(x_valid ).reshape(-1, img_size_target, img_size_target)
 preds_valid = np.array([downsample(x)for x in preds_valid])
 y_valid_ori = np.array([train_df.loc[idx].masks for idx in ids_valid] )<compute_train_metric>
ad_train_likelehood['likelihood'] =(ad_train_likelehood['sum'] + 12*M)/(12 + ad_train_likelehood['count'])
 test = pd.read_csv(".. /input/clicks_test.csv")
 test = test.merge(ad_train_likelehood, how='left')
 test.likelihood.fillna(M, inplace=True)
<find_best_params><EOS> 
test.sort_values(['display_id','likelihood'], inplace=True, ascending=False)
 subm = test.groupby('display_id')['ad_id'].apply(lambda x: " ".join(map(str,x)) ).reset_index()
subm.to_csv("subm.csv", index=False )