class_docstr: The DecisionTreeEncoder() encodes categorical variables with predictions
  of a decision tree.
  
  The encoder first fits a decision tree using a single feature and the target (fit),
  and then replaces the values of the original feature by the predictions of the
  tree (transform). The transformer will train a decision tree per every feature to
  encode.
  
  The DecisionTreeEncoder() will encode only categorical variables by default
  (type 'object' or 'categorical'). You can pass a list of variables to encode or the
  encoder will find and encode all categorical variables.
  
  With `ignore_format=True` you have the option to encode numerical variables as
  well. In this case, you can either enter the list of variables to encode, or the
  transformer will automatically select all variables.
  
  More details in the :ref:`User Guide <decisiontree_encoder>`.
  
  Parameters
  ----------
  encoding_method: str, default='arbitrary'
      The method used to encode the categories to numerical values before fitting the
      decision tree.
  
      **'ordered'**: the categories are numbered in ascending order according to
      the target mean value per category.
  
      **'arbitrary'** : categories are numbered arbitrarily.
  
  cv: int, cross-validation generator or an iterable, default=3
      Determines the cross-validation splitting strategy. Possible inputs for cv are:
  
          - None, to use cross_validate's default 5-fold cross validation
  
          - int, to specify the number of folds in a (Stratified)KFold,
  
          - CV splitter
              - (https://scikit-learn.org/stable/glossary.html#term-CV-splitter)
  
          - An iterable yielding (train, test) splits as arrays of indices.
  
      For int/None inputs, if the estimator is a classifier and y is either binary or
      multiclass, StratifiedKFold is used. In all other cases, KFold is used. These
      splitters are instantiated with `shuffle=False` so the splits will be the same
      across calls. For more details check Scikit-learn's `cross_validate`'s
      documentation.
  
  scoring: str, default='neg_mean_squared_error'
      Desired metric to optimise the performance for the decision tree. Comes from
      sklearn.metrics. See the DecisionTreeRegressor or DecisionTreeClassifier
      model evaluation documentation for more options:
      https://scikit-learn.org/stable/modules/model_evaluation.html
  
  param_grid: dictionary, default=None
      The hyperparameters for the decision tree to test with a grid search. The
      `param_grid` can contain any of the permitted hyperparameters for Scikit-learn's
      DecisionTreeRegressor() or DecisionTreeClassifier(). If None, then param_grid
      will optimise the 'max_depth' over `[1, 2, 3, 4]`.
  
  regression: boolean, default=True
      Indicates whether the encoder should train a regression or a classification
      decision tree.
  
  random_state: int, default=None
      The random_state to initialise the training of the decision tree. It is one
      of the parameters of the Scikit-learn's DecisionTreeRegressor() or
      DecisionTreeClassifier(). For reproducibility it is recommended to set
      the random_state to an integer.
  
  {variables}
  
  {ignore_format}
  
  Attributes
  ----------
  encoder_:
      sklearn Pipeline containing the ordinal encoder and the decision tree.
  
  {variables_}
  
  {feature_names_in_}
  
  {n_features_in_}
  
  Methods
  -------
  fit:
      Fit a decision tree per variable.
  
  {fit_transform}
  
  transform:
      Replace categorical variable by the predictions of the decision tree.
  
  Notes
  -----
  The authors designed this method originally to work with numerical variables. We
  can replace numerical variables by the predictions of a decision tree utilising the
  DecisionTreeDiscretiser(). Here we extend this functionality to work also with
  categorical variables.
  
  NAN are introduced when encoding categories that were not present in the training
  dataset. If this happens, try grouping infrequent categories using the
  RareLabelEncoder().
  
  See Also
  --------
  sklearn.ensemble.DecisionTreeRegressor
  sklearn.ensemble.DecisionTreeClassifier
  feature_engine.discretisation.DecisionTreeDiscretiser
  feature_engine.encoding.RareLabelEncoder
  feature_engine.encoding.OrdinalEncoder
  
  References
  ----------
  .. [1] Niculescu-Mizil, et al. "Winning the KDD Cup Orange Challenge with Ensemble
      Selection". JMLR: Workshop and Conference Proceedings 7: 23-34. KDD 2009
      http://proceedings.mlr.press/v7/niculescu09/niculescu09.pdf
  
  Examples
  --------
  
  >>> import pandas as pd
  >>> from feature_engine.encoding import DecisionTreeEncoder
  >>> X = pd.DataFrame(dict(x1 = [1,2,3,4,5], x2 = ["b", "b", "b", "a", "a"]))
  >>> y = pd.Series([2.2,4, 1.5, 3.2, 1.1])
  >>> dte = DecisionTreeEncoder(cv=2)
  >>> dte.fit(X, y)
  >>> dte.transform(X)
     x1        x2
  0   1  2.566667
  1   2  2.566667
  2   3  2.566667
  3   4  2.150000
  4   5  2.150000
  
  You can also use it for classification by using `regression=False`.
  
  >>> y = pd.Series([0,1,1,1,0])
  >>> dte = DecisionTreeEncoder(regression=False, cv=2)
  >>> dte.fit(X, y)
  >>> dte.transform(X)
     x1        x2
  0   1  0.666667
  1   2  0.666667
  2   3  0.666667
  3   4  0.500000
  4   5  0.500000
class_docstr_tok: ["The","DecisionTreeEncoder","(",")","encodes","categorical","variables","with","predictions","of","a","decision","tree",".","The","encoder","first","fits","a","decision","tree","using","a","single","feature","and","the","target","(","fit",")",",","and","then","replaces","the","values","of","the","original","feature","by","the","predictions","of","the","tree","(","transform",")",".","The","transformer","will","train","a","decision","tree","per","every","feature","to","encode",".","The","DecisionTreeEncoder","(",")","will","encode","only","categorical","variables","by","default","(","type","'object","'","or","'categorical","'",")",".","You","can","pass","a","list","of","variables","to","encode","or","the","encoder","will","find","and","encode","all","categorical","variables",".","With","`","ignore_format=True","`","you","have","the","option","to","encode","numerical","variables","as","well",".","In","this","case",",","you","can","either","enter","the","list","of","variables","to","encode",",","or","the","transformer","will","automatically","select","all","variables",".","More","details","in","the",":","ref",":","`","User","Guide","<","decisiontree_encoder",">","`",".","Parameters","--","--","--","--","--","encoding_method",":","str",",","default='arbitrary'","The","method","used","to","encode","the","categories","to","numerical","values","before","fitting","the","decision","tree",".","*","*","'ordered","'","*","*",":","the","categories","are","numbered","in","ascending","order","according","to","the","target","mean","value","per","category",".","*","*","'arbitrary","'","*","*",":","categories","are","numbered","arbitrarily",".","cv",":","int",",","cross-validation","generator","or","an","iterable",",","default=3","Determines","the","cross-validation","splitting","strategy",".","Possible","inputs","for","cv","are",":","-","None",",","to","use","cross_validate","'s","default","5-fold","cross","validation","-","int",",","to","specify","the","number","of","folds","in","a","(","Stratified",")","KFold",",","-","CV","splitter","-","(","https",":","\/\/scikit-learn.org\/stable\/glossary.html","#","term-CV-splitter",")","-","An","iterable","yielding","(","train",",","test",")","splits","as","arrays","of","indices",".","For","int\/None","inputs",",","if","the","estimator","is","a","classifier","and","y","is","either","binary","or","multiclass",",","StratifiedKFold","is","used",".","In","all","other","cases",",","KFold","is","used",".","These","splitters","are","instantiated","with","`","shuffle=False","`","so","the","splits","will","be","the","same","across","calls",".","For","more","details","check","Scikit-learn","'s","`","cross_validate","`","'s","documentation",".","scoring",":","str",",","default='neg_mean_squared_error'","Desired","metric","to","optimise","the","performance","for","the","decision","tree",".","Comes","from","sklearn.metrics",".","See","the","DecisionTreeRegressor","or","DecisionTreeClassifier","model","evaluation","documentation","for","more","options",":","https",":","\/\/scikit-learn.org\/stable\/modules\/model_evaluation.html","param_grid",":","dictionary",",","default=None","The","hyperparameters","for","the","decision","tree","to","test","with","a","grid","search",".","The","`","param_grid","`","can","contain","any","of","the","permitted","hyperparameters","for","Scikit-learn's","DecisionTreeRegressor","(",")","or","DecisionTreeClassifier","(",")",".","If","None",",","then","param_grid","will","optimise","the","'max_depth","'","over","`","[","1",",","2",",","3",",","4","]","`",".","regression",":","boolean",",","default=True","Indicates","whether","the","encoder","should","train","a","regression","or","a","classification","decision","tree",".","random_state",":","int",",","default=None","The","random_state","to","initialise","the","training","of","the","decision","tree",".","It","is","one","of","the","parameters","of","the","Scikit-learn","'s","DecisionTreeRegressor","(",")","or","DecisionTreeClassifier","(",")",".","For","reproducibility","it","is","recommended","to","set","the","random_state","to","an","integer",".","{","variables","}","{","ignore_format","}","Attributes","--","--","--","--","--","encoder_",":","sklearn","Pipeline","containing","the","ordinal","encoder","and","the","decision","tree",".","{","variables_","}","{","feature_names_in_","}","{","n_features_in_","}","Methods","--","--","--","-","fit",":","Fit","a","decision","tree","per","variable",".","{","fit_transform","}","transform",":","Replace","categorical","variable","by","the","predictions","of","the","decision","tree",".","Notes","--","--","-","The","authors","designed","this","method","originally","to","work","with","numerical","variables",".","We","can","replace","numerical","variables","by","the","predictions","of","a","decision","tree","utilising","the","DecisionTreeDiscretiser","(",")",".","Here","we","extend","this","functionality","to","work","also","with","categorical","variables",".","NAN","are","introduced","when","encoding","categories","that","were","not","present","in","the","training","dataset",".","If","this","happens",",","try","grouping","infrequent","categories","using","the","RareLabelEncoder","(",")",".","See","Also","--","--","--","--","sklearn.ensemble.DecisionTreeRegressor","sklearn.ensemble.DecisionTreeClassifier","feature_engine.discretisation.DecisionTreeDiscretiser","feature_engine.encoding.RareLabelEncoder","feature_engine.encoding.OrdinalEncoder","References","--","--","--","--","--","..","[","1","]","Niculescu-Mizil",",","et","al",".","``","Winning","the","KDD","Cup","Orange","Challenge","with","Ensemble","Selection","''",".","JMLR",":","Workshop","and","Conference","Proceedings","7",":","23-34",".","KDD","2009","http",":","\/\/proceedings.mlr.press\/v7\/niculescu09\/niculescu09.pdf","Examples","--","--","--","--",">",">",">","import","pandas","as","pd",">",">",">","from","feature_engine.encoding","import","DecisionTreeEncoder",">",">",">","X","=","pd.DataFrame","(","dict","(","x1","=","[","1,2,3,4,5","]",",","x2","=","[","``","b","''",",","``","b","''",",","``","b","''",",","``","a","''",",","``","a","''","]",")",")",">",">",">","y","=","pd.Series","(","[","2.2,4",",","1.5",",","3.2",",","1.1","]",")",">",">",">","dte","=","DecisionTreeEncoder","(","cv=2",")",">",">",">","dte.fit","(","X",",","y",")",">",">",">","dte.transform","(","X",")","x1","x2","0","1","2.566667","1","2","2.566667","2","3","2.566667","3","4","2.150000","4","5","2.150000","You","can","also","use","it","for","classification","by","using","`","regression=False","`",".",">",">",">","y","=","pd.Series","(","[","0,1,1,1,0","]",")",">",">",">","dte","=","DecisionTreeEncoder","(","regression=False",",","cv=2",")",">",">",">","dte.fit","(","X",",","y",")",">",">",">","dte.transform","(","X",")","x1","x2","0","1","0.666667","1","2","0.666667","2","3","0.666667","3","4","0.500000","4","5","0.500000"]
code: def __init__(
      self,
      encoding_method: str = "arbitrary",
      cv=3,
      scoring: str = "neg_mean_squared_error",
      param_grid: Optional[dict] = None,
      regression: bool = True,
      random_state: Optional[int] = None,
      variables: Union[None, int, str, List[Union[str, int]]] = None,
      ignore_format: bool = False,
  ) -> None:
      super().__init__(variables, ignore_format)
      self.encoding_method = encoding_method
      self.cv = cv
      self.scoring = scoring
      self.regression = regression
      self.param_grid = param_grid
      self.random_state = random_state
  
imports: from typing import List, Optional, Union
  import pandas
  from sklearn.pipeline import Pipeline
  from sklearn.utils.multiclass import check_classification_targets, type_of_target
  from feature_engine._docstrings.fit_attributes import _feature_names_in_docstring, _n_features_in_docstring, _variables_attribute_docstring
  from feature_engine._docstrings.init_parameters import _ignore_format_docstring, _variables_categorical_docstring
  from feature_engine._docstrings.methods import _fit_transform_docstring
  from feature_engine._docstrings.substitute import Substitution
  from feature_engine.dataframe_checks import check_X_y
  from feature_engine.discretisation import DecisionTreeDiscretiser
  from feature_engine.encoding.base_encoder import CategoricalInitMixin, CategoricalMethodsMixin
  from feature_engine.encoding.ordinal import OrdinalEncoder
  from feature_engine.tags import _return_tags
label_desc: Use image node_id 1 to create a new DecisionTreeEncoder object from inherited base classes: CategoricalInitMixin, CategoricalMethodsMixin with example: obj = DecisionTreeEncoder(encoding_method, cv, scoring, param_grid, regression, random_state, variables, ignore_format)