Kaggle competition: Jane Street Market Prediction
<SOS> metric: JaneStreetPnl Kaggle data source: jane-street-market-prediction<set_options>
pd.set_option('display.max_columns', 500)
 print("XGBoost version:", xgb.__version__)
 env = janestreet.make_env()
iter_test = env.iter_test()
pd.set_option('display.max_rows', 20 )<feature_engineering>
%%time
count_vectorizer = feature_extraction.text.CountVectorizer()
example_train_vectors = count_vectorizer.fit_transform(train_df["text"][0:5] )<categorify>
%%time
train_cudf = cu.read_csv('/kaggle/input/jane-street-market-prediction/train.csv')
 data = train_cudf.to_pandas()
del train_cudf
print(example_train_vectors[0].todense().shape)
 print(example_train_vectors[0].todense() )<feature_engineering>
features = [c for c in data.columns if 'feature' in c]
for i in features:
x = data[i].mean()
data[i] = data[i].fillna(x )
train_vectors = count_vectorizer.fit_transform(train_df["text"])
 dev_vectors = count_vectorizer.transform(dev_df["text"] )<choose_model_class>
clf = linear_model.RidgeClassifier()<predict_on_test>
print(data.shape)
 data = data[data['weight']!=0]
data['action'] =(data['resp']>0)*1
print(data.shape)
 train = data.sample(frac = 0.75, random_state = 73)
 print(train.shape)
 valid = data.drop(train.index)
 print(valid.shape)
 train.reset_index(drop=True, inplace=True)
 valid.reset_index(drop=True, inplace=True)
 X_train = train.loc[:,features]
y_train = train.loc[:, 'action']
X_valid = valid.loc[:, features]
y_valid = valid.loc[:, 'action']
%%time
clf.fit(train_vectors, train_df["target"])
 predictions = clf.predict(dev_vectors);
print(classification_report(dev_df['target'], predictions)) 
<feature_engineering>
%%time
selector = CatBoostClassifier(thread_count = -1, task_type = "GPU", devices = '-1', random_seed = 73 ).fit(Pool(X_train, y_train), verbose = 100)
 list_of_tuples = list(zip(X_train.columns.values, selector.get_feature_importance()))
df = pd.DataFrame(list_of_tuples ).sort_values(by = [1] ).reset_index(drop = True ).rename(columns = {0: 'feat_labels', 1: 'feature_importances'})
 df.head()
count_vectorizer = feature_extraction.text.CountVectorizer()
train_replaced_na_keyword = train_df.copy()
train_replaced_na_keyword['keyword'] = train_df['keyword'].fillna(' ')
 train_vectors = count_vectorizer.fit_transform(train_replaced_na_keyword["keyword"])
 dev_replaced_na_keyword = dev_df.copy()
dev_replaced_na_keyword['keyword'] = dev_df['keyword'].fillna(' ')
 dev_vectors = count_vectorizer.transform(dev_replaced_na_keyword["keyword"])
 train_replaced_na_keyword<categorify>
model = xgb.XGBClassifier(
 n_estimators=500,
max_depth=11,
learning_rate=0.05,
subsample=0.9,
colsample_bytree=0.7,
missing=None,
random_state=73,
tree_method='gpu_hist' 
)
 %time model.fit(X_train, y_train )
train_vectors[1].todense()<choose_model_class>
for(test_df, sample_prediction_df)in tqdm(iter_test):
X_test = test_df.loc[:, features]
for i in features:
x = X_test[i].mean()
X_test[i] = X_test[i].fillna(x)
 y_preds = model.predict(X_test)
 sample_prediction_df.action = y_preds
env.predict(sample_prediction_df )