Kaggle competition: Jane Street Market Prediction
%%time
predictions = torch_bilstm_attention_roberta_exp.predict(X_dev)
 print(classification_report(y_dev, predictions)) 
<choose_model_class>
pd.set_option('display.max_columns', 500)
 warnings.filterwarnings("ignore" )
%%time
os.write(1, b"Starting experiments with spacyclassifier
")
 spacy_classifier = SpacyClassifier(n_iter=50)
 pipe = Pipeline([('preprop', PrePropTextTransformer(lemmatize=False,
lowercase=False,
remove_stopwords=False,
remove_accents=True,
normalize_contractions=False,
normalize_URL=True,
normalize_emoji=True,
normalize_html=True,
normalize_punctuation=False 
)) ,('predictor', spacy_classifier)])
 pipe.fit(train_df["text"], train_df["target"] )<predict_on_test>
env = janestreet.make_env()
iter_test = env.iter_test()
%%time
predictions = pipe.predict(dev_df["text"]);
print(classification_report(dev_df['target'], predictions))<choose_model_class>
import os
import numpy as np
import pandas as pd
from sklearn import preprocessing
import xgboost as xgb
%%time
checkpoint_path = "/kaggle/input/models3/GPT2_CLS_CHECKPOINT_ephoc20.pth.tar"
gpt2_classifier = GPT2Classifier(max_iter=20, finetune_GPT2=False, batch_size=32, checkpoint_path=checkpoint_path,
base_dir=".", classes=[0,1])
 pipe = Pipeline([('preprop', PrePropTextTransformer(lemmatize=False,
lowercase=False,
remove_stopwords=False,
remove_accents=True,
normalize_contractions=False,
normalize_URL=True,
normalize_emoji=True,
normalize_html=True,
normalize_punctuation=False 
)) ,('predictor', gpt2_classifier)])
 pipe.fit(train_df["text"], train_df["target"])
<predict_on_test>
print("XGBoost version:", xgb.__version__ )
%%time
predictions = pipe.predict(dev_df["text"]);
print(classification_report(dev_df['target'], predictions))<concatenate>
print('
total_size = 0
start_path = '.. /input/jane-street-market-prediction'
for path, dirs, files in os.walk(start_path):
for f in files:
fp = os.path.join(path, f)
 total_size += os.path.getsize(fp)
 print("Directory size: " + str(round(total_size/ 1000000, 2)) + 'MB' )
entire_train_df = pd.concat([train_df, dev_df] )<choose_model_class>
%%time
train = pd.read_csv('/kaggle/input/jane-street-market-prediction/train.csv')
 features = pd.read_csv('.. /input/jane-street-market-prediction/features.csv')
 example_test = pd.read_csv('.. /input/jane-street-market-prediction/example_test.csv')
 sample_prediction_df = pd.read_csv('.. /input/jane-street-market-prediction/example_sample_submission.csv')
 print("Data is loaded!" )
%%time
model = ClassificationModel('roberta', '/kaggle/input/simpletransformer-outputs/checkpoint-roberta_submission-epoch-2', args={"overwrite_output_dir": True, "num_train_epochs": 2}, use_cuda=False)
 clf = BertClassifierPredictor(model=model)
 pipe_roberta_finetuned_submit = Pipeline([('preprop', PrePropTextTransformer(lemmatize=False,
lowercase=False,
remove_stopwords=False,
remove_accents=True,
normalize_contractions=False,
normalize_URL=True,
normalize_emoji=True,
normalize_html=True,
normalize_punctuation=False 
)) ,('predictor', clf)])
<load_from_csv>
np.product(train.shape )
test_vectors = test_df['text']
sample_submission = pd.read_csv("/kaggle/input/data-baby2/sample_submission.csv")
 sample_submission["target"] = pipe_roberta_finetuned_submit.predict(test_vectors)
 sample_submission.head()<save_to_csv>
missing_values_count = train.isnull().sum()
print(missing_values_count)
 total_cells = np.product(train.shape)
 total_missing = missing_values_count.sum()
print("% of missing data = ",(total_missing/total_cells)* 100 )
sample_submission.to_csv("submission.csv", index=False )<install_modules>
train[train['weight'] == 0]
!pip install transformers<import_modules>
train = train[train['weight'] != 0]
train['action'] =(( train['weight'].values * train['resp'].values)> 0 ).astype('int')
 X_train = train.loc[:, train.columns.str.contains('feature')]
y_train = train.loc[:, 'action']
from keras.preprocessing import sequence
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import re
import string
from nltk.stem.snowball import SnowballStemmer
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from nltk import word_tokenize
from transformers import BertForSequenceClassification, AdamW, BertConfig
from transformers import BertTokenizer
from transformers import get_linear_schedule_with_warmup
import random
from sklearn.model_selection import train_test_split
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
import time
import datetime
from sklearn.metrics import accuracy_score
from sklearn.metrics import matthews_corrcoef<set_options>
X_train = X_train.fillna(0 )
if torch.cuda.is_available() :
device = torch.device("cuda")
 print('There are %d GPU(s)available.' % torch.cuda.device_count())
 print('We will use the GPU:', torch.cuda.get_device_name(0))
else:
print('No GPU available, using the CPU instead.')
 device = torch.device("cpu" )<define_variables>
del train, x, y
no_classes = 1
MAX_LEN = 64
BATCH_SIZE = 16
no_epochs = 3
random_state=42
seed_val = 2020
steps = 50<load_from_csv>
clf = xgb.XGBClassifier(
 n_estimators=500,
max_depth=11,
learning_rate=0.05,
subsample=0.9,
colsample_bytree=0.7,
missing=-999,
random_state=2020,
tree_method='gpu_hist'
)
train = pd.read_csv('.. /input/nlp-getting-started/train.csv')
 test = pd.read_csv('.. /input/nlp-getting-started/test.csv')
 df_submission = pd.read_csv('/kaggle/input/nlp-getting-started/sample_submission.csv')
 print(train.head())
 print(test.head())
 print(train.shape, test.shape )<count_missing_values>
%time clf.fit(X_train, y_train )
<drop_column><EOS> 
for(test_df, sample_prediction_df)in iter_test:
X_test = test_df.loc[:, test_df.columns.str.contains('feature')]
X_test.fillna(0)
 y_preds = clf.predict(X_test)
 sample_prediction_df.action = y_preds
env.predict(sample_prediction_df)