Kaggle competition: Jane Street Market Prediction
<SOS> metric: JaneStreetPnl Kaggle data source: jane-street-market-prediction<data_type_conversions>
df = dtable.fread('/kaggle/input/jane-street-market-prediction/train.csv' ).to_pandas()
df = df.query('date > 85' ).reset_index(drop = True)
 df = df[df.weight > 0]
df.reset_index(inplace=True, drop=True)
 df = df.astype({c: np.float32 for c in df.select_dtypes(include='float64' ).columns})
 df_labels = df[['date', 'weight', 'resp_1', 'resp_2', 'resp_3', 'resp_4', 'resp']]
features = [c for c in df.columns if 'feature' in c]
df = df.drop(df_labels.columns, axis=1)
 df.fillna(df.mean() , inplace=True)
 resp_cols = ['resp_1', 'resp_2', 'resp_3', 'resp_4', 'resp']
X = df[features]
y = np.stack([(df_labels[c] > 0 ).astype('int')for c in resp_cols] ).T
f_mean = np.mean(df[features[1:]].values, axis=0)
 device = 'cuda' if t.cuda.is_available() else 'cpu'
y_preds[:] = y_preds[:]>=0.5
y_preds = y_preds.astype(int)
 np.mean(y_preds )<save_to_csv>
class Model(nn.Module):
def __init__(self):
super(Model, self ).__init__()
self.layers = nn.Sequential(nn.BatchNorm1d(130),
LinBnDrop(130, 400, bn=True, p=0, act=Mish() , lin_first=False),
LinBnDrop(400, 800, bn=True, p=0.2289, act=Mish() , lin_first=False),
LinBnDrop(800, 400, bn=True, p=0.2289, act=Mish() , lin_first=False),
LinBnDrop(400, 5, bn=False, act=None, lin_first=False))
def forward(self, x):
x = self.layers(x)
 return x
sample_submission["target"] = y_preds
sample_submission.to_csv("submission.csv", index=False)
 y_preds[:20]<define_variables>
model_nn = Model()
model_nn = model_nn.to(device)
 learn = Learner(None, model_nn, loss_func=1)
 learn.load('/kaggle/input/roclossjs1/roc_model' )
stop_words = list(STOPWORDS)+ list('0123456789')+ ['rt', 'amp', 'us', 'will', 'via', 'dont', 'cant', 'u', 'work', 'im',
'got', 'back', 'first', 'one', 'two', 'know', 'going', 'time', 'go', 'may', 'youtube', 'say', 'day', 'love',
'still', 'see', 'watch', 'make', 'think', 'even', 'right', 'left', 'take', 'want', 'http', 'https', 'co']<prepare_output>
@njit
def fillna_npwhere_njit(array, values):
if np.isnan(array.sum()):
array = np.where(np.isnan(array), values, array)
 return array
def for_loop(method, matrix, values):
for i in range(matrix.shape[0]):
matrix[i] = method(matrix[i], values)
 return matrix
outliers = pd.DataFrame(columns = ['text', 'label'])
 for i in range(len(wrong_predictions)) :
outliers.loc[i, 'text'] = wrong_predictions[i].text_a
outliers.loc[i, 'label'] = wrong_predictions[i].label<statistical_test>
%%time
%%capture
env = janestreet.make_env()
learn.model.eval()
preds = []
for(test_df, pred_df)in tqdm(env.iter_test()):
if test_df['weight'].item() > 0:
x_tt = test_df.loc[:, features].values
x_tt[:, 1:] = for_loop(fillna_npwhere_njit, x_tt[:, 1:], f_mean)
 pred = 0.
 pred = learn.model(t.from_numpy(x_tt ).to(device, t.float)).sigmoid() [0][-1].item()
preds.append(pred)
 action = 1 if pred >=.5 else 0
pred_df.action = action
else:
pred_df.action = 0
env.predict(pred_df )
print('Statistics for punctuation marks repetition in outliers')
 subtext_repeation_in_df(outliers, 'text', list(string.punctuation), 10 )<define_variables>
preds = np.array(preds)
 preds.mean() , preds.std() , sum(preds >=.5), sum(preds < 5 )