text_plain_output_1.png
roc_auc_scorer = make_scorer(roc_auc_score, greater_is_better=True, needs_threshold=True)
cross_validation = StratifiedKFold(n_splits=3, shuffle=True, random_state=42)
clf = xgb.XGBClassifier(nthread=1, random_state=42)
param_grid = {'max_depth': [15, 20], 'min_samples_split': [3], 'learning_rate': [0.05, 0.1], 'min_child_weight': [5, 11, 15], 'silent': [1], 'subsample': [0.8], 'colsample_bytree': [0.7], 'n_estimators': [500], 'missing': [-999]}
search = GridSearchCV(clf, param_grid, cv=cross_validation, scoring=roc_auc_scorer, n_jobs=-1).fit(X_train_sm, y_train_sm)
print(search.best_params_)
y_prob = search.predict_proba(X_test)[:, 1]
print(f'ROC-AUC score: {roc_auc_score(y_test, y_prob):.3f}')
predictions_cv_xgb = search.predict_proba(OH_test_df)[:, 1]
submission = pd.DataFrame({'TransactionID': OH_test_df.index, 'isFraud': predictions_cv_xgb})
submission['TransactionID'] = submission['TransactionID'].astype(int)
filename = 'cv_xgb_model_submission.csv'
submission.to_csv(filename, index=False)
print(f'Saved file: {filename}')