text_plain_output_1.png
scores = []
y_probs = []
for fold, (trn_id, val_id) in enumerate(folds.split(trn_data[features], trn_data[target_feature])):
    X_train, y_train = (trn_data[features].iloc[trn_id], trn_data[target_feature].iloc[trn_id])
    X_valid, y_valid = (trn_data[features].iloc[val_id], trn_data[target_feature].iloc[val_id])
    model = XGBClassifier(**optuna_params)
    model.fit(X_train, y_train, eval_set=[(X_valid, y_valid)], eval_metric=['logloss'], early_stopping_rounds=50, verbose=False)
    valid_pred = model.predict(X_valid)
    valid_score = accuracy_score(y_valid, valid_pred)
    print('Fold:', fold, 'Accuracy:', valid_score)
    scores.append(valid_score)
    y_probs.append(model.predict_proba(tst_data[features]))