Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<load_from_csv>
import os
import numpy as np
import pandas as pd
from sklearn import preprocessing
import xgboost as xgb
df_train = pd.read_csv(
 '.. /input/favorita-grocery-sales-forecasting/train.csv', usecols=[1, 2, 3, 4, 5],
dtype={'onpromotion': bool},
converters={'unit_sales': lambda u: np.log1p(
 float(u)) if float(u)> 0 else 0},
parse_dates=["date"],
skiprows=range(1, 66458909)
)
 df_2017 = df_train.loc[df_train.date>=pd.datetime(2017,1,1)]
del df_train
df_2017 = df_2017.set_index(
 ["store_nbr", "item_nbr", "date"])[["unit_sales"]].unstack(
 level=-1 ).fillna(0)
 df_2017.columns = df_2017.columns.get_level_values(1 )<save_to_csv>
print("XGBoost version:", xgb.__version__ )
print("Making submission...")
 df_preds = pd.DataFrame(
 combinedPredY.values, index=df_2017.index,
columns=pd.date_range("2017-08-16", periods=16)
 ).stack().to_frame("unit_sales")
 df_preds.index.set_names(["store_nbr", "item_nbr", "date"], inplace=True )<set_options>
%%time
train_transaction = pd.read_csv('.. /input/train_transaction.csv', index_col='TransactionID')
 test_transaction = pd.read_csv('.. /input/test_transaction.csv', index_col='TransactionID')
 train_identity = pd.read_csv('.. /input/train_identity.csv', index_col='TransactionID')
 test_identity = pd.read_csv('.. /input/test_identity.csv', index_col='TransactionID')
 sample_submission = pd.read_csv('.. /input/sample_submission.csv', index_col='TransactionID')
 train = train_transaction.merge(train_identity, how='left', left_index=True, right_index=True)
 test = test_transaction.merge(test_identity, how='left', left_index=True, right_index=True)
 print(train.shape)
 print(test.shape)
 y_train = train['isFraud'].copy()
del train_transaction, train_identity, test_transaction, test_identity
X_train = train.drop('isFraud', axis=1)
 X_test = test.copy()
del train, test
X_train = X_train.fillna(-999)
 X_test = X_test.fillna(-999)
 for f in X_train.columns:
if X_train[f].dtype=='object' or X_test[f].dtype=='object':
lbl = preprocessing.LabelEncoder()
lbl.fit(list(X_train[f].values)+ list(X_test[f].values))
X_train[f] = lbl.transform(list(X_train[f].values))
X_test[f] = lbl.transform(list(X_test[f].values))
gc.collect()<load_from_csv>
clf = xgb.XGBClassifier(
 n_estimators=500,
max_depth=9,
learning_rate=0.05,
subsample=0.9,
colsample_bytree=0.9,
missing=-999,
random_state=2019,
tree_method='gpu_hist'
)
df_test = pd.read_csv(
 ".. /input/favorita-grocery-sales-forecasting/test.csv", usecols=[0, 1, 2, 3, 4],
dtype={'onpromotion': bool},
parse_dates=["date"]
).set_index(
 ['store_nbr', 'item_nbr', 'date']
)<save_to_csv>
%time clf.fit(X_train, y_train )
<define_variables><EOS> 
sample_submission['isFraud'] = clf.predict_proba(X_test)[:,1]
sample_submission.to_csv('simple_xgboost.csv' )