text_plain_output_1.png
from sklearn.model_selection import StratifiedKFold

import janestreet

import lightgbm as lgb

from sklearn.model_selection import StratifiedKFold
params = {'objective': 'binary', 'metrics': ['auc']}
nfolds = 3
kfold = StratifiedKFold(n_splits=nfolds)
lgb_models = list()
import lightgbm as lgb
for k, (train_idx, valid_idx) in enumerate(kfold.split(train.query('date>150')[just_features], train.query('date>150')['action'])):
    lgb_train = lgb.Dataset(train.loc[train_idx, just_features], train.loc[train_idx, 'action'])
    lgb_valid = lgb.Dataset(train.loc[valid_idx, just_features], train.loc[valid_idx, 'action'])
    model = lgb.train(params, lgb_train, valid_sets=[lgb_train, lgb_valid], num_boost_round=10000, verbose_eval=50, early_stopping_rounds=10)
    lgb_models.append(model)

import janestreet
env = janestreet.make_env()
iter_test = env.iter_test()
for test_df, sample_prediction_df in iter_test:
    prediction = 0
    for model in lgb_models:
        prediction += model.predict(test_df[features])[0]
    prediction /= len(lgb_models)
    prediction = prediction > 0.5
    sample_prediction_df.action = prediction.astype(int)
    env.predict(sample_prediction_df)
    if rcount % 1000 == 0:
        print('Processed: {} rows\n'.format(rcount))
print(f'Finished processing {rcount} rows.')