Kaggle competition: TReNDS Neuroimaging
<SOS> metric: WMAE Kaggle data source: trends-neuroimaging<choose_model_class>
%matplotlib inline
def create_xlm(transformer_layer,random_seed,learning_rate):
tf.keras.backend.clear_session()
tf.random.set_seed(random_seed)
 with strategy.scope() :
model = create_model(transformer_layer,learning_rate)
 model.summary()
return model<choose_model_class>
sub_path = ".. /input/final-ensemble"
all_files = os.listdir(sub_path)
 all_files
Xlm = create_xlm(MODEL,1124234,1e-5 )<train_model>
concat_sub['m_max'] = concat_sub.iloc[:, 1:ncol].max(axis=1)
 concat_sub['m_min'] = concat_sub.iloc[:, 1:ncol].min(axis=1)
 concat_sub['m_median'] = concat_sub.iloc[:, 1:ncol].median(axis=1)
 concat_sub['m_mean'] = concat_sub.iloc[:, 1:ncol].mean(axis=1 )
callbacks = [tf.keras.callbacks.EarlyStopping(patience = 2,
monitor = 'val_loss',
restore_best_weights = True,
mode = 'min')]
steps_per_epoch = len(x_train)// BATCH_SIZE
history_xlm = Xlm.fit(train_dataset,
validation_data=valid_dataset,
steps_per_epoch=steps_per_epoch,
epochs = EPOCHS,
callbacks = callbacks)
<save_to_csv>
cutoff_lo = 0.8
cutoff_hi = 0.2
predictions_xlm = Xlm.predict(test_dataset)
 predictions = predictions_xlm
final = np.argmax(predictions, axis = 1)
 submission = pd.DataFrame()
submission['id'] = test['id']
submission['prediction'] = final.astype(np.int32)
 submission.to_csv('submission.csv', index = False )<install_modules>
concat_sub['Predicted'] = concat_sub['m_mean']
concat_sub[['Id','Predicted']].to_csv('stack_mean.csv',
index=False, float_format='%.6f' )
!pip install transformers==3.0.2<feature_engineering>
concat_sub['Predicted'] = concat_sub['m_median']
concat_sub[['Id','Predicted']].to_csv('stack_median.csv',
index=False, float_format='%.6f' )
os.environ["WANDB_API_KEY"] = "0"<import_modules>
concat_sub['Predicted'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1), 1,
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
0, concat_sub['m_median']))
concat_sub[['Id','Predicted']].to_csv('stack_pushout_median.csv',
index=False, float_format='%.6f' )
!pip install nlp 
<import_modules>
concat_sub['Predicted'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1),
concat_sub['m_max'],
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
concat_sub['m_min'],
concat_sub['m_mean']))
concat_sub[['Id','Predicted']].to_csv('stack_minmax_mean.csv',
index=False, float_format='%.6f' )
<train_model><EOS> 
concat_sub['Predicted'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1),
concat_sub['m_max'],
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
concat_sub['m_min'],
concat_sub['m_median']))
concat_sub[['Id','Predicted']].to_csv('stack_minmax_median.csv',
index=False, float_format='%.6f' )