code: def test_use_kfold_strategy_to_train_a_model_with_cv():
      # XXX: TE KFold strategy allows TE to be trained only once in a context of model building with CV,
      # but it can't be applied just once on the training data,
      # otherwise this is what's happening when training CV1 for example (fold1 = cv_holdout, f2-n = cv_train):
      #     column `cat_te` for cv_holdout is obtained using fold_1 so, only with information collected from folds_2-n, which is what we want.
      #     column `cat_te` for cv_train however is obtained using fold_i, and each of those contains information about fold_1: this is a data leakage from cv_holdout into cv_train.
      #     on top of this, current version of transform is using a global priorMean for NAs, creating an additional data leakage in CV context.
      # The priorMean issue can be fixed internally in the implementation of KFold strategy.
      # However, for proper CCV, we need a deep integration with CV logic in ModelBuilder (translate to Java of course..):
      #   train TE using KFold strategy on the entire train set.
      #   then during CV, for each fold:
      #     train_cv_i = te.transform(train_cv, fold=fold_i)  # so that train_cv_i is not encoded at all with encodings from other folds (they include info about current fold)
      #     test_cv_i = te.transform(test_cv, fold=fold_i)    # same
      #   finally, the final model is trained with TE applied on the whole training frame:
      #     train = te.transform(train, as_training=True)     # still using the fold column, this ensures that the final feature is equivalent to the one used in all the test_cv_i
      #     or
      #     train = te.transform(train)                       # ignoring the fold column, this way the final te feature uses the entire train set.
  
      ds = load_dataset(incl_test=True, incl_foldc=True)
      te = H2OTargetEncoderEstimator(
          noise=0, data_leakage_handling="kfold"
      )
      te.train(
          y=ds.target, training_frame=ds.train, fold_column="foldc"
      )
  
      train_enc_cv = te.transform(ds.train, as_training=True)
      cols_to_remove = [
          n[:-3] for n in train_enc_cv.names if n.endswith("_te")
      ]
      train_enc_cv = h2o.assign(
          train_enc_cv.drop(cols_to_remove), "train_enc_cv"
      )
  
      train_enc_no_cv = te.transform(ds.train)
      train_enc_no_cv = h2o.assign(
          train_enc_no_cv.drop(cols_to_remove), "train_enc_no_cv"
      )
  
      test_enc = te.transform(ds.test)
      test_enc = h2o.assign(test_enc.drop(cols_to_remove), "test_enc")
  
      print(train_enc_cv)
      print(train_enc_no_cv)
  
      gbm = H2OGradientBoostingEstimator(seed=seed)
      gbm.train(
          y=ds.target, training_frame=train_enc_cv, fold_column="foldc"
      )
      auc_with_ccv = gbm.model_performance(test_enc).auc()
      print("AUC with CCV : %s" % auc_with_ccv)
  
      gbm.train(
          y=ds.target,
          training_frame=train_enc_no_cv,
          fold_column="foldc",
      )
      auc_no_ccv = gbm.model_performance(test_enc).auc()
      print("AUC without CCV : %s" % auc_no_ccv)
  
      assert auc_with_ccv > auc_no_ccv
  
file_path: h2o-3/h2o-py/tests/testdir_algos/targetencoder/pyunit_targetencoder_data_leakage.py
imports: import itertools
  import os
  import sys
  import h2o
  from h2o.estimators import H2OTargetEncoderEstimator, H2OGradientBoostingEstimator
  from h2o.exceptions import H2OTypeError
  from tests import pyunit_utils
label_desc: Use image node_id 8 for calling a global function with example usage: test_use_kfold_strategy_to_train_a_model_with_cv() without return types