class_docstr: Implements the proposed method from
  
  "CatBoost: gradient boosting with categorical features support", Dorogush et al. (2018).
  
  The Catboost encoder is a target encoder for categorical features. In this implementation we follow Eq. (1)
  in https://arxiv.org/pdf/1810.11363.pdf.
docstr: Applies the Catboost encoder to the data.
  
  :param X: Input categorical data.
  :param Y: If target data is given, this data is used instead of the fitted data.
  :param use_alpha_when_unique: If True, uses the alpha value when a category only appears exactly once.
  :return: Catboost encoded inputs. If Y is given, it uses the idea if giving each row a time index and only use
           the previously observed data to estimate the encoding. If Y is not given, the previously fitted
           average for each category is used. This can be seen as using the whole training data set as
           past observations.
docstr_tok: ["Applies","the","Catboost","encoder","to","the","data",".",":","param","X",":","Input","categorical","data",".",":","param","Y",":","If","target","data","is","given",",","this","data","is","used","instead","of","the","fitted","data",".",":","param","use_alpha_when_unique",":","If","True",",","uses","the","alpha","value","when","a","category","only","appears","exactly","once",".",":","return",":","Catboost","encoded","inputs",".","If","Y","is","given",",","it","uses","the","idea","if","giving","each","row","a","time","index","and","only","use","the","previously","observed","data","to","estimate","the","encoding",".","If","Y","is","not","given",",","the","previously","fitted","average","for","each","category","is","used",".","This","can","be","seen","as","using","the","whole","training","data","set","as","past","observations","."]
code: def transform(
      self,
      X: np.ndarray,
      Y: Optional[np.ndarray] = None,
      use_alpha_when_unique: bool = True,
  ) -> np.ndarray:
      """Applies the Catboost encoder to the data.
  
      :param X: Input categorical data.
      :param Y: If target data is given, this data is used instead of the fitted data.
      :param use_alpha_when_unique: If True, uses the alpha value when a category only appears exactly once.
      :return: Catboost encoded inputs. If Y is given, it uses the idea if giving each row a time index and only use
               the previously observed data to estimate the encoding. If Y is not given, the previously fitted
               average for each category is used. This can be seen as using the whole training data set as
               past observations.
      """
  
      if self._category_means is None:
          raise ValueError(
              "Encoder must be fitted before calling transform"
          )
  
      if Y is not None:
          return self._fit_transform(
              X, Y, use_alpha_when_unique, train=False
          )
      else:
          if X.ndim > 1 and X.shape[1] > 1:
              raise ValueError(
                  "CatBoost encoder only supports one dimensional categorical data!"
              )
  
          X = X.reshape(-1)
          transformed_values = np.zeros(X.shape[0])
  
          for category in np.unique(X):
              mask = X == category
  
              if category in self._category_means:
                  transformed_values[mask] = self._category_means[
                      category
                  ]
              else:
                  transformed_values[mask] = self._alpha
  
          return transformed_values
  
file_path: dowhy/dowhy/gcm/util/catboost_encoder.py
imports: from typing import Optional
  import numpy
  from sklearn.preprocessing import LabelEncoder
label_desc: Use image node_id 4 for calling the CatBoostEncoder obj's underlying member method code with example usage: obj.transform(X, Y, use_alpha_when_unique) and returns: self, transformed_values