Kaggle competition: Jane Street Market Prediction
<SOS> metric: JaneStreetPnl Kaggle data source: jane-street-market-prediction<init_hyperparams>
warnings.filterwarnings('ignore')
 tf.random.set_seed(42)
train_params = {
'n_splits': 5,
'n_epochs': 12,
'lr': 1e-3,
'base_lr': 1e-4,
'max_lr': 3e-3,
'step_factor': 6,
'train_batch_size': 32,
'train_image_size': 512,
'test_image_size': 512,
'test_batch_size': 32,
'accumulation_steps': 10,
}<install_modules>
train = pd.read_csv('/kaggle/input/jane-street-market-prediction/train.csv', nrows = 3)
 features = [c for c in train.columns if 'feature' in c]
<import_modules>
def create_mlp(num_columns, num_labels, hidden_units, dropout_rates, label_smoothing, learning_rate):
inp = tf.keras.layers.Input(shape =(num_columns,))
x = tf.keras.layers.BatchNormalization()(inp)
 x = tf.keras.layers.Dropout(dropout_rates[0] )(x)
 for i in range(len(hidden_units)) :
x = tf.keras.layers.Dense(hidden_units[i] )(x)
 x = tf.keras.layers.BatchNormalization()(x)
 x = tf.keras.layers.Activation(tf.keras.activations.swish )(x)
 x = tf.keras.layers.Dropout(dropout_rates[i+1] )(x)
 x = tf.keras.layers.Dense(num_labels )(x)
 out = tf.keras.layers.Activation('sigmoid' )(x)
 model = tf.keras.models.Model(inputs = inp, outputs = out)
 model.compile(optimizer = tf.keras.optimizers.Adam(learning_rate = learning_rate),
loss = tf.keras.losses.BinaryCrossentropy(label_smoothing = label_smoothing),
metrics = tf.keras.metrics.AUC(name = 'AUC'), 
)
 return model
sys.path.append('.. /input/efficientnet-my/' )<import_modules>
batch_size = 8192
hidden_units = [384, 896, 896, 394]
dropout_rates = [0.10143786981358652, 0.19720339053599725, 0.2703017847244654, 0.23148340929571917, 0.2357768967777311]
label_smoothing = 1e-2
learning_rate = 1e-4
Compose, HorizontalFlip, IAAAdditiveGaussianNoise, Normalize, OneOf,
RandomBrightness, RandomContrast, Resize, VerticalFlip, Rotate, ShiftScaleRotate,
RandomBrightnessContrast, OpticalDistortion, GridDistortion, ElasticTransform, Cutout 
)
<set_options>
num_models = 2
models = []
for i in range(num_models):
clf = create_mlp(len(features), 1, hidden_units, dropout_rates, label_smoothing, learning_rate)
 clf.load_weights(f'.. /input/js-nn-models/JSModel_{i}.hdf5')
 models.append(clf )
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 device<set_options>
f_mean = np.load('.. /input/js-nn-models/f_mean.npy' )
def seed_torch(seed=777):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
SEED = 777
seed_torch(SEED )<compute_test_metric>
env = janestreet.make_env()
env_iter = env.iter_test()
<compute_test_metric><EOS> 
opt_th = 0.5
for(test_df, pred_df)in tqdm(env_iter):
if test_df['weight'].item() > 0:
x_tt = test_df.loc[:, features].values
if np.isnan(x_tt[:, 1:].sum()):
x_tt[:, 1:] = np.nan_to_num(x_tt[:, 1:])+ np.isnan(x_tt[:, 1:])* f_mean
pred = 0.
 for clf in models:
pred += clf(x_tt, training = False ).numpy().item() / num_models
pred_df.action = np.where(pred >= opt_th, 1, 0 ).astype(int)
 else:
pred_df.action = 0
env.predict(pred_df )