class_docstr: Extends supervised encoders with the nested cross validation on the training data to minimise overfitting.
  
  For a validation or a test set, supervised encoders can be used as follows:
  
      X_train_encoded = encoder.fit_transform(X_train, y_train)
      X_valid_encoded = encoder.transform(X_valid)
  
  However, the downstream model will be overfitting to the encoded training data due to target leakage.
  Using out-of-fold encodings is an effective way to prevent target leakage. This is equivalent to:
  
      X_train_encoded = np.zeros(X.shape)
      for trn, val in kfold.split(X, y):
          encoder.fit(X[trn], y[trn])
          X_train_encoded[val] = encoder.transform(X[val])
  
  This can be used in place of the "inner folds" as discussed here:
      https://sebastianraschka.com/faq/docs/evaluate-a-model.html
  
  See README.md for a list of supervised encoders.
  
  Discussion: Although leave-one-out encoder internally performs leave-one-out cross-validation, it is
  actually the most overfitting supervised model in our library. To illustrate the issue, let's imagine we
  have a totally unpredictive nominal feature and a perfectly balanced binary label. A supervised encoder
  should encode the feature into a constant vector as the feature is unpredictive of the label. But when we
  use leave-one-out cross-validation, the label ratio cease to be perfectly balanced and the wrong class
  label always becomes the majority in the training fold. Leave-one-out encoder returns a seemingly
  predictive feature. And the downstream model starts to overfit to the encoded feature. Unfortunately,
  even 10-fold cross-validation is not immune to this effect:
      http://www.kdd.org/exploration_files/v12-02-4-UR-Perlich.pdf
  To decrease the effect, it is recommended to use a low count of the folds. And that is the reason why
  this wrapper uses 5 folds by default.
  
  Based on the empirical results, only LeaveOneOutEncoder benefits greatly from this wrapper. The remaining
  encoders can be used without this wrapper.
  
  
  Parameters
  ----------
  feature_encoder: Object
      an instance of a supervised encoder.
  
  cv: int or sklearn cv Object
      if an int is given, StratifiedKFold is used by default, where the int is the number of folds.
  
  shuffle: boolean, optional
      whether to shuffle each classes samples before splitting into batches. Ignored if a CV method is provided.
  
  random_state: int, RandomState instance or None, optional, default=None
      if int, random_state is the seed used by the random number generator. Ignored if a CV method is provided.
  
  
  Example
  -------
  >>> import pandas as pd
  >>> from category_encoders import *
  >>> from category_encoders.wrapper import NestedCVWrapper
  >>> from sklearn.datasets import fetch_openml
  >>> from sklearn.model_selection import GroupKFold, train_test_split
  >>> bunch = fetch_openml(name="house_prices", as_frame=True)
  >>> display_cols = ["Id", "MSSubClass", "MSZoning", "LotFrontage", "YearBuilt", "Heating", "CentralAir"]
  >>> y = bunch.target > 200000
  >>> X = pd.DataFrame(bunch.data, columns=bunch.feature_names)[display_cols]
  >>> X_train, X_test, y_train, _ = train_test_split(X, y, random_state=42)
  >>> X_train, X_valid, y_train, y_valid = train_test_split(X_train, y_train, random_state=42)
  >>> # Define the nested CV encoder for a supervised encoder
  >>> enc_nested = NestedCVWrapper(TargetEncoder(cols=['CentralAir', 'Heating']), random_state=42)
  >>> # Encode the X data for train, valid & test
  >>> X_train_enc, X_valid_enc, X_test_enc = enc_nested.fit_transform(X_train, y_train, X_test=(X_valid, X_test))
  >>> print(X_train_enc.info())
  <class 'pandas.core.frame.DataFrame'>
  Int64Index: 821 entries, 1390 to 896
  Data columns (total 7 columns):
   #   Column       Non-Null Count  Dtype  
  ---  ------       --------------  -----  
   0   Id           821 non-null    float64
   1   MSSubClass   821 non-null    float64
   2   MSZoning     821 non-null    object 
   3   LotFrontage  672 non-null    float64
   4   YearBuilt    821 non-null    float64
   5   Heating      821 non-null    float64
   6   CentralAir   821 non-null    float64
  dtypes: float64(6), object(1)
  memory usage: 51.3+ KB
  None
class_docstr_tok: ["Extends","supervised","encoders","with","the","nested","cross","validation","on","the","training","data","to","minimise","overfitting",".","For","a","validation","or","a","test","set",",","supervised","encoders","can","be","used","as","follows",":","X_train_encoded","=","encoder.fit_transform","(","X_train",",","y_train",")","X_valid_encoded","=","encoder.transform","(","X_valid",")","However",",","the","downstream","model","will","be","overfitting","to","the","encoded","training","data","due","to","target","leakage",".","Using","out-of-fold","encodings","is","an","effective","way","to","prevent","target","leakage",".","This","is","equivalent","to",":","X_train_encoded","=","np.zeros","(","X.shape",")","for","trn",",","val","in","kfold.split","(","X",",","y",")",":","encoder.fit","(","X","[","trn","]",",","y","[","trn","]",")","X_train_encoded","[","val","]","=","encoder.transform","(","X","[","val","]",")","This","can","be","used","in","place","of","the","``","inner","folds","''","as","discussed","here",":","https",":","\/\/sebastianraschka.com\/faq\/docs\/evaluate-a-model.html","See","README.md","for","a","list","of","supervised","encoders",".","Discussion",":","Although","leave-one-out","encoder","internally","performs","leave-one-out","cross-validation",",","it","is","actually","the","most","overfitting","supervised","model","in","our","library",".","To","illustrate","the","issue",",","let","'s","imagine","we","have","a","totally","unpredictive","nominal","feature","and","a","perfectly","balanced","binary","label",".","A","supervised","encoder","should","encode","the","feature","into","a","constant","vector","as","the","feature","is","unpredictive","of","the","label",".","But","when","we","use","leave-one-out","cross-validation",",","the","label","ratio","cease","to","be","perfectly","balanced","and","the","wrong","class","label","always","becomes","the","majority","in","the","training","fold",".","Leave-one-out","encoder","returns","a","seemingly","predictive","feature",".","And","the","downstream","model","starts","to","overfit","to","the","encoded","feature",".","Unfortunately",",","even","10-fold","cross-validation","is","not","immune","to","this","effect",":","http",":","\/\/www.kdd.org\/exploration_files\/v12-02-4-UR-Perlich.pdf","To","decrease","the","effect",",","it","is","recommended","to","use","a","low","count","of","the","folds",".","And","that","is","the","reason","why","this","wrapper","uses","5","folds","by","default",".","Based","on","the","empirical","results",",","only","LeaveOneOutEncoder","benefits","greatly","from","this","wrapper",".","The","remaining","encoders","can","be","used","without","this","wrapper",".","Parameters","--","--","--","--","--","feature_encoder",":","Object","an","instance","of","a","supervised","encoder",".","cv",":","int","or","sklearn","cv","Object","if","an","int","is","given",",","StratifiedKFold","is","used","by","default",",","where","the","int","is","the","number","of","folds",".","shuffle",":","boolean",",","optional","whether","to","shuffle","each","classes","samples","before","splitting","into","batches",".","Ignored","if","a","CV","method","is","provided",".","random_state",":","int",",","RandomState","instance","or","None",",","optional",",","default=None","if","int",",","random_state","is","the","seed","used","by","the","random","number","generator",".","Ignored","if","a","CV","method","is","provided",".","Example","--","--","--","-",">",">",">","import","pandas","as","pd",">",">",">","from","category_encoders","import","*",">",">",">","from","category_encoders.wrapper","import","NestedCVWrapper",">",">",">","from","sklearn.datasets","import","fetch_openml",">",">",">","from","sklearn.model_selection","import","GroupKFold",",","train_test_split",">",">",">","bunch","=","fetch_openml","(","name=","''","house_prices","''",",","as_frame=True",")",">",">",">","display_cols","=","[","``","Id","''",",","``","MSSubClass","''",",","``","MSZoning","''",",","``","LotFrontage","''",",","``","YearBuilt","''",",","``","Heating","''",",","``","CentralAir","''","]",">",">",">","y","=","bunch.target",">","200000",">",">",">","X","=","pd.DataFrame","(","bunch.data",",","columns=bunch.feature_names",")","[","display_cols","]",">",">",">","X_train",",","X_test",",","y_train",",","_","=","train_test_split","(","X",",","y",",","random_state=42",")",">",">",">","X_train",",","X_valid",",","y_train",",","y_valid","=","train_test_split","(","X_train",",","y_train",",","random_state=42",")",">",">",">","#","Define","the","nested","CV","encoder","for","a","supervised","encoder",">",">",">","enc_nested","=","NestedCVWrapper","(","TargetEncoder","(","cols=","[","'CentralAir","'",",","'Heating","'","]",")",",","random_state=42",")",">",">",">","#","Encode","the","X","data","for","train",",","valid","&","test",">",">",">","X_train_enc",",","X_valid_enc",",","X_test_enc","=","enc_nested.fit_transform","(","X_train",",","y_train",",","X_test=","(","X_valid",",","X_test",")",")",">",">",">","print","(","X_train_enc.info","(",")",")","<","class","'pandas.core.frame.DataFrame","'",">","Int64Index",":","821","entries",",","1390","to","896","Data","columns","(","total","7","columns",")",":","#","Column","Non-Null","Count","Dtype","--","-","--","--","--","--","--","--","--","--","--","--","--","--","-","0","Id","821","non-null","float64","1","MSSubClass","821","non-null","float64","2","MSZoning","821","non-null","object","3","LotFrontage","672","non-null","float64","4","YearBuilt","821","non-null","float64","5","Heating","821","non-null","float64","6","CentralAir","821","non-null","float64","dtypes",":","float64","(","6",")",",","object","(","1",")","memory","usage",":","51.3+","KB","None"]
code: def __init__(
      self, feature_encoder, cv=5, shuffle=True, random_state=None
  ):
      self.feature_encoder = feature_encoder
      self.__name__ = feature_encoder.__class__.__name__
      self.shuffle = shuffle
      self.random_state = random_state
  
      if isinstance(cv, int):
          self.cv = StratifiedKFold(
              n_splits=cv, shuffle=shuffle, random_state=random_state
          )
      else:
          self.cv = cv
  
imports: import copy
  from category_encoders import utils
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.model_selection import StratifiedKFold
  import category_encoders
  import pandas
  from typing import Dict, Optional
label_desc: Use image node_id 1 to create a new NestedCVWrapper object from inherited base classes: BaseEstimator, TransformerMixin with example: obj = NestedCVWrapper(feature_encoder, cv, shuffle, random_state)