Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<prepare_output>
print('loading libs...')
 warnings.filterwarnings("ignore")
 print('done' )
y1_pred = y1_pred.round(0 )<compute_test_metric>
%%time
print('loading data...')
 train_transaction = pd.read_csv('.. /input/ieee-fraud-detection/train_transaction.csv', index_col='TransactionID')
 test_transaction = pd.read_csv('.. /input/ieee-fraud-detection/test_transaction.csv', index_col='TransactionID')
 train_identity = pd.read_csv('.. /input/ieee-fraud-detection/train_identity.csv', index_col='TransactionID')
 test_identity = pd.read_csv('.. /input/ieee-fraud-detection/test_identity.csv', index_col='TransactionID')
 sample_submission = pd.read_csv('.. /input/ieee-fraud-detection/sample_submission.csv')
 print('done')
print(r2_score(y1_Train, y1_best_dtr_model.predict(X_Train)) )<prepare_x_and_y>
features=['TransactionDT', 'card1', 'TransactionAmt', 'card2', 'addr1',
'P_emaildomain', 'D15', 'card5', 'C13', 'dist1', 'D10', 'D4',
'id_02', 'D1', 'id_20', 'C1', 'id_19', 'D2', 'id_31', 'D8', 'C2',
'DeviceInfo', 'D11', 'C14', 'C6', 'C11', 'R_emaildomain', 'C9',
'id_06', 'V313', 'id_05', 'M4', 'D3', 'id_33', 'M6', 'D5', 'dist2',
'V307', 'V310', 'M5', 'id_01', 'card4', 'id_13', 'C5', 'D9',
'card3', 'card6', 'id_30', 'V315', 'V314', 'D14', 'C10', 'C8',
'V130', 'C12', 'id_14', 'V312', 'V83', 'V87', 'V127', 'V62',
'id_18', 'D6', 'V317', 'V308', 'V320', 'ProductCD', 'V82', 'V76',
'V61', 'M7', 'V53', 'V54', 'D13', 'V20', 'M3', 'V55', 'V78', 'D12',
'V283', 'M8', 'V45', 'V38', 'V75', 'M9', 'V285', 'V309', 'V13',
'V311', 'V131', 'V77', 'V291', 'V12', 'V37', 'V281', 'V282', 'V19',
'V56', 'V35', 'V36']
y2_Train = df_train.Fatalities<train_on_grid>
%%time
print('merging data...')
 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('dropping target...')
 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
print('fillnas...')
 X_train = X_train.fillna(-999)
 X_test = X_test.fillna(-999)
 gc.collect()
print('Label Encoding...')
 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))
print('selecting features...')
 X_train = X_train[features]
X_test=X_test[features]
print('Done' )
<predict_on_test><EOS> 
%%time
NFOLDS = 5
folds = KFold(n_splits=NFOLDS)
 columns = X_train.columns
splits = folds.split(X_train, y_train)
 y_preds = np.zeros(X_test.shape[0])
 y_oof = np.zeros(X_train.shape[0])
 score = 0
for fold_n,(train_index, valid_index)in enumerate(splits):
X_tr, X_val = X_train[columns].iloc[train_index], X_train[columns].iloc[valid_index]
y_tr, y_val = y_train.iloc[train_index], y_train.iloc[valid_index]
eval_set = [(X_val, y_val)]
clf = xgb.XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=0.9, gamma=0,
learning_rate=0.05, max_delta_step=0, max_depth=9,
min_child_weight=1, missing=-999, n_estimators=500, n_jobs=4,
nthread=None, objective='binary:logistic', random_state=2019,
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
silent=None, subsample=0.9, tree_method='gpu_hist', verbosity=1,eval_metric= 'auc')
 clf.fit(X_tr, y_tr, eval_set=eval_set)
 y_pred_valid = clf.predict_proba(X_val)[:,1]
y_oof[valid_index] = y_pred_valid
print(f"Fold {fold_n + 1} | AUC: {roc_auc_score(y_val, y_pred_valid)}")
 score += roc_auc_score(y_val, y_pred_valid)/ NFOLDS
y_preds += clf.predict_proba(X_test)[:,1] / NFOLDS
del X_tr, X_val, y_tr, y_val
gc.collect()
print(f"
Mean AUC = {score}")
 print(f"Out of folds AUC = {roc_auc_score(y_train, y_oof)}")
 print('submission...')
 sample_submission['isFraud'] = y_preds
sample_submission.to_csv("submission_xgb.csv", index=False)