Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<count_values>
print('loading libs...')
 warnings.filterwarnings("ignore")
 print('done' )
train_data['cabin_adv'] = train_data.Cabin.apply(lambda x: str(x)[0])
 train_data['cabin_adv'].value_counts()<create_dataframe>
%%time
print('loading data...')
 train = pd.read_pickle('.. /input/ieee-fe-with-some-eda/train_df.pkl')
 test = pd.read_pickle('.. /input/ieee-fe-with-some-eda/test_df.pkl')
 remove_features = pd.read_pickle('.. /input/ieee-fe-with-some-eda/remove_features.pkl')
 sample_submission = pd.read_csv('.. /input/ieee-fraud-detection/sample_submission.csv')
 print('done')
pd.pivot_table(train_data, index='Survived', columns='cabin_adv', values='Ticket', aggfunc='count' )<feature_engineering>
%%time
print('dropping target...')
 y_train = train['isFraud'].copy()
X_train = train.drop('isFraud', axis=1)
 X_test = test.copy()
train_cols = list(train.columns)
 del train, test
gc.collect()
print('selecting features...')
 remove_features = list(remove_features['features_to_remove'].values)
 features_columns = [col for col in train_cols if col not in remove_features]
X_train = X_train[features_columns]
X_test=X_test[features_columns]
print('Done' )
train_data['numeric_ticket'] = train_data.Ticket.apply(lambda x: 1 if x.isnumeric() else 0)
 train_data['numeric_ticket']<create_dataframe>
X_train = reduce_mem_usage(X_train)
 X_test = reduce_mem_usage(X_test )
pd.pivot_table(train_data, index='Survived', columns='numeric_ticket', values='Ticket', aggfunc='count' )<feature_engineering>
params = {
'objective':'binary',
'boosting_type':'gbdt',
'metric':'auc',
'n_jobs':-1,
'max_depth':-1,
'tree_learner':'serial',
'min_data_in_leaf':30,
'n_estimators':1800,
'max_bin':255,
'verbose':-1,
'seed': 1229,
'learning_rate': 0.01,
'early_stopping_rounds':200,
'colsample_bytree': 0.5,
'num_leaves': 256,
'reg_alpha': 0.35,
}
print(142/88, 407/254 )<feature_engineering>
%%time
NFOLDS = 6
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]
dtrain = lgb.Dataset(X_tr, label=y_tr)
 dvalid = lgb.Dataset(X_val, label=y_val)
 clf = lgb.train(params, dtrain, valid_sets = [dtrain, dvalid], verbose_eval=500)
 y_pred_valid = clf.predict(X_val)
 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
del X_tr, X_val, y_tr, y_val
gc.collect()
y_preds += clf.predict(X_test)/ NFOLDS
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_lgb.csv", index=False )