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
dtypes = {
'imdb_id': 'str',
'avg_rating': 'float32',
'num_rating': 'float32',
}
imdb_df = pd.read_csv('.. /input/box-office-prediction-imbd-scores/imdb_scores.csv',
usecols=dtypes.keys() ,
dtype=dtypes )<feature_engineering>
%%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
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))
def fix_dates(date_str):
if isinstance(date_str, str):
if int(date_str[-2:])< 20:
return date_str[:-2]+'20'+date_str[-2:]
else:
return date_str[:-2]+'19'+date_str[-2:]
else:
return np.nan
train['release_date'] = train['release_date'].apply(fix_dates)
 test['release_date'] = test['release_date'].apply(fix_dates )<filter>
%%time
EPOCHS = 3
kf = KFold(n_splits = EPOCHS, shuffle = True)
 y_preds = np.zeros(sample_submission.shape[0])
 y_oof = np.zeros(X_train.shape[0])
 for tr_idx, val_idx in kf.split(X_train, y_train):
clf = xgb.XGBClassifier(
 n_estimators=500,
max_depth=9,
learning_rate=0.05,
subsample=0.9,
colsample_bytree=0.9,
tree_method='gpu_hist' 
)
 X_tr, X_vl = X_train.iloc[tr_idx, :], X_train.iloc[val_idx, :]
y_tr, y_vl = y_train.iloc[tr_idx], y_train.iloc[val_idx]
clf.fit(X_tr, y_tr)
 y_pred_train = clf.predict_proba(X_vl)[:,1]
y_oof[val_idx] = y_pred_train
print('ROC AUC {}'.format(roc_auc_score(y_vl, y_pred_train)))
 y_preds+= clf.predict_proba(X_test)[:,1] / EPOCHS
df.loc[df['runtime']==0, :]<feature_engineering>
sample_submission['isFraud'] = y_preds
sample_submission.to_csv('simple_xgboost.csv' )